View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.util;
17  
18  import org.kuali.rice.krad.uif.component.BindingInfo;
19  import org.kuali.rice.krad.uif.component.Component;
20  import org.kuali.rice.krad.uif.container.CollectionFilter;
21  import org.kuali.rice.krad.uif.container.Group;
22  import org.kuali.rice.krad.uif.container.TreeGroup;
23  import org.kuali.rice.krad.uif.element.Action;
24  import org.kuali.rice.krad.uif.element.Message;
25  import org.kuali.rice.krad.uif.field.DataField;
26  import org.kuali.rice.krad.uif.util.ComponentUtils;
27  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
28  import org.kuali.rice.krad.uif.view.View;
29  import org.kuali.rice.krad.uif.widget.QuickFinder;
30  import org.kuali.rice.krms.dto.AgendaEditor;
31  import org.kuali.rice.krms.service.RuleViewHelperService;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  /**
37   * @author Kuali Student Team
38   */
39  public class AgendaSection extends Group {
40  
41      private String propertyName;
42      private BindingInfo bindingInfo;
43  
44      private Group agendaPrototype;
45      private Group rulePrototype;
46  
47      private AgendaBuilder agendaBuilder;
48  
49      public AgendaSection(){
50          super();
51      }
52  
53      @Override
54      public void performInitialization(View view, Object model) {
55          setFieldBindingObjectPath(getBindingInfo().getBindingObjectPath());
56  
57          super.performInitialization(view, model);
58  
59          if (bindingInfo != null) {
60              bindingInfo.setDefaults(view, getPropertyName());
61          }
62  
63      }
64  
65      @Override
66      public void performApplyModel(View view, Object model, Component parent) {
67          // get the collection for this group from the model
68          List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model,
69                  this.getBindingInfo().getBindingPath());
70  
71          //Set the ruleviewhelperservice on the agendabuilder.
72          this.getAgendaBuilder().setViewHelperService((RuleViewHelperService) view.getViewHelperService());
73  
74          // create agenda sections for each agenda
75          List<Component> items = new ArrayList<Component>();
76          for (int index = 0; index < modelCollection.size(); index++) {
77              AgendaEditor agenda = (AgendaEditor) modelCollection.get(index);
78              items.add(this.getAgendaBuilder().buildAgenda(agenda, index, this));
79          }
80          this.setItems(items);
81  
82          super.performApplyModel(view, model, parent);
83      }
84  
85      @Override
86      public List<Component> getComponentsForLifecycle() {
87          return super.getComponentsForLifecycle();
88      }
89  
90      @Override
91      public List<Component> getComponentPrototypes() {
92          List<Component> components = super.getComponentPrototypes();
93          components.add(this.getAgendaPrototype());
94          components.add(this.getRulePrototype());
95  
96          return components;
97      }
98  
99      /**
100      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
101      */
102     @Override
103     protected <T> void copyProperties(T component) {
104         super.copyProperties(component);
105 
106         AgendaSection agendaSectionCopy = (AgendaSection) component;
107         agendaSectionCopy.setPropertyName(this.propertyName);
108         if (this.agendaPrototype != null){
109             agendaSectionCopy.setAgendaPrototype((Group) this.agendaPrototype.copy());
110         }
111         if (this.rulePrototype != null){
112             agendaSectionCopy.setRulePrototype((Group) this.rulePrototype.copy());
113         }
114         if (this.bindingInfo != null) {
115             agendaSectionCopy.setBindingInfo((BindingInfo) this.bindingInfo.copy());
116         }
117     }
118 
119     public AgendaBuilder getAgendaBuilder() {
120         if (this.agendaBuilder == null) {
121             this.agendaBuilder = new AgendaBuilder();
122         }
123         return this.agendaBuilder;
124     }
125 
126     public String getPropertyName() {
127         return propertyName;
128     }
129 
130     public void setPropertyName(String propertyName) {
131         this.propertyName = propertyName;
132     }
133 
134     public BindingInfo getBindingInfo() {
135         return bindingInfo;
136     }
137 
138     public void setBindingInfo(BindingInfo bindingInfo) {
139         this.bindingInfo = bindingInfo;
140     }
141 
142     public Group getAgendaPrototype() {
143         return agendaPrototype;
144     }
145 
146     public void setAgendaPrototype(Group agendaPrototype) {
147         this.agendaPrototype = agendaPrototype;
148     }
149 
150     public Group getRulePrototype() {
151         return rulePrototype;
152     }
153 
154     public void setRulePrototype(Group rulePrototype) {
155         this.rulePrototype = rulePrototype;
156     }
157 }