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.mvc;
17  
18  import java.util.List;
19  
20  import org.kuali.student.common.ui.client.security.AuthorizationCallback;
21  import org.kuali.student.common.ui.client.security.RequiresAuthorization;
22  import org.kuali.student.core.rice.authorization.PermissionType;
23  
24  
25  /**
26   * This is a simple view composite that delegates all view operations to nested
27   * controller. Use of this view allows you to nest controllers in the view
28   * hierarchy.
29   * 
30   * @author Kuali Student Team
31   *
32   */
33  public class DelegatingViewComposite extends ViewComposite implements RequiresAuthorization {
34      Controller childController;
35      
36      /**
37       * @param controller
38       * @param name
39       */
40      public DelegatingViewComposite(Controller parentController, Controller childController, Enum<?> viewType) {
41          super(parentController, "DelegatingViewComposite", viewType);
42          initWidget(childController);
43          this.childController = childController;
44      }
45  
46      /**
47       * Delegates beforeHide to the nested controllers current view
48       * 
49       * @see org.kuali.student.common.ui.client.mvc.View#beforeHide()
50       */
51      @Override
52      public boolean beforeHide() {
53          return childController.getCurrentView().beforeHide();
54      }
55  
56      /**
57       * @see org.kuali.student.common.ui.client.mvc.View#beforeShow()
58       */
59      @Override
60      public void beforeShow(final Callback<Boolean> onReadyCallback) {
61          if (childController.getCurrentView() == null){
62              childController.showDefaultView(onReadyCallback);
63          } else {
64              childController.getCurrentView().beforeShow(onReadyCallback);
65          }
66      }
67      
68      public Controller getChildController(){
69          return childController;
70      }
71      
72      public void setChildController(Controller controller){
73          this.childController = controller;
74      }
75      
76      @Override
77  	public String collectHistory(String historyStack) {
78  		return childController.collectHistory(historyStack);
79  	}
80  
81  	@Override
82  	public void onHistoryEvent(String historyStack) {
83  		childController.onHistoryEvent(historyStack);
84  	}
85  
86  	@Override
87      public void clear() {
88      	childController.resetCurrentView();
89      }
90  
91  	@Override
92  	public void checkAuthorization(PermissionType permissionType, AuthorizationCallback callback) {
93  		if (childController instanceof RequiresAuthorization){
94  			((RequiresAuthorization)childController).checkAuthorization(permissionType, callback);
95  		}				
96  	}
97  
98  	@Override
99  	public boolean isAuthorizationRequired() {
100 		if (childController instanceof RequiresAuthorization){
101 			return ((RequiresAuthorization)childController).isAuthorizationRequired();
102 		} else {
103 			return false;
104 		}
105 	}
106 
107 	@Override
108 	public void setAuthorizationRequired(boolean required) {
109 		if (childController instanceof RequiresAuthorization){
110 			((RequiresAuthorization)childController).setAuthorizationRequired(required);
111 		}		
112 	}
113 
114 	@Override
115 	public void collectBreadcrumbNames(List<String> names) {
116 		childController.collectBreadcrumbNames(names);
117 		
118 	}
119 
120 }