1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web.renderers;
17
18 import java.io.IOException;
19 import java.util.List;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.JspWriter;
23 import javax.servlet.jsp.PageContext;
24 import javax.servlet.jsp.tagext.Tag;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.document.web.AccountingLineViewAction;
29 import org.kuali.rice.kns.web.taglib.html.KNSImageTag;
30
31
32
33
34 public class ActionsRenderer implements Renderer {
35 private List<AccountingLineViewAction> actions;
36 private KNSImageTag actionButton = new KNSImageTag();
37 private int tabIndex;
38 private String postButtonSpacing;
39 private String tagBeginning;
40 private String tagEnding;
41
42
43
44
45 public ActionsRenderer() {
46 actionButton.setStyleClass("tinybutton");
47 }
48
49
50
51
52
53 public void clear() {
54 actions = null;
55
56 resetButton();
57 actionButton.setPageContext(null);
58 actionButton.setParent(null);
59 }
60
61
62
63
64 protected void resetButton() {
65 actionButton.setProperty(null);
66 actionButton.setSrc(null);
67 actionButton.setTitle(null);
68 actionButton.setAlt(null);
69 actionButton.setTabindex(null);
70 }
71
72
73
74
75
76 public void render(PageContext pageContext, Tag parentTag) throws JspException {
77 actionButton.setPageContext(pageContext);
78 actionButton.setParent(parentTag);
79 JspWriter out = pageContext.getOut();
80
81 try {
82 if (actions != null && actions.size() > 0) {
83 out.write(this.getTagBeginning());
84 for (AccountingLineViewAction action : actions) {
85 renderAction(action);
86 out.write(this.getPostButtonSpacing());
87 }
88 out.write(this.getTagEnding());
89 }
90 else {
91 out.write(buildNonBreakingSpace());
92 }
93 }
94 catch (IOException ioe) {
95 throw new JspException("Difficulty rendering actions block", ioe);
96 }
97 }
98
99
100
101
102
103
104 protected void renderAction(AccountingLineViewAction action) throws JspException {
105 actionButton.setProperty(OLEConstants.DISPATCH_REQUEST_PARAMETER+"."+action.getActionMethod());
106 actionButton.setSrc(action.getImageName());
107 actionButton.setTitle(action.getActionLabel());
108 actionButton.setAlt(action.getActionLabel());
109 if (!StringUtils.isBlank(getTabIndex())) {
110 actionButton.setTabindex(getTabIndex());
111 }
112 actionButton.doStartTag();
113 actionButton.doEndTag();
114 resetButton();
115 }
116
117
118
119
120
121 protected String buildCenteringDivBeginning() {
122 return "<div style=\"text-align: center;\">";
123 }
124
125
126
127
128
129 protected String buildCenteringDivEnding() {
130 return "</div>";
131 }
132
133
134
135
136
137 public String getPostButtonSpacing() {
138 return postButtonSpacing == null ? "<br />" : postButtonSpacing;
139 }
140
141
142
143
144
145 public void setPostButtonSpacing(String postButtonSpacing) {
146 this.postButtonSpacing = postButtonSpacing;
147 }
148
149
150
151
152
153 public List<AccountingLineViewAction> getActions() {
154 return actions;
155 }
156
157
158
159
160
161 public void setActions(List<AccountingLineViewAction> actions) {
162 this.actions = actions;
163 }
164
165
166
167
168
169 public void setTabIndex(int tabIndex) {
170 this.tabIndex = tabIndex;
171 }
172
173
174
175
176
177 protected String getTabIndex() {
178 if (tabIndex > -1) return Integer.toString(tabIndex);
179 return null;
180 }
181
182
183
184
185 protected String buildNonBreakingSpace() {
186 return " ";
187 }
188
189
190
191
192
193 public String getTagBeginning() {
194 return tagBeginning == null ? this.buildCenteringDivBeginning() : tagBeginning;
195 }
196
197
198
199
200
201 public void setTagBeginning(String tagBeginning) {
202 this.tagBeginning = tagBeginning;
203 }
204
205
206
207
208
209 public String getTagEnding() {
210 return tagEnding == null ? this.buildCenteringDivEnding() : tagEnding;
211 }
212
213
214
215
216
217 public void setTagEnding(String tagEnding) {
218 this.tagEnding = tagEnding;
219 }
220 }