001 /** 002 * Copyright 2010 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.student.lum.lu.ui.main.client; 017 018 019 import org.kuali.student.common.messages.dto.MessageList; 020 import org.kuali.student.common.ui.client.application.Application; 021 import org.kuali.student.common.ui.client.application.ApplicationContext; 022 import org.kuali.student.common.ui.client.application.KSAsyncCallback; 023 import org.kuali.student.common.ui.client.mvc.Controller; 024 import org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbManager; 025 import org.kuali.student.common.ui.client.mvc.history.HistoryManager; 026 import org.kuali.student.common.ui.client.service.MessagesRpcService; 027 import org.kuali.student.common.ui.client.service.SecurityRpcService; 028 import org.kuali.student.common.ui.client.service.SecurityRpcServiceAsync; 029 import org.kuali.student.common.ui.client.util.BrowserUtils; 030 import org.kuali.student.common.ui.client.util.WindowTitleUtils; 031 import org.kuali.student.common.ui.client.widgets.ApplicationPanel; 032 import org.kuali.student.common.ui.client.widgets.KSFooter; 033 import org.kuali.student.lum.common.client.widgets.AppLocations; 034 import org.kuali.student.lum.lu.ui.main.client.controllers.ApplicationController; 035 import org.kuali.student.lum.lu.ui.main.client.theme.LumTheme; 036 import org.kuali.student.lum.lu.ui.main.client.widgets.ApplicationHeader; 037 038 import com.google.gwt.core.client.EntryPoint; 039 import com.google.gwt.core.client.GWT; 040 import com.google.gwt.dom.client.StyleInjector; 041 import com.google.gwt.user.client.rpc.SerializationException; 042 import com.google.gwt.user.client.rpc.SerializationStreamFactory; 043 import com.google.gwt.user.client.rpc.SerializationStreamReader; 044 045 public class LUMMainEntryPoint implements EntryPoint{ 046 047 private ApplicationController manager = null; 048 private AppLocations locations = new AppLocations(); 049 private ApplicationHeader header = GWT.create(ApplicationHeader.class); 050 @Override 051 public void onModuleLoad() { 052 final ApplicationContext context = Application.getApplicationContext(); 053 054 final String injectString = LumTheme.INSTANCE.getLumCss().getCssString(); 055 StyleInjector.injectStylesheet(injectString); 056 057 try { 058 loadMessages(context); 059 loadApp(context); 060 } catch (Exception e) { 061 GWT.log("Error loading entrypoint", e); 062 } 063 } 064 065 private void initScreen(){ 066 manager = new ApplicationController("KualiStudent", header); 067 WindowTitleUtils.setApplicationTitle(Application.getApplicationContext().getMessage("applicationName")); 068 ApplicationPanel.get().add(manager); 069 ApplicationPanel.get().add(new KSFooter()); 070 HistoryManager.bind(manager, locations); 071 BreadcrumbManager.bind(manager); 072 HistoryManager.processWindowLocation(); 073 if(manager.getCurrentView() == null) 074 manager.showDefaultView(Controller.NO_OP_CALLBACK); 075 header.setHeaderTitle(Application.getApplicationContext().getMessage("applicationTitleLabel")); 076 } 077 078 private void loadMessages(final ApplicationContext context) throws SerializationException { 079 MessageList commonMessageList = getMsgSerializedObject("commonMessages" ); 080 MessageList lumMessageList = getMsgSerializedObject("luMessages" ); 081 context.addMessages(commonMessageList.getMessages()); 082 context.addMessages(lumMessageList.getMessages()); 083 } 084 085 @SuppressWarnings("unchecked") 086 public <T> T getMsgSerializedObject(String key ) throws SerializationException 087 { 088 String serialized = BrowserUtils.getString( key ); 089 SerializationStreamFactory ssf = GWT.create( MessagesRpcService.class); // magic 090 SerializationStreamReader ssr = ssf.createStreamReader( serialized ); 091 T ret = (T)ssr.readObject(); 092 return ret; 093 } 094 095 public void loadApp(final ApplicationContext context){ 096 SecurityRpcServiceAsync securityRpc = GWT.create(SecurityRpcService.class); 097 098 securityRpc.getPrincipalUsername(new KSAsyncCallback<String>(){ 099 public void handleFailure(Throwable caught) { 100 context.setUserId("Unknown"); 101 initScreen(); 102 } 103 104 @Override 105 public void onSuccess(String principalId) { 106 context.setUserId(principalId); 107 initScreen(); 108 } 109 }); 110 } 111 112 }