Coverage Report - org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserController
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogBrowserController
0%
0/33
0%
0/2
1.455
CatalogBrowserController$1
0%
0/3
N/A
1.455
CatalogBrowserController$2
0%
0/15
0%
0/2
1.455
CatalogBrowserController$3
0%
0/5
0%
0/2
1.455
CatalogBrowserController$CatalogBrowserViews
0%
0/2
N/A
1.455
 
 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.tools.client.configuration;
 17  
 
 18  
 import org.kuali.student.common.assembly.data.Data;
 19  
 import org.kuali.student.common.assembly.data.Metadata;
 20  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 21  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.TabMenuController;
 22  
 import org.kuali.student.common.ui.client.mvc.Callback;
 23  
 import org.kuali.student.common.ui.client.mvc.Controller;
 24  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 25  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 26  
 import org.kuali.student.common.ui.client.mvc.ModelProvider;
 27  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 28  
 import org.kuali.student.common.ui.client.service.MetadataRpcService;
 29  
 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync;
 30  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 31  
 import org.kuali.student.common.ui.client.widgets.containers.KSTitleContainerImpl;
 32  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 33  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 34  
 
 35  
 import com.google.gwt.core.client.GWT;
 36  
 
 37  
 
 38  0
 public class CatalogBrowserController extends TabMenuController
 39  
 {
 40  0
         private MetadataRpcServiceAsync metadataService = GWT.create(MetadataRpcService.class);
 41  0
         private final DataModel dataModel = new DataModel ();
 42  0
         private boolean initialized = false;
 43  
         private Controller controller;
 44  0
         private static KSTitleContainerImpl container = new KSTitleContainerImpl("Catalog Browser");
 45  0
         private BlockingTask initializingTask = new BlockingTask("Loading");
 46  
         
 47  
         //enum is necessary for the page to be added to breadcrumbs
 48  0
         public enum CatalogBrowserViews {
 49  0
                 COURSE_CATALOG
 50  
     };
 51  
 
 52  
         public CatalogBrowserController (Controller controller)        {
 53  0
                 super(CatalogBrowserController.class.getName());
 54  0
                 this.controller = controller;
 55  
                 //sets the name of the page to be used in breadcrumbs
 56  0
                 super.setName("Course Catalog");
 57  
                 //sets enum
 58  0
                 setViewEnum(CatalogBrowserViews.COURSE_CATALOG);
 59  0
                 initialize();
 60  0
         }
 61  
 
 62  
         private void initialize ()        {
 63  0
                 dataModel.setRoot(new Data ());
 64  
                 
 65  0
                 super.setDefaultModelId (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL);
 66  0
                 super.registerModel (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL, new ModelProvider<DataModel> () {
 67  
 
 68  
                         @Override
 69  
                         public void requestModel (final ModelRequestCallback<DataModel> callback) {
 70  0
                                 callback.onModelReady (dataModel);
 71  0
                         }
 72  
                 });
 73  0
         }
 74  
 
 75  
  private static final String METADATA_OBJECT_KEY_BROWSE = "browse";
 76  
 
 77  
         private void init (final Callback<Boolean> onReadyCallback)
 78  
         {
 79  
 
 80  0
                 if (initialized) {
 81  0
                         onReadyCallback.exec (true);
 82  
                 } else        {
 83  0
                     KSBlockingProgressIndicator.addTask(initializingTask);
 84  
                     
 85  0
                         metadataService.getMetadata (METADATA_OBJECT_KEY_BROWSE, null, null, new KSAsyncCallback<Metadata> (){
 86  
 
 87  
                                 @Override
 88  
                                 public void handleFailure (Throwable caught)
 89  
                                 {
 90  0
                                         onReadyCallback.exec (false);
 91  0
                                     KSBlockingProgressIndicator.removeTask(initializingTask);
 92  0
                                         throw new RuntimeException ("Failed to get model definition for " + METADATA_OBJECT_KEY_BROWSE, caught);
 93  
                                 }
 94  
 
 95  
                                 @Override
 96  
                                 public void onSuccess (Metadata result)
 97  
                                 {
 98  0
      if (result == null)
 99  
      {
 100  0
                                          onReadyCallback.exec (false);
 101  0
                     KSBlockingProgressIndicator.removeTask(initializingTask);
 102  0
                                          throw new RuntimeException ("Got null metdata for " + METADATA_OBJECT_KEY_BROWSE);
 103  
      }
 104  0
                                         DataModelDefinition def = new DataModelDefinition (result);
 105  0
                                         dataModel.setDefinition (def);
 106  0
                                         configure (def);
 107  0
                                         initialized = true;
 108  0
                                         onReadyCallback.exec (true);
 109  0
                                     KSBlockingProgressIndicator.removeTask(initializingTask);
 110  0
                                 }
 111  
                         });
 112  
                 }
 113  0
         }
 114  
 
 115  
         private void configure (DataModelDefinition modelDefinition)        {
 116  0
                 CatalogBrowserConfigurer cfg = GWT.create(CatalogBrowserConfigurer.class);
 117  0
                 cfg.setModelDefinition (modelDefinition);
 118  0
                 cfg.setController (controller);
 119  0
                 cfg.configureCatalogBrowser (this);
 120  0
         }
 121  
         
 122  
         @Override
 123  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 124  0
                 WindowTitleUtils.setContextTitle(name);
 125  0
                 dataModel.setRoot(new Data ());
 126  0
                 init (new Callback<Boolean> ()        {
 127  
 
 128  
                         @Override
 129  
                         public void exec (Boolean result)
 130  
                         {
 131  0
                                 if (result)        {
 132  0
                                         showDefaultView (onReadyCallback);
 133  
                                 } else        {
 134  0
                                         onReadyCallback.exec (false);
 135  
                                 }
 136  0
                         }
 137  
                         
 138  
                 });
 139  0
         }
 140  
 
 141  
         @Override
 142  
         public Enum<?> getViewEnumValue (String enumValue){
 143  0
                 return null;
 144  
         }
 145  
 
 146  
         @Override
 147  
         public void setParentController (Controller controller)        {
 148  0
                 super.setParentController (controller);
 149  0
         }
 150  
 
 151  
 }