Coverage Report - org.kuali.student.lum.lu.ui.main.client.widgets.ApplicationHeader
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationHeader
0%
0/88
0%
0/8
1.24
ApplicationHeader$1
0%
0/15
0%
0/4
1.24
ApplicationHeader$2
0%
0/5
N/A
1.24
ApplicationHeader$2$1
0%
0/5
N/A
1.24
ApplicationHeader$3
0%
0/3
N/A
1.24
ApplicationHeader$4
0%
0/3
N/A
1.24
ApplicationHeader$5
0%
0/4
N/A
1.24
ApplicationHeader$6
0%
0/3
N/A
1.24
ApplicationHeader$7
0%
0/3
N/A
1.24
ApplicationHeader$8
0%
0/3
N/A
1.24
ApplicationHeader$9
0%
0/3
N/A
1.24
ApplicationHeader$WrapperNavigationHandler
0%
0/4
N/A
1.24
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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.KSAsyncCallback;
 25  
 import org.kuali.student.common.ui.client.mvc.Callback;
 26  
 import org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbManager;
 27  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 28  
 import org.kuali.student.common.ui.client.service.ServerPropertiesRpcService;
 29  
 import org.kuali.student.common.ui.client.service.ServerPropertiesRpcServiceAsync;
 30  
 import org.kuali.student.common.ui.client.theme.Theme;
 31  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 32  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 33  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 34  
 import org.kuali.student.common.ui.client.widgets.NavigationHandler;
 35  
 import org.kuali.student.common.ui.client.widgets.StylishDropDown;
 36  
 import org.kuali.student.common.ui.client.widgets.headers.KSHeader;
 37  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenu.MenuImageLocation;
 38  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 39  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 40  
 
 41  
 import com.google.gwt.core.client.GWT;
 42  
 import com.google.gwt.event.dom.client.ClickEvent;
 43  
 import com.google.gwt.event.dom.client.ClickHandler;
 44  
 import com.google.gwt.event.dom.client.MouseOutEvent;
 45  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 46  
 import com.google.gwt.event.dom.client.MouseOverEvent;
 47  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 48  
 import com.google.gwt.user.client.Window;
 49  
 import com.google.gwt.user.client.ui.Anchor;
 50  
 import com.google.gwt.user.client.ui.Composite;
 51  
 import com.google.gwt.user.client.ui.FocusPanel;
 52  
 import com.google.gwt.user.client.ui.Frame;
 53  
 import com.google.gwt.user.client.ui.HTML;
 54  
 import com.google.gwt.user.client.ui.PopupPanel;
 55  
 import com.google.gwt.user.client.ui.SimplePanel;
 56  
 import com.google.gwt.user.client.ui.VerticalPanel;
 57  
 import com.google.gwt.user.client.ui.Widget;
 58  
 
 59  
 
 60  0
 public class ApplicationHeader extends Composite{
 61  
 
 62  
     private static final String LUM_APP_URL                = "lum.application.url";
 63  
     private static final String APP_URL                        = "application.url";
 64  
     private static final String DOC_SEARCH_URL                = "ks.rice.docSearch.serviceAddress";
 65  
     private static final String RICE_URL           = "ks.rice.url";
 66  
     private static final String RICE_LINK_LABEL        = "ks.rice.label";
 67  
     private static final String APP_VERSION                = "ks.application.version";
 68  
     
 69  
     //This property is used to append code server param to urls so links displayed in get dev mode works as intended
 70  
     private static final String CODE_SERVER                = "ks.gwt.codeServer"; 
 71  
 
 72  0
     private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class);
 73  
 
 74  0
         private KSHeader ksHeader = GWT.create(KSHeader.class);
 75  
 
 76  0
         private StylishDropDown navDropDown = new StylishDropDown("Select an area\u2026");
 77  0
         private Anchor versionAnchor = new Anchor(" ( Version ) ");
 78  
         //private Widget headerCustomWidget = Theme.INSTANCE.getCommonWidgets().getHeaderWidget();
 79  
 
 80  0
         private SimplePanel content = new SimplePanel();
 81  0
         private KSLightBox docSearchDialog = new KSLightBox();
 82  
 
 83  
         private Frame docSearch;
 84  0
     private String docSearchUrl = "";
 85  0
     private String appUrl = "..";
 86  0
     private String lumAppUrl = "..";
 87  0
     private String riceURL ="..";
 88  0
     private String riceLinkLabel="Rice";
 89  0
     private String appVersion = "";
 90  0
     private String codeServer = "";
 91  
 
 92  0
     private boolean loaded = false;
 93  
 
 94  
     private static class WrapperNavigationHandler extends NavigationHandler{
 95  
                 public WrapperNavigationHandler(String url) {
 96  0
                         super(url);
 97  0
                 }
 98  
 
 99  
                 @Override
 100  
                 public void beforeNavigate(Callback<Boolean> callback) {
 101  
                         //FIXME notify current controller of the page change so it can perform an action
 102  
                         //FIXME before navigation event
 103  0
                         callback.exec(true);
 104  0
                 }
 105  
     }
 106  0
         public ApplicationHeader(){
 107  0
                 this.initWidget(ksHeader);
 108  0
         }
 109  
         protected void onLoad() {
 110  0
                 super.onLoad();
 111  0
                 if (!loaded){
 112  0
                         List<String> serverPropertyList = Arrays.asList(APP_URL, DOC_SEARCH_URL, LUM_APP_URL,RICE_URL,RICE_LINK_LABEL, APP_VERSION, CODE_SERVER);
 113  
 
 114  0
                 serverPropertiesRpcService.get(serverPropertyList, new KSAsyncCallback<Map<String,String>>() {
 115  
                     public void handleFailure(Throwable caught) {
 116  
                             //ignoring, we'll use the default
 117  0
                             init();
 118  0
                     }
 119  
 
 120  
                     public void onSuccess(Map<String,String> result) {
 121  0
                         GWT.log("ServerProperties fetched: "+result.toString(), null);
 122  0
                         if(result != null){
 123  0
                             appUrl                         = result.get(APP_URL);
 124  0
                             docSearchUrl        = result.get(DOC_SEARCH_URL);
 125  0
                             lumAppUrl                 = result.get(LUM_APP_URL);
 126  0
                             riceURL         = result.get(RICE_URL);
 127  0
                             riceLinkLabel         = result.get(RICE_LINK_LABEL);
 128  0
                             appVersion                = result.get(APP_VERSION);
 129  
                             
 130  0
                             if (result.get(CODE_SERVER) != null){
 131  0
                                     codeServer        = result.get(CODE_SERVER);
 132  
                             }
 133  
                         }
 134  0
                         init();
 135  0
                     }
 136  
 
 137  
                 });
 138  
 
 139  0
                         loaded = false;
 140  
                 }
 141  0
         }
 142  
         private void init(){
 143  
                 //headerBottomLinks.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
 144  0
                 createUserDropDown();
 145  
                 //headerBottomLinks.add(userDropDown);
 146  0
                 ksHeader.setHiLabelText("Hi,");
 147  0
                 ksHeader.setUserName(Application.getApplicationContext().getUserId());
 148  0
                 Anchor logoutLink = new Anchor(getMessage("wrapperPanelLogout"));
 149  0
                 logoutLink.addClickHandler(new WrapperNavigationHandler("j_spring_security_logout"));
 150  0
                 ksHeader.addLogout(logoutLink);
 151  0
                 ksHeader.addLogout(versionAnchor);
 152  
 
 153  
                 //headerBottomLinks.add(logoutLink);
 154  0
                 createHelpInfo();
 155  0
                 createNavDropDown();
 156  0
                 ksHeader.addNavigation(navDropDown);
 157  0
                 ksHeader.addBottomContainerWidget(BreadcrumbManager.getBreadcrumbPanel());
 158  0
                 BreadcrumbManager.setParentPanel(ksHeader.getBottomContainer());
 159  
                 
 160  0
                 List<KSLabel> topLinks = new ArrayList<KSLabel>();
 161  
                 //FIXME the following code gets overridden
 162  0
                 topLinks.add(buildLink(riceLinkLabel,riceLinkLabel,riceURL+"/portal.do"));
 163  0
                 setHeaderCustomLinks(topLinks);
 164  
 
 165  0
                 navDropDown.addStyleName("KS-Navigation-DropDown");
 166  0
                 content.addStyleName("KS-Wrapper-Content");
 167  0
         }
 168  
 
 169  
         private void createHelpInfo(){
 170  0
             versionAnchor.addClickHandler(new ClickHandler(){
 171  
 
 172  
                    public void onClick(ClickEvent event) {
 173  0
                        final PopupPanel helpPopup = new PopupPanel(true);
 174  0
                        helpPopup.setWidget(new HTML("<br><h3>&nbsp;&nbsp; " + appVersion + "&nbsp;&nbsp;<h3>"));
 175  
 
 176  0
                        helpPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
 177  
                            public void setPosition(int offsetWidth, int offsetHeight) {
 178  0
                              int left = (Window.getClientWidth() - offsetWidth);
 179  0
                              int top = 0;
 180  0
                              helpPopup.setPopupPosition(left, top);
 181  0
                            }
 182  
                        });
 183  0
                    }
 184  
             });
 185  0
         }
 186  
 
 187  
         private void createUserDropDown() {
 188  0
                 List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
 189  0
             items.add(new KSMenuItemData(getMessage("wrapperPanelLogout"),new WrapperNavigationHandler("j_spring_security_logout")));
 190  0
         }
 191  
 
 192  
         private void createNavDropDown() {
 193  0
                 navDropDown.setImageLocation(MenuImageLocation.LEFT);
 194  
 
 195  0
                 List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
 196  
 
 197  0
                 items.add(new KSMenuItemData(getMessage("wrapperPanelTitleHome"),Theme.INSTANCE.getCommonImages().getApplicationIcon(),
 198  0
                             new ClickHandler(){
 199  
 
 200  
                                         @Override
 201  
                                         public void onClick(ClickEvent event) {
 202  0
                                                 HistoryManager.navigate(AppLocations.Locations.HOME.getLocation());
 203  0
                                         }}));
 204  0
                 items.add(new KSMenuItemData(getMessage("wrapperPanelTitleCurriculumManagement"),Theme.INSTANCE.getCommonImages().getBookIcon(),
 205  0
                             new ClickHandler(){
 206  
                                         @Override
 207  
                                         public void onClick(ClickEvent event) {
 208  0
                                                 HistoryManager.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());
 209  0
                                         }}));
 210  0
             items.add(new KSMenuItemData(getMessage("wrapperPanelTitleOrg"), Theme.INSTANCE.getCommonImages().getPeopleIcon(),
 211  
                             new WrapperNavigationHandler(lumAppUrl+"/org.kuali.student.core.organization.ui.OrgEntry/OrgEntry.jsp"))
 212  
             );
 213  0
             items.add(new KSMenuItemData(getMessage("wrapperPanelTitleWorkflowDocSearch"), Theme.INSTANCE.getCommonImages().getNodeIcon(),
 214  0
                             new ClickHandler(){
 215  
 
 216  
                                         @Override
 217  
                                         public void onClick(ClickEvent event) {
 218  0
                                                 buildDocSearchPanel();
 219  0
                                                 docSearchDialog.show();
 220  0
                                         }})
 221  
             );
 222  0
             items.add(new KSMenuItemData(getMessage("wrapperPanelTitleRice"), Theme.INSTANCE.getCommonImages().getRiceIcon(),
 223  
                             new WrapperNavigationHandler(
 224  
                                             riceURL+"/portal.do?selectedTab=main"))
 225  
             );
 226  
 
 227  0
             navDropDown.setItems(items);
 228  0
             navDropDown.setArrowImage(Theme.INSTANCE.getCommonImages().getDropDownIconWhite());
 229  
 
 230  0
         }
 231  
 
 232  
         public void setContent(Widget wrappedContent){
 233  0
                 content.setWidget(wrappedContent);
 234  0
         }
 235  
 
 236  
         public void setHeaderCustomLinks(List<KSLabel> links){
 237  0
                 for(KSLabel link: links){
 238  0
                         FocusPanel panel = new FocusPanel();
 239  0
                         panel.setWidget(link);
 240  
                         //headerTopLinks.add(panel);
 241  0
                         panel.addStyleName("KS-Wrapper-Header-Custom-Link-Panel");
 242  0
                         link.addStyleName("KS-Wrapper-Header-Custom-Link");
 243  0
                 }
 244  0
         }
 245  
 
 246  
         public void setFooterLinks(List<KSLabel> links){
 247  0
                 for(KSLabel link: links){
 248  
                         //footer.add(link);
 249  0
                         link.addStyleName("KS-Wrapper-Footer-Link");
 250  
                 }
 251  0
         }
 252  
 
 253  
 
 254  
     private KSLabel buildLink(final String text, final String title, final String actionUrl) {
 255  
 
 256  
         //Using KSLabel for now - couldn't change color for Anchor
 257  0
         final KSLabel link = new KSLabel(text);
 258  0
         link.addStyleName("KS-Header-Link");
 259  0
         link.setTitle(title);
 260  0
         link.addMouseOverHandler(new MouseOverHandler() {
 261  
 
 262  
             @Override
 263  
             public void onMouseOver(MouseOverEvent event) {
 264  0
                 link.addStyleName("KS-Header-Link-Focus");
 265  0
             }});
 266  
 
 267  0
         link.addMouseOutHandler(new MouseOutHandler() {
 268  
 
 269  
             @Override
 270  
             public void onMouseOut(MouseOutEvent event) {
 271  0
                 link.removeStyleName("KS-Header-Link-Focus");
 272  
 
 273  0
             }});
 274  0
         link.addClickHandler(new ClickHandler() {
 275  
 
 276  
             @Override
 277  
             public void onClick(ClickEvent event) {
 278  0
                 Window.Location.assign(actionUrl);
 279  0
             }});
 280  
 
 281  0
         return link;
 282  
 
 283  
     }
 284  
 
 285  
     //Method to build the light box for the doc search
 286  
     private void buildDocSearchPanel(){
 287  0
             if (docSearch == null){
 288  0
                 docSearch = new Frame();
 289  0
                     docSearch.setSize("700px", "500px");
 290  0
                 docSearch.setUrl(docSearchUrl);
 291  
 
 292  0
                 VerticalPanel docSearchPanel = new VerticalPanel();
 293  0
                 docSearchPanel.add(docSearch);
 294  
 
 295  0
                 KSButton closeActionButton = new KSButton(getMessage("wrapperPanelClose"));
 296  0
                 closeActionButton.addClickHandler(new ClickHandler(){
 297  
                     public void onClick(ClickEvent event) {
 298  0
                         docSearchDialog.hide();
 299  0
                     }
 300  
                 });
 301  
 
 302  0
                 docSearchPanel.add(closeActionButton);
 303  0
                 docSearchDialog.setWidget(docSearchPanel);
 304  
             }
 305  0
     }
 306  
 
 307  
     private static String getMessage(final String messageId) {
 308  0
         return Application.getApplicationContext().getMessage(messageId);
 309  
     }
 310  
 }