Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.views.SectionView
 
Classes in this File Line Coverage Branch Coverage Complexity
SectionView
0%
0/60
0%
0/16
1.29
SectionView$1
0%
0/9
N/A
1.29
SectionView$2
0%
0/2
N/A
1.29
SectionView$3
0%
0/6
N/A
1.29
 
 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.common.ui.client.configurable.mvc.views;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.assembly.data.Metadata;
 22  
 import org.kuali.student.common.assembly.data.ModelDefinition;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.LayoutController;
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 27  
 import org.kuali.student.common.ui.client.mvc.Callback;
 28  
 import org.kuali.student.common.ui.client.mvc.Controller;
 29  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 30  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 31  
 import org.kuali.student.common.ui.client.mvc.View;
 32  
 
 33  
 import com.google.gwt.user.client.Window;
 34  
 import com.google.gwt.user.client.ui.Widget;
 35  
 
 36  
 
 37  
 /**
 38  
  * A view implementation of a section.  A section view is used to add sections as views to a controller.
 39  
  * 
 40  
  * @author Kuali Student
 41  
  *
 42  
  */
 43  
 public abstract class SectionView extends BaseSection implements View {
 44  
 
 45  
     protected String modelId;
 46  
     protected DataModel model;
 47  
 
 48  
     private Enum<?> viewEnum;
 49  
     private String viewName;
 50  
 
 51  0
     private List<View> views = new ArrayList<View>();
 52  
 
 53  0
     public SectionView() {}
 54  
 
 55  
     /**
 56  
      * @param viewEnum Enumeration of this view - id used for navigation, history, and showing a view
 57  
      * @param viewName Name of this view - what this view is called in the breadcrumb
 58  
      */
 59  0
     public SectionView(Enum<?> viewEnum, String viewName) {
 60  0
         this.viewEnum = viewEnum;
 61  0
         this.viewName = viewName;
 62  0
     }
 63  
     
 64  
     public void init(Enum<?> viewEnum, String viewName) {
 65  0
         this.viewEnum = viewEnum;
 66  0
         this.viewName = viewName;
 67  0
     }
 68  
 
 69  
     /**
 70  
      * This method gets view name enumeration
 71  
      *
 72  
      * @return
 73  
      */
 74  
     @Override
 75  
     public Enum<?> getViewEnum() {
 76  0
         return viewEnum;
 77  
     }
 78  
 
 79  
     public void setViewEnum(Enum<?> viewEnum) {
 80  0
         this.viewEnum = viewEnum;
 81  0
     }
 82  
 
 83  
 
 84  
     /**
 85  
      * Called by controller before the view is displayed to allow lazy initialization or any other preparatory work to be
 86  
      * done.
 87  
      * In SectionView, the section is cleared of all validation errors, the model is requested from its parent
 88  
      * controller, the widgets are updated with the latest data, and beforeShow is called on all of its potential child
 89  
      * views.
 90  
      */
 91  
     @Override
 92  
     public void beforeShow(final Callback<Boolean> onReadyCallback) {
 93  
 
 94  0
         super.clearValidationErrors();
 95  
         
 96  0
         if (getController() != null) {
 97  0
             getController().requestModel(modelId, new ModelRequestCallback<DataModel>() {
 98  
 
 99  
                 @Override
 100  
                 public void onRequestFail(Throwable cause) {        //Don't place a breakpoint here:  It will stall debugging for some unknown reason!
 101  0
                     Window.alert("Failed to get model: "  + modelId + " for SectionView " + getName());
 102  0
                     onReadyCallback.exec(false);
 103  0
                 }
 104  
 
 105  
                 @Override        //Don't place a breakpoint here:  It will stall debugging for some unknown reason!
 106  
                 public void onModelReady(DataModel m) {
 107  0
                     model = m;
 108  0
                     updateWidgetData(m);
 109  0
                     resetFieldInteractionFlags();
 110  0
                     onReadyCallback.exec(true);
 111  0
                 }
 112  
 
 113  
             });
 114  
         }
 115  
 
 116  0
         for (Section section : sections) {
 117  0
             if (section instanceof SectionView) {
 118  0
                 ((SectionView) section).beforeShow(new Callback<Boolean>() {
 119  
                     @Override        //Don't place a breakpoint here:  It will stall debugging for some unknown reason!
 120  
                     public void exec(Boolean result) {
 121  0
                     }
 122  
                 });
 123  
             }
 124  
         }
 125  0
         for (View view : views) {
 126  0
             view.beforeShow(Controller.NO_OP_CALLBACK);
 127  
         }
 128  
 
 129  0
     }
 130  
 
 131  
     public String getModelId() {
 132  0
         return modelId;
 133  
     }
 134  
 
 135  
     public void setModelId(String modelId) {
 136  0
         this.modelId = modelId;
 137  0
     }
 138  
 
 139  
     /**
 140  
      * Called by the controller before the view is hidden to allow the view to perform cleanup or request confirmation from
 141  
      * the user, etc. Can cancel the action by returning false.
 142  
      *
 143  
      * @return true if the view can be hidden, or false to cancel the action.
 144  
      */
 145  
     @Override
 146  
     public boolean beforeHide() {
 147  0
         return true;
 148  
     }
 149  
 
 150  
     /**
 151  
      * Returns the controller associated with the view
 152  
      *
 153  
      * @see org.kuali.student.common.ui.client.mvc.View#getController()
 154  
      */
 155  
     @Override
 156  
     public Controller getController() {
 157  0
         return super.getLayoutController();
 158  
     }
 159  
 
 160  
     /**
 161  
      * Returns the view's name
 162  
      *
 163  
      * @see org.kuali.student.common.ui.client.mvc.View#getName()
 164  
      */
 165  
     @Override
 166  
     public String getName() {
 167  0
         return viewName;
 168  
     }
 169  
 
 170  
     public void setName(String name) {
 171  0
         this.viewName = name;
 172  0
     }
 173  
 
 174  
     public void setController(Controller controller) {
 175  0
         if (controller instanceof LayoutController) {
 176  0
             super.setLayoutController((LayoutController) controller);
 177  
         } else {
 178  0
             throw new IllegalArgumentException("Configurable UI sections require a LayoutController, not a base MVC controller");
 179  
         }
 180  0
     }
 181  
 
 182  
     /**
 183  
      * Update the fields on the screen with the model received back from requestModel on the parent controller
 184  
      */
 185  
     public void updateView() {
 186  0
         getController().requestModel(modelId, new ModelRequestCallback<DataModel>() {
 187  
             @Override
 188  
             public void onModelReady(DataModel m) {
 189  
                 // TODO review this, shouldn't it assign this.model = m?
 190  0
                 SectionView.this.model = m;
 191  0
                 updateWidgetData(m);
 192  0
             }
 193  
 
 194  
 
 195  
             @Override
 196  
             public void onRequestFail(Throwable cause) {
 197  0
                 Window.alert("Failed to get model");
 198  0
             }
 199  
         });
 200  
 
 201  0
     }
 202  
 
 203  
     /**
 204  
      * Force an update of fields on this section with the model passed in
 205  
      * @param m
 206  
      */
 207  
     public void updateView(DataModel m) {
 208  0
         this.model = m;
 209  0
         updateWidgetData(m);
 210  0
     }
 211  
 
 212  
     /**
 213  
      * @see org.kuali.student.common.ui.client.mvc.View#asWidget()
 214  
      */
 215  
     public Widget asWidget() {
 216  0
         return this.getLayout();
 217  
     }
 218  
 
 219  
     /**
 220  
      * @see org.kuali.student.common.ui.client.mvc.history.HistorySupport#collectHistory(java.lang.String)
 221  
      */
 222  
     @Override
 223  
     public String collectHistory(String historyStack) {
 224  0
         return null;
 225  
     }
 226  
 
 227  
     /**
 228  
      * @see org.kuali.student.common.ui.client.mvc.history.HistorySupport#onHistoryEvent(java.lang.String)
 229  
      */
 230  
     @Override
 231  
     public void onHistoryEvent(String historyStack) {
 232  
 
 233  0
     }
 234  
 
 235  
     /**
 236  
      * @see org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbSupport#collectBreadcrumbNames(java.util.List)
 237  
      */
 238  
     @Override
 239  
     public void collectBreadcrumbNames(List<String> names) {
 240  0
         names.add(this.getName());
 241  0
     }
 242  
 
 243  
     /**
 244  
      * Add a view as a widget to this section
 245  
      * @param view
 246  
      */
 247  
     public void addView(View view) {
 248  0
         views.add(view);
 249  0
         addWidget(view.asWidget());
 250  0
     }
 251  
 
 252  
     public DataModel getModel() {
 253  0
         return model;
 254  
     }
 255  
 
 256  
     public void updateMetadata(ModelDefinition modelDefinition) {
 257  0
         updateMetadata(modelDefinition, this);
 258  0
     }
 259  
 
 260  
     private void updateMetadata(ModelDefinition modelDefinition, Section topSection) {
 261  0
         for (Section section : topSection.getSections()) {
 262  0
             updateMetadata(modelDefinition, section);
 263  
         }
 264  0
         for (FieldDescriptor field : topSection.getFields()) {
 265  0
             Metadata newMetadata = modelDefinition.getMetadata(field.getFieldKey());
 266  0
             if (newMetadata != null) {
 267  0
                 field.setMetadata(newMetadata);
 268  
             }
 269  0
         }
 270  0
     }
 271  
 
 272  
     @Override
 273  
     public String toString() {
 274  0
         return viewName;
 275  
     }
 276  
     
 277  
     public boolean isExportButtonActive() {
 278  0
         return false;
 279  
     }
 280  
 
 281  
         @Override
 282  
         public void showExport(boolean show) {
 283  
                 // TODO Auto-generated method stub
 284  
                 
 285  0
         }
 286  
 }