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.krad.uif.UifConstants; |
21 | |
import org.kuali.rice.krad.uif.container.CollectionGroup; |
22 | |
import org.kuali.rice.krad.uif.container.View; |
23 | |
import org.kuali.rice.krad.uif.core.Component; |
24 | |
import org.kuali.rice.krad.uif.field.AttributeField; |
25 | |
import org.kuali.rice.krad.uif.field.GroupField; |
26 | |
import org.kuali.rice.krad.uif.layout.LayoutManager; |
27 | |
import org.kuali.rice.krad.uif.layout.TableLayoutManager; |
28 | |
import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; |
29 | |
|
30 | |
import java.util.Date; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class TableTools extends WidgetBase { |
43 | |
private static final long serialVersionUID = 4671589690877390070L; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
private String emptyTableMessage; |
49 | |
private boolean disableTableSort; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | private boolean showSearchAndExportOptions = true; |
55 | |
|
56 | |
public TableTools() { |
57 | 0 | super(); |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
@Override |
68 | |
public void performFinalize(View view, Object model, Component component) { |
69 | 0 | super.performFinalize(view, model, component); |
70 | |
|
71 | 0 | if (isRender()) { |
72 | 0 | if (StringUtils.isNotBlank(getEmptyTableMessage())) { |
73 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.LANGUAGE, |
74 | |
"{\"" + UifConstants.TableToolsKeys.EMPTY_TABLE + "\" : \"" + getEmptyTableMessage() + "\"}"); |
75 | |
} |
76 | |
|
77 | 0 | if (isDisableTableSort()) { |
78 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.TABLE_SORT, "false"); |
79 | |
} |
80 | |
|
81 | 0 | if (!isShowSearchAndExportOptions()) { |
82 | 0 | String sDomOption = getComponentOptions().get(UifConstants.TableToolsKeys.SDOM); |
83 | 0 | sDomOption = StringUtils.remove(sDomOption, "T"); |
84 | 0 | sDomOption = StringUtils.remove(sDomOption, "f"); |
85 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.SDOM, sDomOption); |
86 | |
} |
87 | |
|
88 | 0 | if (component instanceof CollectionGroup) { |
89 | 0 | buildTableSortOptions((CollectionGroup) component); |
90 | |
} |
91 | |
} |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
protected void buildTableSortOptions(CollectionGroup collectionGroup) { |
100 | |
|
101 | 0 | LayoutManager layoutManager = collectionGroup.getLayoutManager(); |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 0 | if (!collectionGroup.getSubCollections().isEmpty()) { |
107 | 0 | setDisableTableSort(true); |
108 | |
} |
109 | |
|
110 | 0 | if (!isDisableTableSort()) { |
111 | |
|
112 | |
|
113 | |
|
114 | 0 | if (collectionGroup.isRenderAddLine() && !collectionGroup.isReadOnly()) { |
115 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS, |
116 | |
"[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]"); |
117 | |
} |
118 | |
|
119 | 0 | if (!collectionGroup.isReadOnly()) { |
120 | |
|
121 | 0 | StringBuffer tableToolsColumnOptions = new StringBuffer("["); |
122 | |
|
123 | 0 | if (layoutManager instanceof TableLayoutManager && |
124 | |
((TableLayoutManager) layoutManager).isRenderSequenceField()) { |
125 | 0 | tableToolsColumnOptions.append(" null ,"); |
126 | |
} |
127 | |
|
128 | 0 | for (Component component : collectionGroup.getItems()) { |
129 | |
|
130 | |
|
131 | |
|
132 | 0 | if (component instanceof GroupField) { |
133 | 0 | component = ((GroupField) component).getItems().get(0); |
134 | |
} |
135 | 0 | Class dataTypeClass = ObjectPropertyUtils |
136 | |
.getPropertyType(collectionGroup.getCollectionObjectClass(), |
137 | |
((AttributeField) component).getPropertyName()); |
138 | 0 | String colOptions = constructTableColumnOptions(true, dataTypeClass); |
139 | 0 | tableToolsColumnOptions.append(colOptions + " , "); |
140 | 0 | } |
141 | |
|
142 | 0 | if (collectionGroup.isRenderLineActions()) { |
143 | 0 | String colOptions = constructTableColumnOptions(false, null); |
144 | 0 | tableToolsColumnOptions.append(colOptions); |
145 | 0 | } else { |
146 | 0 | tableToolsColumnOptions = |
147 | |
new StringBuffer(StringUtils.removeEnd(tableToolsColumnOptions.toString(), ", ")); |
148 | |
} |
149 | |
|
150 | 0 | tableToolsColumnOptions.append("]"); |
151 | |
|
152 | 0 | getComponentOptions().put(UifConstants.TableToolsKeys.AO_COLUMNS, tableToolsColumnOptions.toString()); |
153 | |
} |
154 | |
} |
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
protected String constructTableColumnOptions(boolean isSortable, Class dataTypeClass) { |
161 | |
|
162 | 0 | String colOptions = "null"; |
163 | |
|
164 | 0 | if (!isSortable || dataTypeClass == null) { |
165 | 0 | colOptions = "{ \"" + UifConstants.TableToolsKeys.SORTABLE + "\" : false } "; |
166 | |
} else { |
167 | 0 | if (ClassUtils.isAssignable(dataTypeClass, String.class)) { |
168 | 0 | colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + |
169 | |
UifConstants.TableToolsValues.DOM_TEXT + "\" } "; |
170 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, Date.class)) { |
171 | 0 | colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + |
172 | |
UifConstants.TableToolsValues.DOM_TEXT + "\" , \"" + UifConstants.TableToolsKeys.SORT_TYPE + |
173 | |
"\" : \"" + UifConstants.TableToolsValues.DATE + "\" } "; |
174 | 0 | } else if (ClassUtils.isAssignable(dataTypeClass, Number.class)) { |
175 | 0 | colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + |
176 | |
UifConstants.TableToolsValues.DOM_TEXT + "\" , \"" + UifConstants.TableToolsKeys.SORT_TYPE + |
177 | |
"\" : \"" + UifConstants.TableToolsValues.NUMERIC + "\" } "; |
178 | |
} |
179 | |
} |
180 | |
|
181 | 0 | return colOptions; |
182 | |
} |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public String getEmptyTableMessage() { |
190 | 0 | return emptyTableMessage; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
public void setEmptyTableMessage(String emptyTableMessage) { |
199 | 0 | this.emptyTableMessage = emptyTableMessage; |
200 | 0 | } |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public boolean isDisableTableSort() { |
208 | 0 | return this.disableTableSort; |
209 | |
} |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
public void setDisableTableSort(boolean disableTableSort) { |
217 | 0 | this.disableTableSort = disableTableSort; |
218 | 0 | } |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public boolean isShowSearchAndExportOptions() { |
226 | 0 | return this.showSearchAndExportOptions; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
public void setShowSearchAndExportOptions(boolean showSearchAndExportOptions) { |
235 | 0 | this.showSearchAndExportOptions = showSearchAndExportOptions; |
236 | 0 | } |
237 | |
} |