001/** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.util; 017 018import org.kuali.rice.krad.uif.component.BindingInfo; 019import org.kuali.rice.krad.uif.component.Component; 020import org.kuali.rice.krad.uif.container.Group; 021import org.kuali.rice.krad.uif.container.TreeGroup; 022import org.kuali.rice.krad.uif.field.DataField; 023import org.kuali.rice.krad.uif.util.ComponentUtils; 024import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; 025import org.kuali.rice.krad.uif.view.View; 026import org.kuali.rice.krms.dto.AgendaEditor; 027import org.kuali.rice.krms.service.RuleViewHelperService; 028 029import java.util.ArrayList; 030import java.util.List; 031 032/** 033 * @author Kuali Student Team 034 */ 035public class AgendaSection extends Group { 036 037 private String propertyName; 038 private BindingInfo bindingInfo; 039 040 private Group agendaPrototype; 041 private Group rulePrototype; 042 043 private AgendaBuilder agendaBuilder; 044 045 @Override 046 public void performInitialization(View view, Object model) { 047 setFieldBindingObjectPath(getBindingInfo().getBindingObjectPath()); 048 049 super.performInitialization(view, model); 050 051 if (bindingInfo != null) { 052 bindingInfo.setDefaults(view, getPropertyName()); 053 } 054 055 } 056 057 @Override 058 public void performApplyModel(View view, Object model, Component parent) { 059 // get the collection for this group from the model 060 List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model, 061 this.getBindingInfo().getBindingPath()); 062 063 //Set the ruleviewhelperservice on the agendabuilder. 064 this.getAgendaBuilder().setViewHelperService((RuleViewHelperService) view.getViewHelperService()); 065 066 // create agenda sections for each agenda 067 List<Component> items = new ArrayList<Component>(); 068 for (int index = 0; index < modelCollection.size(); index++) { 069 AgendaEditor agenda = (AgendaEditor) modelCollection.get(index); 070 items.add(this.getAgendaBuilder().buildAgenda(agenda, index, this)); 071 } 072 this.setItems(items); 073 074 super.performApplyModel(view, model, parent); 075 } 076 077 @Override 078 public List<Component> getComponentsForLifecycle() { 079 return super.getComponentsForLifecycle(); 080 } 081 082 @Override 083 public List<Component> getComponentPrototypes() { 084 List<Component> components = super.getComponentPrototypes(); 085 components.add(this.getAgendaPrototype()); 086 components.add(this.getRulePrototype()); 087 088 return components; 089 } 090 091 public AgendaBuilder getAgendaBuilder() { 092 if (this.agendaBuilder == null) { 093 this.agendaBuilder = new AgendaBuilder(); 094 } 095 return this.agendaBuilder; 096 } 097 098 public String getPropertyName() { 099 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}