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