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