View Javadoc

1   package org.appfuse.webapp.client.ui;
2   
3   import org.appfuse.webapp.client.application.Application;
4   import org.appfuse.webapp.client.application.base.security.LoginEvent;
5   import org.appfuse.webapp.client.application.base.security.LogoutEvent;
6   import org.appfuse.webapp.client.ui.navigation.NavigationBar;
7   import org.appfuse.webapp.client.ui.navigation.SideNavigationBar;
8   
9   import com.google.gwt.core.client.GWT;
10  import com.google.gwt.dom.client.Element;
11  import com.google.gwt.place.shared.PlaceChangeEvent;
12  import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
13  import com.google.gwt.uibinder.client.UiBinder;
14  import com.google.gwt.uibinder.client.UiField;
15  import com.google.gwt.user.client.Window;
16  import com.google.gwt.user.client.ui.Widget;
17  
18  /**
19   * The outermost UI of the application.
20   */
21  public class DesktopShell extends Shell implements LoginEvent.Handler, LogoutEvent.Handler, PlaceChangeEvent.Handler {
22  
23      interface Binder extends UiBinder<Widget, DesktopShell> {
24      }
25  
26      private static final Binder uiBinder = GWT.create(Binder.class);
27  
28      @UiField
29      NavigationBar navigationBar;
30      @UiField
31      SideNavigationBar sideNavigationBar;
32  
33  
34      @UiField
35      Element currentUserInfo;
36  
37      public DesktopShell() {
38          initWidget(uiBinder.createAndBindUi(this));
39      }
40  
41      @Override
42      public void setApplication(final Application application) {
43          super.setApplication(application);
44          navigationBar.setApplication(application);
45          sideNavigationBar.setApplication(application);
46      }
47  
48      @Override
49      protected void onAttach() {
50          super.onAttach();
51          navigationBar.load();
52      }
53  
54      @Override
55      public void onLoginEvent(final LoginEvent loginEvent) {
56          navigationBar.load();
57          final SafeHtmlBuilder sb = new SafeHtmlBuilder();
58          sb.appendEscaped(" | ");
59          sb.appendEscaped(application.getI18n().user_status());
60          sb.append(' ');
61          sb.appendEscaped(application.getCurrentUsername());
62          currentUserInfo.setInnerSafeHtml(sb.toSafeHtml());
63      }
64  
65      @Override
66      public void onLogoutEvent(final LogoutEvent logoutEvent) {
67          navigationBar.load();
68          currentUserInfo.setInnerHTML("");
69      }
70  
71      @Override
72      public void onPlaceChange(final PlaceChangeEvent event) {
73          Window.scrollTo(0, 0);
74          for (final Widget widget : messages) {
75              try {
76                  widget.removeFromParent();
77              } catch (final Throwable e) {
78                  // already removed
79                  // XXX null in native method Node.removeChild:L291
80              }
81          }
82      }
83  }