Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.DelayedToolView
 
Classes in this File Line Coverage Branch Coverage Complexity
DelayedToolView
0%
0/34
0%
0/4
1.125
DelayedToolView$1
0%
0/9
N/A
1.125
 
 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;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.student.common.ui.client.mvc.Callback;
 21  
 import org.kuali.student.common.ui.client.mvc.Controller;
 22  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 23  
 import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel;
 24  
 
 25  
 import com.google.gwt.user.client.Window;
 26  
 import com.google.gwt.user.client.ui.LazyPanel;
 27  
 import com.google.gwt.user.client.ui.Widget;
 28  
 
 29  
 /**
 30  
  * A view that delays its generation until it requested to be shown.
 31  
  * 
 32  
  * @author Kuali Student Team
 33  
  *
 34  
  */
 35  0
 public abstract class DelayedToolView extends LazyPanel implements ToolView{
 36  
     private Controller controller;    
 37  
     private Enum<?> viewEnum;
 38  
     private String viewName;    //View name is being used as menu item label   
 39  
 
 40  
     private HasReferenceId reference;
 41  
     
 42  0
     private ModelRequestCallback<ReferenceModel> modelRequestCallback = 
 43  0
         new ModelRequestCallback<ReferenceModel>(){
 44  
             public void onModelReady(ReferenceModel model) {
 45  0
                 reference.setReferenceId(model.getReferenceId());
 46  0
                 reference.setReferenceTypeKey(model.getReferenceTypeKey());
 47  0
                 reference.setReferenceType(model.getReferenceType());
 48  0
                 reference.setReferenceState(model.getReferenceState());
 49  0
                 DelayedToolView.this.setVisible(true);       
 50  0
             }
 51  
     
 52  
             public void onRequestFail(Throwable cause) {
 53  0
                 Window.alert(cause.toString());
 54  0
             }
 55  
     };
 56  
     
 57  
     
 58  
     /**
 59  
      * @param controller
 60  
      * @param name
 61  
      */
 62  0
     public DelayedToolView(Controller controller, Enum<?> viewEnum, String viewName) {
 63  0
         this.controller = controller;
 64  0
         this.viewName = viewName;
 65  0
         this.viewEnum = viewEnum;
 66  0
     }
 67  
 
 68  
 
 69  0
     public DelayedToolView(Enum<?> viewEnum, String viewName) {
 70  0
         this.controller = null;
 71  0
         this.viewEnum = viewEnum;
 72  0
         this.viewName = viewName;
 73  0
     }
 74  
    
 75  
     @Override
 76  
     public void beforeShow(final Callback<Boolean> onReadyCallback){
 77  0
         if (getWidget() instanceof HasReferenceId){
 78  0
             reference = (HasReferenceId)getWidget();
 79  0
             controller.requestModel(ReferenceModel.class, modelRequestCallback);
 80  0
         } else if (this instanceof HasReferenceId){
 81  0
             reference = (HasReferenceId)this;
 82  0
             controller.requestModel(ReferenceModel.class, modelRequestCallback);            
 83  
         } else {
 84  0
             this.setVisible(true);
 85  
         }
 86  
         // FIXME ? need to wire onReadyCallback into the model request, so that we aren't indicating that we're ready before the model is available?
 87  0
         onReadyCallback.exec(true);
 88  0
     }
 89  
 
 90  
     /**
 91  
      * @see org.kuali.student.common.ui.client.mvc.View#beforeHide()
 92  
      */
 93  
     @Override
 94  
     public boolean beforeHide() {
 95  0
         return true;
 96  
     }
 97  
 
 98  
 
 99  
     /**
 100  
      * @see org.kuali.student.common.ui.client.mvc.View#getController()
 101  
      */
 102  
     @Override
 103  
     public Controller getController() {
 104  0
         return this.controller;
 105  
     }
 106  
 
 107  
 
 108  
     /**
 109  
      * @see org.kuali.student.common.ui.client.mvc.View#getName()
 110  
      */
 111  
     @Override
 112  
     public String getName() {
 113  0
         return this.viewName;
 114  
     }
 115  
 
 116  
     public Enum<?> getViewEnum() {
 117  0
         return viewEnum;
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see org.kuali.student.common.ui.client.mvc.View#updateModel()
 122  
      */
 123  
     @Override
 124  
     public void updateModel() {
 125  
         //There is no model to update here, reference model is read-only        
 126  0
     }
 127  
     
 128  
     public void setController(Controller controller){
 129  0
         this.controller = controller;
 130  0
     }
 131  
 
 132  
     
 133  
     public Widget asWidget(){
 134  0
             return this;
 135  
     }
 136  
     
 137  
     @Override
 138  
     public String collectHistory(String historyStack) {
 139  0
             return null;
 140  
     }
 141  
 
 142  
 
 143  
         @Override
 144  
         protected Widget createWidget() {
 145  
                 // TODO Auto-generated method stub
 146  0
                 return null;
 147  
         }
 148  
 
 149  
         @Override
 150  
         public void onHistoryEvent(String historyStack) {
 151  
                 
 152  0
         }
 153  
 
 154  
         @Override
 155  
         public void collectBreadcrumbNames(List<String> names) {
 156  0
                 names.add(this.getName());
 157  
                 
 158  0
         }
 159  
 }