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.Group;
21  import org.kuali.rice.krad.uif.container.TreeGroup;
22  import org.kuali.rice.krad.uif.field.DataField;
23  import org.kuali.rice.krad.uif.util.ComponentUtils;
24  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
25  import org.kuali.rice.krad.uif.view.View;
26  import org.kuali.rice.krms.dto.AgendaEditor;
27  import org.kuali.rice.krms.service.RuleViewHelperService;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * @author Kuali Student Team
34   */
35  public class AgendaSection extends Group {
36  
37      private String propertyName;
38      private BindingInfo bindingInfo;
39  
40      private Group agendaPrototype;
41      private Group rulePrototype;
42  
43      private AgendaBuilder agendaBuilder;
44  
45      @Override
46      public void performInitialization(View view, Object model) {
47          setFieldBindingObjectPath(getBindingInfo().getBindingObjectPath());
48  
49          super.performInitialization(view, model);
50  
51          if (bindingInfo != null) {
52              bindingInfo.setDefaults(view, getPropertyName());
53          }
54  
55      }
56  
57      @Override
58      public void performApplyModel(View view, Object model, Component parent) {
59          // get the collection for this group from the model
60          List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model,
61                  this.getBindingInfo().getBindingPath());
62  
63          //Set the ruleviewhelperservice on the agendabuilder.
64          this.getAgendaBuilder().setViewHelperService((RuleViewHelperService) view.getViewHelperService());
65  
66          // create agenda sections for each agenda
67          List<Component> items = new ArrayList<Component>();
68          for (int index = 0; index < modelCollection.size(); index++) {
69              AgendaEditor agenda = (AgendaEditor) modelCollection.get(index);
70              items.add(this.getAgendaBuilder().buildAgenda(agenda, index, this));
71          }
72          this.setItems(items);
73  
74          super.performApplyModel(view, model, parent);
75      }
76  
77      @Override
78      public List<Component> getComponentsForLifecycle() {
79          return super.getComponentsForLifecycle();
80      }
81  
82      @Override
83      public List<Component> getComponentPrototypes() {
84          List<Component> components = super.getComponentPrototypes();
85          components.add(this.getAgendaPrototype());
86          components.add(this.getRulePrototype());
87  
88          return components;
89      }
90  
91      public AgendaBuilder getAgendaBuilder() {
92          if (this.agendaBuilder == null) {
93              this.agendaBuilder = new AgendaBuilder();
94          }
95          return this.agendaBuilder;
96      }
97  
98      public String getPropertyName() {
99          return propertyName;
100     }
101 
102     public void setPropertyName(String propertyName) {
103         this.propertyName = propertyName;
104     }
105 
106     public BindingInfo getBindingInfo() {
107         return bindingInfo;
108     }
109 
110     public void setBindingInfo(BindingInfo bindingInfo) {
111         this.bindingInfo = bindingInfo;
112     }
113 
114     public Group getAgendaPrototype() {
115         return agendaPrototype;
116     }
117 
118     public void setAgendaPrototype(Group agendaPrototype) {
119         this.agendaPrototype = agendaPrototype;
120     }
121 
122     public Group getRulePrototype() {
123         return rulePrototype;
124     }
125 
126     public void setRulePrototype(Group rulePrototype) {
127         this.rulePrototype = rulePrototype;
128     }
129 }