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