| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.lum.lu.ui.main.client.widgets; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.Arrays; | 
  | 20 |  |  import java.util.List; | 
  | 21 |  |  import java.util.Map; | 
  | 22 |  |   | 
  | 23 |  |  import org.kuali.student.common.ui.client.application.Application; | 
  | 24 |  |  import org.kuali.student.common.ui.client.application.ApplicationContext; | 
  | 25 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 26 |  |  import org.kuali.student.common.ui.client.mvc.Callback; | 
  | 27 |  |  import org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbManager; | 
  | 28 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 29 |  |  import org.kuali.student.common.ui.client.service.ServerPropertiesRpcService; | 
  | 30 |  |  import org.kuali.student.common.ui.client.service.ServerPropertiesRpcServiceAsync; | 
  | 31 |  |  import org.kuali.student.common.ui.client.theme.Theme; | 
  | 32 |  |  import org.kuali.student.common.ui.client.widgets.ApplicationPanel; | 
  | 33 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 34 |  |  import org.kuali.student.common.ui.client.widgets.KSLabel; | 
  | 35 |  |  import org.kuali.student.common.ui.client.widgets.KSLightBox; | 
  | 36 |  |  import org.kuali.student.common.ui.client.widgets.NavigationHandler; | 
  | 37 |  |  import org.kuali.student.common.ui.client.widgets.StylishDropDown; | 
  | 38 |  |  import org.kuali.student.common.ui.client.widgets.headers.KSHeader; | 
  | 39 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSMenu.MenuImageLocation; | 
  | 40 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; | 
  | 41 |  |  import org.kuali.student.lum.common.client.widgets.AppLocations; | 
  | 42 |  |   | 
  | 43 |  |  import com.google.gwt.core.client.GWT; | 
  | 44 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 45 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 46 |  |  import com.google.gwt.event.dom.client.MouseOutEvent; | 
  | 47 |  |  import com.google.gwt.event.dom.client.MouseOutHandler; | 
  | 48 |  |  import com.google.gwt.event.dom.client.MouseOverEvent; | 
  | 49 |  |  import com.google.gwt.event.dom.client.MouseOverHandler; | 
  | 50 |  |  import com.google.gwt.user.client.Window; | 
  | 51 |  |  import com.google.gwt.user.client.ui.Anchor; | 
  | 52 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 53 |  |  import com.google.gwt.user.client.ui.FocusPanel; | 
  | 54 |  |  import com.google.gwt.user.client.ui.Frame; | 
  | 55 |  |  import com.google.gwt.user.client.ui.HTML; | 
  | 56 |  |  import com.google.gwt.user.client.ui.Hidden; | 
  | 57 |  |  import com.google.gwt.user.client.ui.PopupPanel; | 
  | 58 |  |  import com.google.gwt.user.client.ui.SimplePanel; | 
  | 59 |  |  import com.google.gwt.user.client.ui.VerticalPanel; | 
  | 60 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 61 |  |   | 
  | 62 |  |   | 
  | 63 | 0 |  public class ApplicationHeader extends Composite{ | 
  | 64 |  |   | 
  | 65 |  |      private static final String LUM_APP_URL                = "lum.application.url"; | 
  | 66 |  |      private static final String APP_URL                        = "application.url"; | 
  | 67 |  |      private static final String DOC_SEARCH_URL                = "ks.rice.docSearch.serviceAddress"; | 
  | 68 |  |      private static final String RICE_URL           = "ks.rice.url"; | 
  | 69 |  |      private static final String RICE_LINK_LABEL        = "ks.rice.label"; | 
  | 70 |  |      private static final String APP_VERSION                = "ks.application.version"; | 
  | 71 |  |       | 
  | 72 |  |       | 
  | 73 |  |      private static final String CODE_SERVER                = "ks.gwt.codeServer";  | 
  | 74 |  |   | 
  | 75 | 0 |      private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class); | 
  | 76 |  |   | 
  | 77 | 0 |          private KSHeader ksHeader = GWT.create(KSHeader.class); | 
  | 78 |  |   | 
  | 79 | 0 |          private StylishDropDown navDropDown = new StylishDropDown("Select an area\u2026"); | 
  | 80 | 0 |          private Anchor versionAnchor = new Anchor(" ( Version ) "); | 
  | 81 |  |           | 
  | 82 |  |   | 
  | 83 | 0 |          private SimplePanel content = new SimplePanel(); | 
  | 84 | 0 |          private KSLightBox docSearchDialog = new KSLightBox(); | 
  | 85 |  |   | 
  | 86 |  |          private Frame docSearch; | 
  | 87 | 0 |      private String docSearchUrl = ""; | 
  | 88 | 0 |      private String appUrl = ".."; | 
  | 89 | 0 |      private String lumAppUrl = ".."; | 
  | 90 | 0 |      private String riceURL =".."; | 
  | 91 | 0 |      private String riceLinkLabel="Rice"; | 
  | 92 | 0 |      private String appVersion = ""; | 
  | 93 | 0 |      private String codeServer = ""; | 
  | 94 |  |   | 
  | 95 | 0 |      private boolean loaded = false; | 
  | 96 |  |   | 
  | 97 |  |      private static class WrapperNavigationHandler extends NavigationHandler{ | 
  | 98 |  |                  public WrapperNavigationHandler(String url) { | 
  | 99 | 0 |                          super(url); | 
  | 100 | 0 |                  } | 
  | 101 |  |   | 
  | 102 |  |                  @Override | 
  | 103 |  |                  public void beforeNavigate(Callback<Boolean> callback) { | 
  | 104 |  |                           | 
  | 105 |  |                           | 
  | 106 | 0 |                          callback.exec(true); | 
  | 107 | 0 |                  } | 
  | 108 |  |      } | 
  | 109 | 0 |          public ApplicationHeader(){ | 
  | 110 | 0 |                  this.initWidget(ksHeader); | 
  | 111 | 0 |          } | 
  | 112 |  |          protected void onLoad() { | 
  | 113 | 0 |                  super.onLoad(); | 
  | 114 | 0 |                  if (!loaded){ | 
  | 115 | 0 |                          List<String> serverPropertyList = Arrays.asList(APP_URL, DOC_SEARCH_URL, LUM_APP_URL,RICE_URL,RICE_LINK_LABEL, APP_VERSION, CODE_SERVER); | 
  | 116 |  |   | 
  | 117 | 0 |                  serverPropertiesRpcService.get(serverPropertyList, new KSAsyncCallback<Map<String,String>>() { | 
  | 118 |  |                      public void handleFailure(Throwable caught) { | 
  | 119 |  |                               | 
  | 120 | 0 |                              init(); | 
  | 121 | 0 |                      } | 
  | 122 |  |   | 
  | 123 |  |                      public void onSuccess(Map<String,String> result) { | 
  | 124 | 0 |                          GWT.log("ServerProperties fetched: "+result.toString(), null); | 
  | 125 | 0 |                          if(result != null){ | 
  | 126 | 0 |                              appUrl                         = result.get(APP_URL); | 
  | 127 | 0 |                              docSearchUrl        = result.get(DOC_SEARCH_URL); | 
  | 128 | 0 |                              lumAppUrl                 = result.get(LUM_APP_URL); | 
  | 129 | 0 |                              riceURL         = result.get(RICE_URL); | 
  | 130 | 0 |                              riceLinkLabel         = result.get(RICE_LINK_LABEL); | 
  | 131 | 0 |                              appVersion                = result.get(APP_VERSION); | 
  | 132 | 0 |                              if (result.get(CODE_SERVER) != null){ | 
  | 133 | 0 |                                      codeServer        = result.get(CODE_SERVER); | 
  | 134 |  |                              } | 
  | 135 |  |                          } | 
  | 136 | 0 |                          init(); | 
  | 137 | 0 |                      } | 
  | 138 |  |   | 
  | 139 |  |                  }); | 
  | 140 |  |   | 
  | 141 | 0 |                          loaded = false; | 
  | 142 |  |                  } | 
  | 143 | 0 |          } | 
  | 144 |  |          private void init(){ | 
  | 145 |  |                   | 
  | 146 | 0 |                  createUserDropDown(); | 
  | 147 |  |                   | 
  | 148 | 0 |                  ksHeader.setHiLabelText("Hi,"); | 
  | 149 | 0 |                  ksHeader.setUserName(Application.getApplicationContext().getUserId()); | 
  | 150 | 0 |                  Anchor logoutLink = new Anchor(getMessage("wrapperPanelLogout")); | 
  | 151 | 0 |                  logoutLink.addClickHandler(new WrapperNavigationHandler("j_spring_security_logout")); | 
  | 152 | 0 |                  ksHeader.addLogout(logoutLink); | 
  | 153 | 0 |                  createNavDropDown(); | 
  | 154 | 0 |                  ksHeader.addNavigation(navDropDown); | 
  | 155 | 0 |                  ksHeader.addBottomContainerWidget(BreadcrumbManager.getBreadcrumbPanel()); | 
  | 156 | 0 |                  BreadcrumbManager.setParentPanel(ksHeader.getBottomContainer()); | 
  | 157 |  |                   | 
  | 158 | 0 |                  List<KSLabel> topLinks = new ArrayList<KSLabel>(); | 
  | 159 |  |                   | 
  | 160 | 0 |                  topLinks.add(buildLink(riceLinkLabel,riceLinkLabel,riceURL+"/portal.do")); | 
  | 161 | 0 |                  setHeaderCustomLinks(topLinks); | 
  | 162 |  |   | 
  | 163 | 0 |                  navDropDown.addStyleName("KS-Navigation-DropDown"); | 
  | 164 | 0 |                  content.addStyleName("KS-Wrapper-Content"); | 
  | 165 | 0 |          } | 
  | 166 |  |   | 
  | 167 |  |          private void createUserDropDown() { | 
  | 168 | 0 |                  List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); | 
  | 169 | 0 |              items.add(new KSMenuItemData(getMessage("wrapperPanelLogout"),new WrapperNavigationHandler("j_spring_security_logout"))); | 
  | 170 | 0 |          } | 
  | 171 |  |   | 
  | 172 |  |          private void createNavDropDown() { | 
  | 173 | 0 |                  navDropDown.setImageLocation(MenuImageLocation.LEFT); | 
  | 174 |  |   | 
  | 175 | 0 |                  List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); | 
  | 176 |  |   | 
  | 177 | 0 |                  items.add(new KSMenuItemData(getMessage("wrapperPanelTitleHome"),Theme.INSTANCE.getCommonImages().getApplicationIcon(), | 
  | 178 | 0 |                              new ClickHandler(){ | 
  | 179 |  |   | 
  | 180 |  |                                          @Override | 
  | 181 |  |                                          public void onClick(ClickEvent event) { | 
  | 182 | 0 |                                                  HistoryManager.navigate(AppLocations.Locations.HOME.getLocation()); | 
  | 183 | 0 |                                          }})); | 
  | 184 | 0 |                  items.add(new KSMenuItemData(getMessage("wrapperPanelTitleCurriculumManagement"),Theme.INSTANCE.getCommonImages().getBookIcon(), | 
  | 185 | 0 |                              new ClickHandler(){ | 
  | 186 |  |                                          @Override | 
  | 187 |  |                                          public void onClick(ClickEvent event) { | 
  | 188 | 0 |                                                  HistoryManager.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation()); | 
  | 189 | 0 |                                          }})); | 
  | 190 | 0 |              items.add(new KSMenuItemData(getMessage("wrapperPanelTitleOrg"), Theme.INSTANCE.getCommonImages().getPeopleIcon(), | 
  | 191 |  |                              new WrapperNavigationHandler(lumAppUrl+"/org.kuali.student.core.organization.ui.OrgEntry/OrgEntry.jsp")) | 
  | 192 |  |              ); | 
  | 193 | 0 |              items.add(new KSMenuItemData(getMessage("wrapperPanelTitleWorkflowDocSearch"), Theme.INSTANCE.getCommonImages().getNodeIcon(), | 
  | 194 | 0 |                              new ClickHandler(){ | 
  | 195 |  |   | 
  | 196 |  |                                          @Override | 
  | 197 |  |                                          public void onClick(ClickEvent event) { | 
  | 198 | 0 |                                                  buildDocSearchPanel(); | 
  | 199 | 0 |                                                  docSearchDialog.show(); | 
  | 200 | 0 |                                          }}) | 
  | 201 |  |              ); | 
  | 202 | 0 |              items.add(new KSMenuItemData(getMessage("wrapperPanelTitleRice"), Theme.INSTANCE.getCommonImages().getRiceIcon(), | 
  | 203 |  |                              new WrapperNavigationHandler( | 
  | 204 |  |                                              riceURL+"/portal.do?selectedTab=main")) | 
  | 205 |  |              ); | 
  | 206 |  |   | 
  | 207 | 0 |              navDropDown.setItems(items); | 
  | 208 | 0 |              navDropDown.setArrowImage(Theme.INSTANCE.getCommonImages().getDropDownIconWhite()); | 
  | 209 |  |   | 
  | 210 | 0 |          } | 
  | 211 |  |   | 
  | 212 |  |          public void setContent(Widget wrappedContent){ | 
  | 213 | 0 |                  content.setWidget(wrappedContent); | 
  | 214 | 0 |          } | 
  | 215 |  |   | 
  | 216 |  |          public void setHeaderCustomLinks(List<KSLabel> links){ | 
  | 217 | 0 |                  for(KSLabel link: links){ | 
  | 218 | 0 |                          FocusPanel panel = new FocusPanel(); | 
  | 219 | 0 |                          panel.setWidget(link); | 
  | 220 |  |                           | 
  | 221 | 0 |                          panel.addStyleName("KS-Wrapper-Header-Custom-Link-Panel"); | 
  | 222 | 0 |                          link.addStyleName("KS-Wrapper-Header-Custom-Link"); | 
  | 223 | 0 |                  } | 
  | 224 | 0 |          } | 
  | 225 |  |   | 
  | 226 |  |          public void setFooterLinks(List<KSLabel> links){ | 
  | 227 | 0 |                  for(KSLabel link: links){ | 
  | 228 |  |                           | 
  | 229 | 0 |                          link.addStyleName("KS-Wrapper-Footer-Link"); | 
  | 230 |  |                  } | 
  | 231 | 0 |          } | 
  | 232 |  |   | 
  | 233 |  |   | 
  | 234 |  |      private KSLabel buildLink(final String text, final String title, final String actionUrl) { | 
  | 235 |  |   | 
  | 236 |  |           | 
  | 237 | 0 |          final KSLabel link = new KSLabel(text); | 
  | 238 | 0 |          link.addStyleName("KS-Header-Link"); | 
  | 239 | 0 |          link.setTitle(title); | 
  | 240 | 0 |          link.addMouseOverHandler(new MouseOverHandler() { | 
  | 241 |  |   | 
  | 242 |  |              @Override | 
  | 243 |  |              public void onMouseOver(MouseOverEvent event) { | 
  | 244 | 0 |                  link.addStyleName("KS-Header-Link-Focus"); | 
  | 245 | 0 |              }}); | 
  | 246 |  |   | 
  | 247 | 0 |          link.addMouseOutHandler(new MouseOutHandler() { | 
  | 248 |  |   | 
  | 249 |  |              @Override | 
  | 250 |  |              public void onMouseOut(MouseOutEvent event) { | 
  | 251 | 0 |                  link.removeStyleName("KS-Header-Link-Focus"); | 
  | 252 |  |   | 
  | 253 | 0 |              }}); | 
  | 254 | 0 |          link.addClickHandler(new ClickHandler() { | 
  | 255 |  |   | 
  | 256 |  |              @Override | 
  | 257 |  |              public void onClick(ClickEvent event) { | 
  | 258 | 0 |                  Window.Location.assign(actionUrl); | 
  | 259 | 0 |              }}); | 
  | 260 |  |   | 
  | 261 | 0 |          return link; | 
  | 262 |  |   | 
  | 263 |  |      } | 
  | 264 |  |   | 
  | 265 |  |       | 
  | 266 |  |      private void buildDocSearchPanel(){ | 
  | 267 | 0 |              if (docSearch == null){ | 
  | 268 | 0 |                  docSearch = new Frame(); | 
  | 269 | 0 |                      docSearch.setSize("700px", "500px"); | 
  | 270 | 0 |                  docSearch.setUrl(docSearchUrl); | 
  | 271 |  |   | 
  | 272 | 0 |                  VerticalPanel docSearchPanel = new VerticalPanel(); | 
  | 273 | 0 |                  docSearchPanel.add(docSearch); | 
  | 274 |  |   | 
  | 275 | 0 |                  KSButton closeActionButton = new KSButton(getMessage("wrapperPanelClose")); | 
  | 276 | 0 |                  closeActionButton.addClickHandler(new ClickHandler(){ | 
  | 277 |  |                      public void onClick(ClickEvent event) { | 
  | 278 | 0 |                          docSearchDialog.hide(); | 
  | 279 | 0 |                      } | 
  | 280 |  |                  }); | 
  | 281 |  |   | 
  | 282 | 0 |                  docSearchPanel.add(closeActionButton); | 
  | 283 | 0 |                  docSearchDialog.setWidget(docSearchPanel); | 
  | 284 |  |              } | 
  | 285 | 0 |      } | 
  | 286 |  |   | 
  | 287 |  |      private static String getMessage(final String messageId) { | 
  | 288 | 0 |          return Application.getApplicationContext().getMessage(messageId); | 
  | 289 |  |      } | 
  | 290 |  |       | 
  | 291 |  |      public void setHeaderTitle(String title) { | 
  | 292 | 0 |              ksHeader.setApplicationTitle(title); | 
  | 293 | 0 |      } | 
  | 294 |  |       | 
  | 295 |  |  } |