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
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.PageContext;
22 import javax.servlet.jsp.tagext.Tag;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewHideShowLinesDefinition;
26 import org.kuali.ole.sys.document.web.renderers.HideShowBlockRenderer;
27 import org.kuali.rice.kns.util.WebUtils;
28 import org.kuali.rice.kns.web.ui.Field;
29
30
31
32
33 public class HideShowBlock implements RenderableElement {
34 private List<AccountingLineTableRow> contentRows;
35 private AccountingLineViewHideShowLinesDefinition definition;
36 private AccountingLineRenderingContext renderingContext;
37 private String tabKey;
38
39
40
41
42
43
44
45 public void appendFields(List<Field> fields) {
46 for (AccountingLineTableRow row : contentRows) {
47 row.appendFields(fields);
48 }
49 }
50
51
52
53
54
55 public boolean isActionBlock() {
56 return false;
57 }
58
59
60
61
62
63 public boolean isEmpty() {
64 for (AccountingLineTableRow row : contentRows) {
65 if (!row.isEmpty()) return false;
66 }
67 return true;
68 }
69
70
71
72
73
74 public boolean isHidden() {
75 for (AccountingLineTableRow row : contentRows) {
76 if (!row.isHidden()) return false;
77 }
78 return true;
79 }
80
81
82
83
84
85 public void populateWithTabIndexIfRequested(int reallyHighIndex) {
86 for (AccountingLineTableRow row : contentRows) {
87 row.populateWithTabIndexIfRequested(reallyHighIndex);
88 }
89 }
90
91
92
93
94
95 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
96 this.renderingContext = renderingContext;
97
98 HideShowBlockRenderer renderer = new HideShowBlockRenderer();
99 renderer.setHideShowBlock(this);
100 renderer.render(pageContext, parentTag);
101
102 this.renderingContext = null;
103 }
104
105
106
107
108
109
110
111 public void renderChildRows(PageContext pageContext, Tag parentTag) throws JspException {
112 for (AccountingLineTableRow row : contentRows) {
113 row.renderElement(pageContext, parentTag, renderingContext);
114 }
115 }
116
117
118
119
120
121 public List<AccountingLineTableRow> getContentRows() {
122 return contentRows;
123 }
124
125
126
127
128
129 public void setContentRows(List<AccountingLineTableRow> contentRows) {
130 this.contentRows = contentRows;
131 }
132
133
134
135
136
137 public void setDefinition(AccountingLineViewHideShowLinesDefinition definition) {
138 this.definition = definition;
139 }
140
141
142
143
144 public String getTabKey() {
145 if (tabKey == null) {
146 tabKey = WebUtils.generateTabKey(renderingContext.getGroupLabel()+definition.getLabel()) + "-" + renderingContext.getAccountingLinePropertyPath().replaceAll("\\.","-").replaceAll("\\[", "(").replaceAll("\\]", ")");
147 }
148 return tabKey;
149 }
150
151
152
153
154 public String getTabState() {
155 String tabState = renderingContext.getTabState(getTabKey());
156 return StringUtils.isNotBlank(tabState) ? tabState : "CLOSE";
157 }
158
159
160
161
162
163 public boolean isShowing() {
164 return getTabState().equals("OPEN");
165 }
166
167
168
169
170 public String getLabel() {
171 return definition.getLabel();
172 }
173
174
175
176
177 public String getFullLabel() {
178 return renderingContext.getGroupLabel()+(!StringUtils.isBlank(definition.getLabel()) ? " "+definition.getLabel() : " Hide/Show Block");
179 }
180 }