View Javadoc

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.KSMenuItemData;
38  import org.kuali.student.common.ui.client.widgets.menus.KSMenu.MenuImageLocation;
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.SimplePanel;
54  import com.google.gwt.user.client.ui.VerticalPanel;
55  import com.google.gwt.user.client.ui.Widget;
56  
57  
58  public class ApplicationHeader extends Composite{
59  
60      private static final String LUM_APP_URL		= "lum.application.url";
61      private static final String APP_URL			= "application.url";
62      private static final String DOC_SEARCH_URL		= "ks.rice.docSearch.serviceAddress";
63      private static final String RICE_URL           = "ks.rice.url";
64      private static final String RICE_LINK_LABEL	= "ks.rice.label";
65      private static final String APP_VERSION		= "ks.application.version";
66      
67      //This property is used to append code server param to urls so links displayed in get dev mode works as intended
68      private static final String CODE_SERVER		= "ks.gwt.codeServer"; 
69  
70      private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class);
71  
72  	private KSHeader ksHeader = GWT.create(KSHeader.class);
73  
74  	protected StylishDropDown navDropDown = GWT.create(StylishDropDown.class);
75  	//private Widget headerCustomWidget = Theme.INSTANCE.getCommonWidgets().getHeaderWidget();
76  
77  	private SimplePanel content = new SimplePanel();
78  	protected KSLightBox docSearchDialog = new KSLightBox();
79  
80  	private Frame docSearch;
81      private String docSearchUrl = "";
82      private String appUrl = "..";
83      private String lumAppUrl = "..";
84      protected String riceURL ="..";
85      private String riceLinkLabel="Rice";
86      private String appVersion = "";
87      private String codeServer = "";
88  
89      private boolean loaded = false;
90  
91      protected static class WrapperNavigationHandler extends NavigationHandler{
92  		public WrapperNavigationHandler(String url) {
93  			super(url);
94  		}
95  
96  		@Override
97  		public void beforeNavigate(Callback<Boolean> callback) {
98  			//FIXME notify current controller of the page change so it can perform an action
99  			//FIXME before navigation event
100 			callback.exec(true);
101 		}
102     }
103 	public ApplicationHeader(){
104 		this.initWidget(ksHeader);
105 		navDropDown.initialise("Select an area\u2026");
106 	}
107 	protected void onLoad() {
108 		super.onLoad();
109 		if (!loaded){
110 			List<String> serverPropertyList = Arrays.asList(APP_URL, DOC_SEARCH_URL, LUM_APP_URL,RICE_URL,RICE_LINK_LABEL, APP_VERSION, CODE_SERVER);
111 
112 	        serverPropertiesRpcService.get(serverPropertyList, new KSAsyncCallback<Map<String,String>>() {
113 	            public void handleFailure(Throwable caught) {
114 	            	//ignoring, we'll use the default
115 	            	init();
116 	            }
117 
118 	            public void onSuccess(Map<String,String> result) {
119 	                GWT.log("ServerProperties fetched: "+result.toString(), null);
120 	                if(result != null){
121 	                    appUrl 			= result.get(APP_URL);
122 	                    docSearchUrl	= result.get(DOC_SEARCH_URL);
123 	                    lumAppUrl 		= result.get(LUM_APP_URL);
124 	                    riceURL         = result.get(RICE_URL);
125 	                    riceLinkLabel 	= result.get(RICE_LINK_LABEL);
126 	                    appVersion		= result.get(APP_VERSION);
127 	                    if (result.get(CODE_SERVER) != null){
128 	                    	codeServer	= result.get(CODE_SERVER);
129 	                    }
130 	                }
131 	                init();
132 	            }
133 
134 	        });
135 
136 			loaded = false;
137 		}
138 	}
139 	private void init(){
140 		//headerBottomLinks.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
141 		createUserDropDown();
142 		//headerBottomLinks.add(userDropDown);
143 		ksHeader.setHiLabelText("Hi,");
144 		ksHeader.setUserName(Application.getApplicationContext().getSecurityContext().getUserId());
145 		Anchor logoutLink = new Anchor(getMessage("wrapperPanelLogout"));
146 		logoutLink.addClickHandler(new WrapperNavigationHandler("j_spring_security_logout"));
147 		ksHeader.addLogout(logoutLink);
148 		createNavDropDown();
149 		ksHeader.addNavigation(navDropDown);
150 		ksHeader.addBottomContainerWidget(BreadcrumbManager.getBreadcrumbPanel());
151 		BreadcrumbManager.setParentPanel(ksHeader.getBottomContainer());
152 		
153 		List<KSLabel> topLinks = new ArrayList<KSLabel>();
154 		//FIXME the following code gets overridden
155 		topLinks.add(buildLink(riceLinkLabel,riceLinkLabel,riceURL+"/portal.do"));
156 		setHeaderCustomLinks(topLinks);
157 
158 		navDropDown.addStyleName("KS-Navigation-DropDown");
159 		content.addStyleName("KS-Wrapper-Content");
160 	}
161 
162 	private void createUserDropDown() {
163 		List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
164     	items.add(new KSMenuItemData(getMessage("wrapperPanelLogout"),new WrapperNavigationHandler("j_spring_security_logout")));
165 	}
166 
167 	protected void createNavDropDown() {
168 		navDropDown.setImageLocation(MenuImageLocation.LEFT);
169 
170 		List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
171 
172 		items.add(new KSMenuItemData(getMessage("wrapperPanelTitleHome"),Theme.INSTANCE.getCommonImages().getApplicationIcon(),
173     			new ClickHandler(){
174 
175 					@Override
176 					public void onClick(ClickEvent event) {
177 						HistoryManager.navigate(AppLocations.Locations.HOME.getLocation());
178 					}}));
179 		items.add(new KSMenuItemData(getMessage("wrapperPanelTitleCurriculumManagement"),Theme.INSTANCE.getCommonImages().getBookIcon(),
180     			new ClickHandler(){
181 					@Override
182 					public void onClick(ClickEvent event) {
183 						HistoryManager.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());
184 					}}));
185     	items.add(new KSMenuItemData(getMessage("wrapperPanelTitleOrg"), Theme.INSTANCE.getCommonImages().getPeopleIcon(),
186     			new WrapperNavigationHandler(lumAppUrl+"/org.kuali.student.core.organization.ui.OrgEntry/OrgEntry.jsp"))
187     	);
188     	items.add(new KSMenuItemData(getMessage("wrapperPanelTitleWorkflowDocSearch"), Theme.INSTANCE.getCommonImages().getNodeIcon(),
189     			new ClickHandler(){
190 
191 					@Override
192 					public void onClick(ClickEvent event) {
193 						buildDocSearchPanel();
194 						docSearchDialog.show();
195 					}})
196     	);
197     	items.add(new KSMenuItemData(getMessage("wrapperPanelTitleRice"), Theme.INSTANCE.getCommonImages().getRiceIcon(),
198     			new WrapperNavigationHandler(
199     					riceURL+"/portal.do?selectedTab=main"))
200     	);
201 
202     	navDropDown.setItems(items);
203     	navDropDown.setArrowImage(Theme.INSTANCE.getCommonImages().getDropDownIconWhite());
204     	navDropDown.ensureDebugId("Application-Header");
205 	}
206 
207 	public void setContent(Widget wrappedContent){
208 		content.setWidget(wrappedContent);
209 	}
210 
211 	public void setHeaderCustomLinks(List<KSLabel> links){
212 		for(KSLabel link: links){
213 			FocusPanel panel = new FocusPanel();
214 			panel.setWidget(link);
215 			//headerTopLinks.add(panel);
216 			panel.addStyleName("KS-Wrapper-Header-Custom-Link-Panel");
217 			link.addStyleName("KS-Wrapper-Header-Custom-Link");
218 		}
219 	}
220 
221 	public void setFooterLinks(List<KSLabel> links){
222 		for(KSLabel link: links){
223 			//footer.add(link);
224 			link.addStyleName("KS-Wrapper-Footer-Link");
225 		}
226 	}
227 
228 
229     private KSLabel buildLink(final String text, final String title, final String actionUrl) {
230 
231         //Using KSLabel for now - couldn't change color for Anchor
232         final KSLabel link = new KSLabel(text);
233         link.addStyleName("KS-Header-Link");
234         link.setTitle(title);
235         link.addMouseOverHandler(new MouseOverHandler() {
236 
237             @Override
238             public void onMouseOver(MouseOverEvent event) {
239                 link.addStyleName("KS-Header-Link-Focus");
240             }});
241 
242         link.addMouseOutHandler(new MouseOutHandler() {
243 
244             @Override
245             public void onMouseOut(MouseOutEvent event) {
246                 link.removeStyleName("KS-Header-Link-Focus");
247 
248             }});
249         link.addClickHandler(new ClickHandler() {
250 
251             @Override
252             public void onClick(ClickEvent event) {
253                 Window.Location.assign(actionUrl);
254             }});
255 
256         return link;
257 
258     }
259 
260     //Method to build the light box for the doc search
261     protected void buildDocSearchPanel(){
262     	if (docSearch == null){
263 	        docSearch = new Frame();
264 	    	docSearch.setSize("700px", "500px");
265 	        docSearch.setUrl(docSearchUrl);
266 
267 	        VerticalPanel docSearchPanel = new VerticalPanel();
268 	        docSearchPanel.add(docSearch);
269 
270 	        KSButton closeActionButton = new KSButton(getMessage("wrapperPanelClose"));
271 	        closeActionButton.addClickHandler(new ClickHandler(){
272 	            public void onClick(ClickEvent event) {
273 	                docSearchDialog.hide();
274 	            }
275 	        });
276 
277 	        docSearchPanel.add(closeActionButton);
278 	        docSearchDialog.setWidget(docSearchPanel);
279     	}
280     }
281 
282     protected static String getMessage(final String messageId) {
283         return Application.getApplicationContext().getMessage(messageId);
284     }
285     
286     public void setHeaderTitle(String title) {
287     	ksHeader.setApplicationTitle(title);
288     }
289     
290 }