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