1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24
25 import org.kuali.ole.sys.businessobject.AccountingLine;
26 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewOverrideFieldDefinition;
27 import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
28 import org.kuali.ole.sys.document.web.renderers.OverrideFieldRenderer;
29 import org.kuali.rice.kns.util.FieldUtils;
30 import org.kuali.rice.kns.web.ui.Field;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33
34
35
36 public class AccountingLineViewOverrideField implements RenderableElement {
37 private AccountingLineViewField parent;
38 private AccountingLineViewOverrideFieldDefinition definition;
39 private Field overrideField;
40 private int arbitrarilyHighIndex;
41
42
43
44
45
46
47 public AccountingLineViewOverrideField(AccountingLineViewField field, AccountingLineViewOverrideFieldDefinition definition, Class<? extends AccountingLine> accountingLineClass) {
48 this.parent = field;
49 this.definition = definition;
50 overrideField = FieldUtils.getPropertyField(accountingLineClass, definition.getName(), false);
51 }
52
53
54
55
56
57
58
59 public void appendFields(List<Field> fields) {
60 fields.add(overrideField);
61 }
62
63
64
65
66
67 public boolean isActionBlock() {
68 return false;
69 }
70
71
72
73
74
75 public boolean isEmpty() {
76 return parent.isEmpty();
77 }
78
79
80
81
82
83 public boolean isHidden() {
84 return parent.isHidden();
85 }
86
87
88
89
90
91 public void populateWithTabIndexIfRequested(int reallyHighIndex) {
92 arbitrarilyHighIndex = reallyHighIndex;
93 }
94
95
96
97
98
99 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
100 OverrideFieldRenderer renderer = new OverrideFieldRenderer();
101 renderer.setField(overrideField);
102 renderer.setArbitrarilyHighTabIndex(arbitrarilyHighIndex);
103 if (parent.isReadOnly() && definition.isAllowEditDespiteReadOnlyParentWhenAccoutingLineEditable() && renderingContext.isEditableLine()) {
104 renderer.setReadOnly(false);
105 } else {
106 renderer.setReadOnly(parent.isReadOnly());
107 }
108 renderer.setOverrideNeededValue(getOverrideNeededValue(renderingContext.getAccountingLine()));
109 renderer.setAccountingLine(renderingContext.getAccountingLine());
110 renderer.render(pageContext, parentTag);
111 renderer.clear();
112 }
113
114
115
116
117
118
119 protected String getOverrideNeededValue(AccountingLine accountingLine) {
120 String overrideNeededPropertyName = overrideField.getPropertyName()+"Needed";
121 Boolean value = (Boolean)ObjectUtils.getPropertyValue(accountingLine, overrideNeededPropertyName);
122 return value != null && value.booleanValue() ? "Yes" : "No";
123 }
124
125
126
127
128
129
130
131 public void transformField(AccountingLineFieldRenderingTransformation fieldTransformation, AccountingLine accountingLine, Map unconvertedValues) {
132 fieldTransformation.transformField(accountingLine, overrideField, definition, unconvertedValues);
133 }
134
135
136
137
138
139 public void setAccountingLineProperty(String propertyPrefix) {
140 overrideField.setPropertyPrefix(propertyPrefix);
141 }
142 }