Coverage Report - org.kuali.student.lum.lu.ui.main.client.LUMMainEntryPoint
 
Classes in this File Line Coverage Branch Coverage Complexity
LUMMainEntryPoint
0%
0/37
0%
0/2
1.286
LUMMainEntryPoint$1
0%
0/7
N/A
1.286
 
 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;
 17  
 
 18  
 
 19  
 import org.kuali.student.common.messages.dto.MessageList;
 20  
 import org.kuali.student.common.ui.client.application.Application;
 21  
 import org.kuali.student.common.ui.client.application.ApplicationContext;
 22  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 23  
 import org.kuali.student.common.ui.client.mvc.Controller;
 24  
 import org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbManager;
 25  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 26  
 import org.kuali.student.common.ui.client.service.MessagesRpcService;
 27  
 import org.kuali.student.common.ui.client.service.SecurityRpcService;
 28  
 import org.kuali.student.common.ui.client.service.SecurityRpcServiceAsync;
 29  
 import org.kuali.student.common.ui.client.util.BrowserUtils;
 30  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 31  
 import org.kuali.student.common.ui.client.widgets.ApplicationPanel;
 32  
 import org.kuali.student.common.ui.client.widgets.KSFooter;
 33  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 34  
 import org.kuali.student.lum.lu.ui.main.client.controllers.ApplicationController;
 35  
 import org.kuali.student.lum.lu.ui.main.client.theme.LumTheme;
 36  
 import org.kuali.student.lum.lu.ui.main.client.widgets.ApplicationHeader;
 37  
 
 38  
 import com.google.gwt.core.client.EntryPoint;
 39  
 import com.google.gwt.core.client.GWT;
 40  
 import com.google.gwt.dom.client.StyleInjector;
 41  
 import com.google.gwt.user.client.rpc.SerializationException;
 42  
 import com.google.gwt.user.client.rpc.SerializationStreamFactory;
 43  
 import com.google.gwt.user.client.rpc.SerializationStreamReader;
 44  
 
 45  0
 public class LUMMainEntryPoint implements EntryPoint{
 46  
 
 47  0
     private ApplicationController manager = null;
 48  0
     private AppLocations locations = new AppLocations();
 49  0
     private ApplicationHeader header = GWT.create(ApplicationHeader.class);
 50  
     @Override
 51  
     public void onModuleLoad() {
 52  0
         final ApplicationContext context = Application.getApplicationContext();
 53  
 
 54  0
         final String injectString = LumTheme.INSTANCE.getLumCss().getCssString();
 55  0
         StyleInjector.injectStylesheet(injectString);   
 56  
 
 57  
         try {
 58  0
             loadMessages(context);                    
 59  0
             loadApp(context);
 60  0
         } catch (Exception e) {
 61  0
             GWT.log("Error loading entrypoint", e);
 62  0
         } 
 63  0
     }
 64  
 
 65  
     private void initScreen(){
 66  0
         manager = new ApplicationController("KualiStudent", header);
 67  0
         WindowTitleUtils.setApplicationTitle(Application.getApplicationContext().getMessage("applicationName"));
 68  0
         ApplicationPanel.get().add(manager);
 69  0
         ApplicationPanel.get().add(new KSFooter());
 70  0
         HistoryManager.bind(manager, locations);
 71  0
         BreadcrumbManager.bind(manager);
 72  0
         HistoryManager.processWindowLocation();
 73  0
         if(manager.getCurrentView() == null)
 74  0
             manager.showDefaultView(Controller.NO_OP_CALLBACK);
 75  0
         header.setHeaderTitle(Application.getApplicationContext().getMessage("applicationTitleLabel"));
 76  0
     }
 77  
     
 78  
     private void loadMessages(final ApplicationContext context) throws SerializationException {
 79  0
         MessageList commonMessageList =  getMsgSerializedObject("commonMessages" );
 80  0
         MessageList lumMessageList =  getMsgSerializedObject("luMessages" );
 81  0
         context.addMessages(commonMessageList.getMessages());
 82  0
         context.addMessages(lumMessageList.getMessages());
 83  0
     }
 84  
 
 85  
     @SuppressWarnings("unchecked")
 86  
     public  <T> T getMsgSerializedObject(String key ) throws SerializationException
 87  
     {
 88  0
         String serialized = BrowserUtils.getString( key );
 89  0
         SerializationStreamFactory ssf = GWT.create( MessagesRpcService.class); // magic
 90  0
         SerializationStreamReader ssr = ssf.createStreamReader( serialized );
 91  0
         T ret = (T)ssr.readObject();
 92  0
         return ret;
 93  
     } 
 94  
       
 95  
     public void loadApp(final ApplicationContext context){
 96  0
         SecurityRpcServiceAsync securityRpc = GWT.create(SecurityRpcService.class);
 97  
         
 98  0
         securityRpc.getPrincipalUsername(new KSAsyncCallback<String>(){
 99  
             public void handleFailure(Throwable caught) {
 100  0
                 context.setUserId("Unknown");
 101  0
                 initScreen();
 102  0
             }
 103  
 
 104  
             @Override
 105  
             public void onSuccess(String principalId) {
 106  0
                 context.setUserId(principalId);
 107  0
                 initScreen();
 108  0
             }            
 109  
         });
 110  0
     }
 111  
 
 112  
 }