View Javadoc

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  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      private ModelRequestCallback<ReferenceModel> modelRequestCallback = 
43          new ModelRequestCallback<ReferenceModel>(){
44              public void onModelReady(ReferenceModel model) {
45                  reference.setReferenceId(model.getReferenceId());
46                  reference.setReferenceTypeKey(model.getReferenceTypeKey());
47                  reference.setReferenceType(model.getReferenceType());
48                  reference.setReferenceState(model.getReferenceState());
49                  DelayedToolView.this.setVisible(true);       
50              }
51      
52              public void onRequestFail(Throwable cause) {
53                  Window.alert(cause.toString());
54              }
55      };
56      
57      
58      /**
59       * @param controller
60       * @param name
61       */
62      public DelayedToolView(Controller controller, Enum<?> viewEnum, String viewName) {
63          this.controller = controller;
64          this.viewName = viewName;
65          this.viewEnum = viewEnum;
66      }
67  
68  
69      public DelayedToolView(Enum<?> viewEnum, String viewName) {
70          this.controller = null;
71          this.viewEnum = viewEnum;
72          this.viewName = viewName;
73      }
74     
75      @Override
76      public void beforeShow(final Callback<Boolean> onReadyCallback){
77          if (getWidget() instanceof HasReferenceId){
78              reference = (HasReferenceId)getWidget();
79              controller.requestModel(ReferenceModel.class, modelRequestCallback);
80          } else if (this instanceof HasReferenceId){
81              reference = (HasReferenceId)this;
82              controller.requestModel(ReferenceModel.class, modelRequestCallback);            
83          } else {
84              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          onReadyCallback.exec(true);
88      }
89  
90      /**
91       * @see org.kuali.student.common.ui.client.mvc.View#beforeHide()
92       */
93      @Override
94      public boolean beforeHide() {
95          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         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         return this.viewName;
114     }
115 
116     public Enum<?> getViewEnum() {
117         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     }
127     
128     public void setController(Controller controller){
129         this.controller = controller;
130     }
131 
132     
133     public Widget asWidget(){
134     	return this;
135     }
136     
137     @Override
138     public String collectHistory(String historyStack) {
139     	return null;
140     }
141 
142 
143 	@Override
144 	protected Widget createWidget() {
145 		// TODO Auto-generated method stub
146 		return null;
147 	}
148 
149 	@Override
150 	public void onHistoryEvent(String historyStack) {
151 		
152 	}
153 
154 	@Override
155 	public void collectBreadcrumbNames(List<String> names) {
156 		names.add(this.getName());
157 		
158 	}
159 	
160 	   public boolean isExportButtonActive() {
161 	        return false;
162 	    }
163 }