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