Coverage Report - org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserController
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogBrowserController
0%
0/31
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
 
 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.*;
 23  
 import org.kuali.student.common.ui.client.service.MetadataRpcService;
 24  
 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync;
 25  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 26  
 import org.kuali.student.common.ui.client.widgets.containers.KSTitleContainerImpl;
 27  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 28  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 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  
         @Override
 109  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 110  0
                 WindowTitleUtils.setContextTitle(name);
 111  0
                 dataModel.setRoot(new Data ());
 112  0
                 init (new Callback<Boolean> ()        {
 113  
 
 114  
                         @Override
 115  
                         public void exec (Boolean result)
 116  
                         {
 117  0
                                 if (result)        {
 118  0
                                         showDefaultView (onReadyCallback);
 119  
                                 } else        {
 120  0
                                         onReadyCallback.exec (false);
 121  
                                 }
 122  0
                         }
 123  
 
 124  
                 });
 125  0
         }
 126  
 
 127  
         @Override
 128  
         public Enum<?> getViewEnumValue (String enumValue){
 129  0
                 return null;
 130  
         }
 131  
 
 132  
         @Override
 133  
         public void setParentController (Controller controller)        {
 134  0
                 super.setParentController (controller);
 135  0
         }
 136  
 
 137  
 }