View Javadoc

1   package de.orangecafe.amazonrcp.binding;
2   
3   import org.springframework.richclient.form.binding.support.CustomBinding;
4   import org.springframework.richclient.application.support.DefaultViewDescriptor;
5   import org.springframework.richclient.application.event.LifecycleApplicationEvent;
6   import org.springframework.richclient.application.Application;
7   import org.springframework.richclient.application.ApplicationException;
8   import org.springframework.richclient.command.ActionCommand;
9   import org.springframework.binding.form.FormModel;
10  
11  import javax.swing.*;
12  import java.net.URL;
13  import java.net.MalformedURLException;
14  
15  /**
16   * @author Torsten Strasser
17   */
18  public class UrlBinding extends CustomBinding {
19      private JButton _button;
20      private String _formPropertyPath;
21      private ActionCommand _command;
22  
23      protected UrlBinding(final JButton button, final FormModel formModel, final String formPropertyPath) {
24          super(formModel, formPropertyPath, String.class);
25  
26          DefaultViewDescriptor descriptor = (DefaultViewDescriptor) getApplicationContext().getBean("browserView");
27          _command = descriptor.createShowViewCommand(getActiveWindow());
28  
29          _button = button;
30          _formPropertyPath = formPropertyPath;
31      }
32  
33      protected JComponent doBindControl() {
34          Object o = getValueModel().getValue();
35          if (o != null) {
36              valueModelChanged(o);
37          }
38          _command.attach(_button);
39          _command.setEnabled(true);
40  
41          _button.setText(getMessage(_formPropertyPath + ".label"));
42          _button.setIcon(getIconSource().getIcon(_formPropertyPath + ".icon"));
43  
44          return _button;
45      }
46  
47      protected void readOnlyChanged() {
48          //TODO: check what to do here
49      }
50  
51      protected void enabledChanged() {
52          //TODO: check what to do here
53      }
54  
55      protected void valueModelChanged(final Object newValue) {
56          if (newValue != null) {
57              try {
58                  URL url = new URL((String) newValue);
59                  Application.instance().getApplicationContext().publishEvent(new LifecycleApplicationEvent(LifecycleApplicationEvent.MODIFIED, url));
60              } catch (MalformedURLException e) {
61                  throw new ApplicationException(e);
62              }
63          }
64      }
65  }