View Javadoc
1   package org.vaadin.jonatan.contexthelp.widgetset.client.ui;
2   
3   import com.google.gwt.core.client.Scheduler;
4   import com.google.gwt.core.client.Scheduler.ScheduledCommand;
5   import com.vaadin.client.ServerConnector;
6   import com.vaadin.client.communication.RpcProxy;
7   import com.vaadin.client.communication.StateChangeEvent;
8   import com.vaadin.client.extensions.AbstractExtensionConnector;
9   import com.vaadin.event.ShortcutAction;
10  import com.vaadin.shared.ui.Connect;
11  import org.vaadin.jonatan.contexthelp.ContextHelp;
12  
13  @Connect(ContextHelp.class)
14  public class ContextHelpConnector extends AbstractExtensionConnector implements ContextHelpEvent.BubbleMovedHandler,
15          ContextHelpEvent.BubbleHiddenHandler, ContextHelpEvent.BubbleShownHandler {
16  
17      ContextHelpServerRpc rpc = RpcProxy.create(ContextHelpServerRpc.class, this);
18  
19      VContextHelp contextHelp;
20  
21      @Override
22      protected void extend(ServerConnector serverConnector) {
23          if (contextHelp == null) {
24              contextHelp = new VContextHelp(serverConnector.getConnection());
25              contextHelp.addBubbleHiddenHandler(this);
26              contextHelp.addBubbleMovedHandler(this);
27              contextHelp.addBubbleShownHandler(this);
28              contextHelp.setHidden(getState().hidden);
29              contextHelp.setFollowFocus(getState().followFocus);
30              contextHelp.setHelpKeyCode(getState().helpKey);
31              contextHelp.setHideOnBlur(getState().hideOnBlur);
32          }
33      }
34  
35      @Override
36      public ContextHelpState getState() {
37          return (ContextHelpState) super.getState();
38      }
39  
40      @Override
41      public void onStateChanged(StateChangeEvent stateChangeEvent) {
42          super.onStateChanged(stateChangeEvent);
43          if (stateChangeEvent.hasPropertyChanged("hidden")) {
44              contextHelp.setHidden(getState().hidden);
45          } else if (stateChangeEvent.hasPropertyChanged("followFocus")) {
46              contextHelp.setFollowFocus(getState().followFocus);
47          } else if (stateChangeEvent.hasPropertyChanged("helpKey")) {
48              contextHelp.setHelpKeyCode(getState().helpKey);
49          } else if (stateChangeEvent.hasPropertyChanged("hideOnBlur")) {
50              contextHelp.setHideOnBlur(getState().hideOnBlur);
51          }
52          if (!getState().hidden && getState().helpHTML != null) {
53              showHelpBubbleDeferred();
54          } else {
55              contextHelp.hideHelpBubble();
56          }
57      }
58  
59      private void showHelpBubbleDeferred() {
60          Scheduler.get().scheduleDeferred(new ScheduledCommand() {
61              public void execute() {
62                  contextHelp.showHelpBubble(getState().selectedComponentId,
63                          getState().helpHTML, getState().placement);
64              }
65          });
66      }
67  
68      @Override
69      public void onBubbleHidden(ContextHelpEvent.BubbleHiddenEvent event) {
70          if (!getState().hidden) {
71              rpc.setHidden(true);
72          }
73      }
74  
75      @Override
76      public void onBubbleMoved(ContextHelpEvent.BubbleMovedEvent event) {
77          rpc.selectComponent(event.getComponentId());
78      }
79  
80      @Override
81      public void onBubbleShown(ContextHelpEvent.BubbleShownEvent event) {
82          // TODO: do we need to do anything here?
83      }
84  
85      // public void updateFromUIDL(final UIDL uidl, ApplicationConnection client)
86      // {
87      //
88      // bubble.updateStyleNames(uidl.getStringAttribute("style"));
89      //
90      // final String helpText = uidl.getStringAttribute("helpText");
91      // if (!hidden && helpText != null) {
92      // Scheduler.get().scheduleDeferred(new ScheduledCommand() {
93      // public void execute() {
94      // Placement placement = Placement.DEFAULT;
95      // if (uidl.hasAttribute("placement")) {
96      // placement = Placement.valueOf(uidl
97      // .getStringAttribute("placement"));
98      // }
99      // bubble.showHelpBubble(uidl, helpText, placement);
100     // }
101     // });
102     // } else {
103     // hidden = true;
104     // if (bubble.isShowing()) {
105     // bubble.hide();
106     // }
107     // updateServersideState(false);
108     // }
109     // }
110 
111 }