View Javadoc
1   package org.kuali.ole.select.document.krad;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.apache.log4j.Logger;
7   import org.kuali.ole.coa.businessobject.options.SimpleChartValuesFinder;
8   import org.kuali.ole.module.purap.businessobject.InvoiceAccount;
9   import org.kuali.ole.select.businessobject.OlePurchaseOrderAccount;
10  import org.kuali.ole.select.document.OleInvoiceDocument;
11  import org.kuali.ole.select.form.OLEInvoiceForm;
12  import org.kuali.rice.core.api.util.KeyValue;
13  import org.kuali.rice.krad.uif.UifConstants;
14  import org.kuali.rice.krad.uif.UifPropertyPaths;
15  import org.kuali.rice.krad.uif.component.BindingInfo;
16  import org.kuali.rice.krad.uif.component.Component;
17  import org.kuali.rice.krad.uif.container.CollectionGroup;
18  import org.kuali.rice.krad.uif.container.Container;
19  import org.kuali.rice.krad.uif.container.Group;
20  import org.kuali.rice.krad.uif.element.Action;
21  import org.kuali.rice.krad.uif.field.Field;
22  import org.kuali.rice.krad.uif.field.FieldGroup;
23  import org.kuali.rice.krad.uif.layout.CollectionLayoutManager;
24  import org.kuali.rice.krad.uif.layout.LayoutManagerBase;
25  import org.kuali.rice.krad.uif.util.ComponentUtils;
26  import org.kuali.rice.krad.uif.view.View;
27  import org.kuali.rice.krad.uif.widget.QuickFinder;
28  
29  public class OleInvoiceAccountingLinesLayout extends LayoutManagerBase
30  		implements CollectionLayoutManager {
31  
32  	private static final long serialVersionUID = 5289870490845303915L;
33  	private static final Logger LOG = Logger
34  			.getLogger(OleInvoiceAccountingLinesLayout.class);
35  
36  	private List<OleInvoiceAccountingLine> accountingLines = new ArrayList<OleInvoiceAccountingLine>();
37  	private boolean foreignCurrency;
38  	private List<KeyValue> chartKeyValues;
39  
40  	private QuickFinder accountNumberQuickfinder;
41  	private QuickFinder subAccountNumberQuickfinder;
42  	private QuickFinder financialObjectCodeQuickfinder;
43  	private QuickFinder financialSubObjectCodeQuickfinder;
44  	private QuickFinder projectCodeQuickfinder;
45  
46  	private List<Component> components = new ArrayList<Component>();
47  
48  	@Override
49  	public void performApplyModel(View view, Object model, Container container) {
50  		if (LOG.isDebugEnabled())
51  			LOG.debug(container
52  					+ " ro is "
53  					+ container.isReadOnly()
54  					+ " "
55  					+ ((CollectionGroup) container).isRenderAddLine()
56  					+ " "
57  					+ ((CollectionGroup) container)
58  							.isRenderAddBlankLineButton());
59  
60  		chartKeyValues = new SimpleChartValuesFinder().getKeyValues();
61  		foreignCurrency = ((OleInvoiceDocument) ((OLEInvoiceForm) model)
62  				.getDocument()).isForeignCurrencyFlag();
63  
64  		super.performApplyModel(view, model, container);
65  	}
66  
67  	private <T extends Component> T createComponent(T prototype, View view,
68  			Object model, CollectionGroup collectionGroup,
69  			BindingInfo bindingInfo, String idSuffix, Object currentLine,
70  			int lineIndex) {
71  
72  		T rv = ComponentUtils.copy(prototype, idSuffix);
73  
74  		if (rv instanceof Group)
75  			((Group) rv).setFieldBindByNamePrefix(bindingInfo
76  					.getBindByNamePrefix());
77  
78  		if (rv instanceof QuickFinder) {
79  			QuickFinder qf = (QuickFinder) rv;
80  			qf.updateFieldConversions(bindingInfo);
81  			qf.updateLookupParameters(bindingInfo);
82  			qf.updateReferencesToRefresh(bindingInfo);
83  		}
84  
85  		ComponentUtils.updateContextForLine(rv, currentLine, lineIndex,
86  				idSuffix);
87  		view.getViewHelperService().spawnSubLifecyle(view, model, rv,
88  				collectionGroup, null, UifConstants.ViewPhases.INITIALIZE);
89  
90  		synchronized (components) {
91  			components.add(rv);
92  		}
93  
94  		return rv;
95  	}
96  
97  	@Override
98  	public void buildLine(View view, Object model,
99  			CollectionGroup collectionGroup, List<Field> lineFields,
100 			List<FieldGroup> subCollectionFields, String bindingPath,
101 			List<Action> actions, String idSuffix, Object currentLine,
102 			int lineIndex) {
103 
104 		BindingInfo bi = new BindingInfo();
105 		bi.setBindByNamePrefix(bindingPath
106 				.startsWith(UifPropertyPaths.NEW_COLLECTION_LINES) ? bindingPath
107 				: view.getDefaultBindingObjectPath() + '.' + bindingPath);
108 
109 		OleInvoiceAccountingLine line = new OleInvoiceAccountingLine();
110 		line.setLineId(collectionGroup.getId() + idSuffix);
111 		line.setBindPath(bi.getBindByNamePrefix());
112 
113 		if (currentLine instanceof OlePurchaseOrderAccount)
114 			line.setPoAccount((OlePurchaseOrderAccount) currentLine);
115 		else if (currentLine instanceof InvoiceAccount)
116 			line.setInvoiceAccount((InvoiceAccount) currentLine);
117 		else
118 			throw new UnsupportedOperationException("Unsupported data object "
119 					+ currentLine.getClass());
120 
121 		line.setAccountNumberQuickfinder(createComponent(
122 				accountNumberQuickfinder, view, model, collectionGroup, bi,
123 				idSuffix, currentLine, lineIndex));
124 		line.setSubAccountNumberQuickfinder(createComponent(
125 				subAccountNumberQuickfinder, view, model, collectionGroup, bi,
126 				idSuffix, currentLine, lineIndex));
127 		line.setFinancialObjectCodeQuickfinder(createComponent(
128 				financialObjectCodeQuickfinder, view, model, collectionGroup,
129 				bi, idSuffix, currentLine, lineIndex));
130 		line.setFinancialSubObjectCodeQuickfinder(createComponent(
131 				financialSubObjectCodeQuickfinder, view, model,
132 				collectionGroup, bi, idSuffix, currentLine, lineIndex));
133 		line.setProjectCodeQuickfinder(createComponent(projectCodeQuickfinder,
134 				view, model, collectionGroup, bi, idSuffix, currentLine,
135 				lineIndex));
136 
137 		line.setActions(actions);
138 
139 		synchronized (components) {
140 			components.addAll(actions);
141 		}
142 
143 		synchronized (accountingLines) {
144 			accountingLines.add(line);
145 		}
146 	}
147 
148 	public List<KeyValue> getChartKeyValues() {
149 		return chartKeyValues;
150 	}
151 
152 	public boolean isForeignCurrency() {
153 		return foreignCurrency;
154 	}
155 
156 	public void setForeignCurrency(boolean foreignCurrency) {
157 		this.foreignCurrency = foreignCurrency;
158 	}
159 
160 	public QuickFinder getAccountNumberQuickfinder() {
161 		return accountNumberQuickfinder;
162 	}
163 
164 	public void setAccountNumberQuickfinder(QuickFinder accountNumberQuickfinder) {
165 		this.accountNumberQuickfinder = accountNumberQuickfinder;
166 	}
167 
168 	public QuickFinder getSubAccountNumberQuickfinder() {
169 		return subAccountNumberQuickfinder;
170 	}
171 
172 	public void setSubAccountNumberQuickfinder(
173 			QuickFinder subAccountNumberQuickfinder) {
174 		this.subAccountNumberQuickfinder = subAccountNumberQuickfinder;
175 	}
176 
177 	public QuickFinder getFinancialObjectCodeQuickfinder() {
178 		return financialObjectCodeQuickfinder;
179 	}
180 
181 	public void setFinancialObjectCodeQuickfinder(
182 			QuickFinder financialObjectCodeQuickfinder) {
183 		this.financialObjectCodeQuickfinder = financialObjectCodeQuickfinder;
184 	}
185 
186 	public QuickFinder getFinancialSubObjectCodeQuickfinder() {
187 		return financialSubObjectCodeQuickfinder;
188 	}
189 
190 	public void setFinancialSubObjectCodeQuickfinder(
191 			QuickFinder financialSubObjectCodeQuickfinder) {
192 		this.financialSubObjectCodeQuickfinder = financialSubObjectCodeQuickfinder;
193 	}
194 
195 	public QuickFinder getProjectCodeQuickfinder() {
196 		return projectCodeQuickfinder;
197 	}
198 
199 	public void setProjectCodeQuickfinder(QuickFinder projectCodeQuickfinder) {
200 		this.projectCodeQuickfinder = projectCodeQuickfinder;
201 	}
202 
203 	public List<OleInvoiceAccountingLine> getAccountingLines() {
204 		return accountingLines;
205 	}
206 
207 	public void setAccountingLines(
208 			List<OleInvoiceAccountingLine> accountingLines) {
209 		this.accountingLines = accountingLines;
210 	}
211 
212 	@Override
213 	public FieldGroup getSubCollectionFieldGroupPrototype() {
214 		return null;
215 	}
216 
217 	@Override
218 	public List<Component> getComponentPrototypes() {
219 		List<Component> rv = super.getComponentPrototypes();
220 		rv.add(accountNumberQuickfinder);
221 		rv.add(subAccountNumberQuickfinder);
222 		rv.add(financialObjectCodeQuickfinder);
223 		rv.add(financialSubObjectCodeQuickfinder);
224 		rv.add(projectCodeQuickfinder);
225 		return rv;
226 	}
227 
228 	@Override
229 	public List<Component> getComponentsForLifecycle() {
230 		List<Component> rv = super.getComponentsForLifecycle();
231 		if (components != null)
232 			rv.addAll(components);
233 		return rv;
234 	}
235 
236 	@Override
237 	protected <T> void copyProperties(T copy) {
238 		super.copyProperties(copy);
239 
240 		OleInvoiceAccountingLinesLayout c = (OleInvoiceAccountingLinesLayout) copy;
241 		if (accountNumberQuickfinder != null)
242 			c.setAccountNumberQuickfinder(ComponentUtils
243 					.copy(accountNumberQuickfinder));
244 		if (subAccountNumberQuickfinder != null)
245 			c.setSubAccountNumberQuickfinder(ComponentUtils
246 					.copy(subAccountNumberQuickfinder));
247 		if (financialObjectCodeQuickfinder != null)
248 			c.setFinancialObjectCodeQuickfinder(ComponentUtils
249 					.copy(financialObjectCodeQuickfinder));
250 		if (financialSubObjectCodeQuickfinder != null)
251 			c.setFinancialSubObjectCodeQuickfinder(ComponentUtils
252 					.copy(financialSubObjectCodeQuickfinder));
253 		if (projectCodeQuickfinder != null)
254 			c.setProjectCodeQuickfinder(ComponentUtils
255 					.copy(projectCodeQuickfinder));
256 
257 	}
258 
259 }
260