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