1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.datadictionary;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.sys.businessobject.AccountingLine;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.service.DynamicNameLabelGenerator;
25 import org.kuali.ole.sys.document.web.AccountingLineViewField;
26 import org.kuali.ole.sys.document.web.AccountingLineViewOverrideField;
27 import org.kuali.ole.sys.document.web.TableJoining;
28 import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
29 import org.kuali.rice.kns.service.DataDictionaryService;
30 import org.kuali.rice.kns.util.FieldUtils;
31 import org.kuali.rice.kns.web.ui.Field;
32 import org.kuali.rice.kns.web.ui.FieldBridge;
33
34
35
36
37 public class AccountingLineViewFieldDefinition extends MaintainableFieldDefinition implements AccountingLineViewRenderableElementDefinition {
38 private String dynamicLabelProperty;
39 private boolean useShortLabel = false;
40 private boolean hidden = false;
41 private List<AccountingLineViewOverrideFieldDefinition> overrideFields;
42 private String dynamicNameLabelGeneratorBeanName;
43 private int overrideColSpan = -1;
44 private Class<? extends AccountingLineViewField> accountingLineViewFieldClass = org.kuali.ole.sys.document.web.AccountingLineViewField.class;
45 private String overrideLookupParameters;
46
47 private DynamicNameLabelGenerator dynamicNameLabelGenerator;
48
49
50
51
52
53 public String getDynamicLabelProperty() {
54 return dynamicLabelProperty;
55 }
56
57
58
59
60
61 public void setDynamicLabelProperty(String dynamicLabelProperty) {
62 this.dynamicLabelProperty = dynamicLabelProperty;
63 }
64
65
66
67
68
69 public boolean shouldUseShortLabel() {
70 return useShortLabel;
71 }
72
73
74
75
76
77 public void setUseShortLabel(boolean useShortLabel) {
78 this.useShortLabel = useShortLabel;
79 }
80
81
82
83
84
85 public boolean isHidden() {
86 return hidden;
87 }
88
89
90
91
92
93 public void setHidden(boolean hidden) {
94 this.hidden = hidden;
95 }
96
97
98
99
100
101 public List<AccountingLineViewOverrideFieldDefinition> getOverrideFields() {
102 return overrideFields;
103 }
104
105
106
107
108
109 public void setOverrideFields(List<AccountingLineViewOverrideFieldDefinition> overrideFields) {
110 this.overrideFields = overrideFields;
111 }
112
113
114
115
116
117 public String getDynamicNameLabelGeneratorBeanName() {
118 return dynamicNameLabelGeneratorBeanName;
119 }
120
121
122
123
124
125 public void setDynamicNameLabelGeneratorBeanName(String dynamicNameLabelGeneratorBeanName) {
126 this.dynamicNameLabelGeneratorBeanName = dynamicNameLabelGeneratorBeanName;
127 }
128
129
130
131
132
133 public int getOverrideColSpan() {
134 return overrideColSpan;
135 }
136
137
138
139
140
141 public void setOverrideColSpan(int overrideColSpan) {
142 this.overrideColSpan = overrideColSpan;
143 }
144
145
146
147
148
149 public Class<? extends AccountingLineViewField> getAccountingLineViewFieldClass() {
150 return accountingLineViewFieldClass;
151 }
152
153
154
155
156
157 public void setAccountingLineViewFieldClass(Class<? extends AccountingLineViewField> accountingLineViewFieldClass) {
158 if (accountingLineViewFieldClass != null) {
159 this.accountingLineViewFieldClass = accountingLineViewFieldClass;
160 }
161 }
162
163
164
165
166
167 public DynamicNameLabelGenerator getDynamicNameLabelGenerator() {
168 if (!StringUtils.isBlank(dynamicNameLabelGeneratorBeanName) && dynamicNameLabelGenerator == null) {
169 dynamicNameLabelGenerator = SpringContext.getBean(DynamicNameLabelGenerator.class,dynamicNameLabelGeneratorBeanName);
170 }
171 return dynamicNameLabelGenerator;
172 }
173
174
175
176
177 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
178 AccountingLineViewField layoutElement = getNewAccountingLineViewField();
179 layoutElement.setDefinition(this);
180 layoutElement.setField(getKNSFieldForDefinition(accountingLineClass));
181 layoutElement.setOverrideFields(getFieldsForOverrideFields(layoutElement, accountingLineClass));
182 return layoutElement;
183 }
184
185
186
187
188
189 protected AccountingLineViewField getNewAccountingLineViewField() {
190 AccountingLineViewField layoutElement = null;
191 try {
192 layoutElement = (AccountingLineViewField)getAccountingLineViewFieldClass().newInstance();
193 }
194 catch (InstantiationException ie) {
195 throw new RuntimeException("Could not instantiate instance of class "+getAccountingLineViewFieldClass().getName(), ie);
196 }
197 catch (IllegalAccessException iae) {
198 throw new RuntimeException("IllegalAccessException while attempting to instantiate "+getAccountingLineViewFieldClass().getName(), iae);
199 }
200 return layoutElement;
201 }
202
203
204
205
206
207
208 public Field getKNSFieldForDefinition(Class<? extends AccountingLine> accountingLineClass) {
209 Field realField = FieldUtils.getPropertyField(accountingLineClass, getName(), false);
210 FieldBridge.setupField(realField, this, null);
211 if (isHidden()) {
212 realField.setFieldType(Field.HIDDEN);
213 }
214 if (shouldUseShortLabel()) {
215 org.kuali.rice.krad.datadictionary.BusinessObjectEntry boEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getBusinessObjectEntry(accountingLineClass.getName());
216 realField.setFieldLabel(boEntry.getAttributeDefinition(getName()).getShortLabel());
217 }
218 return realField;
219 }
220
221
222
223
224
225
226
227 protected List<AccountingLineViewOverrideField> getFieldsForOverrideFields(AccountingLineViewField parentField, Class<? extends AccountingLine> accountingLineClass) {
228 List<AccountingLineViewOverrideField> fields = new ArrayList<AccountingLineViewOverrideField>();
229 if (getOverrideFields() != null && getOverrideFields().size() > 0) {
230 for (AccountingLineViewOverrideFieldDefinition overrideFieldDefinition : getOverrideFields()) {
231 fields.add(overrideFieldDefinition.getOverrideFieldForDefinition(parentField, accountingLineClass));
232 }
233 }
234 return fields;
235 }
236
237
238
239
240
241 public String getOverrideLookupParameters() {
242 return overrideLookupParameters;
243 }
244
245
246
247
248
249 public void setOverrideLookupParameters(String overrideLookupParameters) {
250 this.overrideLookupParameters = overrideLookupParameters;
251 }
252 }