1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.uif.widget; |
17 | |
|
18 | |
import org.apache.commons.lang.ClassUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.util.type.KualiDecimal; |
21 | |
import org.kuali.rice.core.api.util.type.KualiInteger; |
22 | |
import org.kuali.rice.core.api.util.type.KualiPercent; |
23 | |
import org.kuali.rice.krad.uif.UifConstants; |
24 | |
import org.kuali.rice.krad.uif.container.CollectionGroup; |
25 | |
import org.kuali.rice.krad.uif.control.Control; |
26 | |
import org.kuali.rice.krad.uif.field.DataField; |
27 | |
import org.kuali.rice.krad.uif.field.InputField; |
28 | |
import org.kuali.rice.krad.uif.view.View; |
29 | |
import org.kuali.rice.krad.uif.control.CheckboxControl; |
30 | |
import org.kuali.rice.krad.uif.control.CheckboxGroupControl; |
31 | |
import org.kuali.rice.krad.uif.control.RadioGroupControl; |
32 | |
import org.kuali.rice.krad.uif.control.SelectControl; |
33 | |
import org.kuali.rice.krad.uif.control.TextControl; |
34 | |
import org.kuali.rice.krad.uif.component.Component; |
35 | |
import org.kuali.rice.krad.uif.field.FieldGroup; |
36 | |
import org.kuali.rice.krad.uif.layout.LayoutManager; |
37 | |
import org.kuali.rice.krad.uif.layout.TableLayoutManager; |
38 | |
import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; |
39 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
40 | |
|
41 | |
import java.sql.Timestamp; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public class RichTable extends WidgetBase { |
54 | |
private static final long serialVersionUID = 4671589690877390070L; |
55 | |
|
56 | |
private String emptyTableMessage; |
57 | |
private boolean disableTableSort; |
58 | |
|
59 | 0 | private boolean showSearchAndExportOptions = true; |
60 | |
|
61 | |
public RichTable() { |
62 | 0 | super(); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
@Override |
73 | |
public void performFinalize(View view, Object model, Component component) { |
74 | 0 | super.performFinalize(view, model, component); |
75 | |
|
76 | 0 | UifFormBase formBase = (UifFormBase) model; |
77 | |
|
78 | 0 | if (isRender()) { |
79 | 0 | if (StringUtils.isNotBlank(getEmptyTableMessage())) { |
80 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.LANGUAGE, |
81 | |
"{\"" + UifConstants.TableToolsKeys.EMPTY_TABLE + "\" : \"" + getEmptyTableMessage() + "\"}"); |
82 | |
} |
83 | |
|
84 | 0 | if (!isShowSearchAndExportOptions()) { |
85 | 0 | Object domOption = getComponentOptions().get(UifConstants.TableToolsKeys.SDOM); |
86 | 0 | if (domOption instanceof String) { |
87 | 0 | String sDomOption = (String) domOption; |
88 | 0 | if (StringUtils.isNotBlank(sDomOption)) { |
89 | 0 | sDomOption = StringUtils.remove(sDomOption, "T"); |
90 | 0 | sDomOption = StringUtils.remove(sDomOption, "f"); |
91 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.SDOM, sDomOption); |
92 | |
} |
93 | |
} |
94 | |
|
95 | |
} |
96 | |
|
97 | |
|
98 | 0 | if (UifConstants.ActionEvents.ADD_LINE.equals(formBase.getActionEvent())) { |
99 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.AASORTING, "[]"); |
100 | |
} |
101 | |
|
102 | 0 | if (component instanceof CollectionGroup) { |
103 | 0 | buildTableSortOptions((CollectionGroup) component); |
104 | |
} |
105 | |
|
106 | 0 | if (isDisableTableSort()) { |
107 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.TABLE_SORT, "false"); |
108 | |
} |
109 | |
} |
110 | 0 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
protected void buildTableSortOptions(CollectionGroup collectionGroup) { |
118 | 0 | LayoutManager layoutManager = collectionGroup.getLayoutManager(); |
119 | |
|
120 | |
|
121 | 0 | if (!collectionGroup.getSubCollections().isEmpty()) { |
122 | 0 | setDisableTableSort(true); |
123 | |
} |
124 | |
|
125 | 0 | if (!isDisableTableSort()) { |
126 | |
|
127 | 0 | if (collectionGroup.isRenderAddLine() |
128 | |
&& !collectionGroup.isReadOnly() |
129 | |
&& !((layoutManager instanceof TableLayoutManager) && ((TableLayoutManager) layoutManager) |
130 | |
.isSeparateAddLine())) { |
131 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS, |
132 | |
"[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]"); |
133 | |
} |
134 | |
|
135 | 0 | StringBuffer tableToolsColumnOptions = new StringBuffer("["); |
136 | |
|
137 | 0 | if (layoutManager instanceof TableLayoutManager && ((TableLayoutManager) layoutManager) |
138 | |
.isRenderSequenceField()) { |
139 | 0 | tableToolsColumnOptions.append(" null ,"); |
140 | |
} |
141 | |
|
142 | |
|
143 | 0 | if (collectionGroup.isRenderSelectField()) { |
144 | 0 | String colOptions = constructTableColumnOptions(false, null, null); |
145 | 0 | tableToolsColumnOptions.append(colOptions + " , "); |
146 | |
} |
147 | |
|
148 | |
|
149 | 0 | for (Component component : collectionGroup.getItems()) { |
150 | |
|
151 | 0 | if (component instanceof FieldGroup) { |
152 | 0 | component = ((FieldGroup) component).getItems().get(0); |
153 | |
} |
154 | |
|
155 | 0 | if (component instanceof DataField) { |
156 | 0 | DataField field = (DataField) component; |
157 | |
|
158 | 0 | String sortType = null; |
159 | 0 | if (!collectionGroup.isReadOnly() && (field instanceof InputField) |
160 | |
&& ((InputField) field).getControl() != null) { |
161 | 0 | Control control = ((InputField) field).getControl(); |
162 | 0 | if (control instanceof SelectControl) { |
163 | 0 | sortType = UifConstants.TableToolsValues.DOM_SELECT; |
164 | 0 | } else if (control instanceof CheckboxControl || control instanceof CheckboxGroupControl) { |
165 | 0 | sortType = UifConstants.TableToolsValues.DOM_CHECK; |
166 | 0 | } else if (control instanceof RadioGroupControl) { |
167 | 0 | sortType = UifConstants.TableToolsValues.DOM_RADIO; |
168 | |
} else { |
169 | 0 | sortType = UifConstants.TableToolsValues.DOM_TEXT; |
170 | |
} |
171 | 0 | } else { |
172 | 0 | sortType = UifConstants.TableToolsValues.DOM_TEXT; |
173 | |
} |
174 | |
|
175 | 0 | Class dataTypeClass = ObjectPropertyUtils.getPropertyType( |
176 | |
collectionGroup.getCollectionObjectClass(), field.getPropertyName()); |
177 | 0 | String colOptions = constructTableColumnOptions(true, dataTypeClass, sortType); |
178 | 0 | tableToolsColumnOptions.append(colOptions + " , "); |
179 | 0 | } else { |
180 | 0 | String colOptions = constructTableColumnOptions(false, null, null); |
181 | 0 | tableToolsColumnOptions.append(colOptions + " , "); |
182 | 0 | } |
183 | |
} |
184 | |
|
185 | 0 | if (collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly()) { |
186 | 0 | String colOptions = constructTableColumnOptions(false, null, null); |
187 | 0 | tableToolsColumnOptions.append(colOptions); |
188 | 0 | } else { |
189 | 0 | tableToolsColumnOptions = new StringBuffer(StringUtils.removeEnd(tableToolsColumnOptions.toString(), |
190 | |
", ")); |
191 | |
} |
192 | |
|
193 | 0 | tableToolsColumnOptions.append("]"); |
194 | |
|
195 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.AO_COLUMNS, tableToolsColumnOptions.toString()); |
196 | |
} |
197 | 0 | } |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
protected String constructTableColumnOptions(boolean isSortable, Class dataTypeClass, String sortDataType) { |
203 | 0 | String colOptions = "null"; |
204 | |
|
205 | 0 | String sortType = ""; |
206 | 0 | if (!isSortable || dataTypeClass == null || sortType == null) { |
207 | 0 | colOptions = "\"" + UifConstants.TableToolsKeys.SORTABLE + "\" : false, \"sType\" : \"string\""; |
208 | |
} else { |
209 | 0 | if (ClassUtils.isAssignable(dataTypeClass, KualiPercent.class)) { |
210 | 0 | sortType = UifConstants.TableToolsValues.PERCENT; |
211 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, KualiInteger.class) || ClassUtils.isAssignable( |
212 | |
dataTypeClass, KualiDecimal.class)) { |
213 | 0 | sortType = UifConstants.TableToolsValues.CURRENCY; |
214 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, Timestamp.class)) { |
215 | 0 | sortType = "date"; |
216 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, java.sql.Date.class) || ClassUtils.isAssignable( |
217 | |
dataTypeClass, java.util.Date.class)) { |
218 | 0 | sortType = UifConstants.TableToolsValues.DATE; |
219 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, Number.class)) { |
220 | 0 | sortType = UifConstants.TableToolsValues.NUMERIC; |
221 | |
} |
222 | |
else { |
223 | 0 | sortType = UifConstants.TableToolsValues.STRING; |
224 | |
} |
225 | |
|
226 | 0 | colOptions = "\"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortDataType + "\""; |
227 | 0 | colOptions += " , \"" + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + sortType + "\""; |
228 | |
} |
229 | |
|
230 | 0 | colOptions = "{" + colOptions + "}"; |
231 | |
|
232 | 0 | return colOptions; |
233 | |
} |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
public String getEmptyTableMessage() { |
241 | 0 | return emptyTableMessage; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
public void setEmptyTableMessage(String emptyTableMessage) { |
250 | 0 | this.emptyTableMessage = emptyTableMessage; |
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
public boolean isDisableTableSort() { |
259 | 0 | return this.disableTableSort; |
260 | |
} |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public void setDisableTableSort(boolean disableTableSort) { |
268 | 0 | this.disableTableSort = disableTableSort; |
269 | 0 | } |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
public boolean isShowSearchAndExportOptions() { |
277 | 0 | return this.showSearchAndExportOptions; |
278 | |
} |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
public void setShowSearchAndExportOptions(boolean showSearchAndExportOptions) { |
286 | 0 | this.showSearchAndExportOptions = showSearchAndExportOptions; |
287 | 0 | } |
288 | |
} |