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