List of usage examples for com.vaadin.v7.shared.ui.table TableConstants COLUMN_REORDER_EVENT_ID
String COLUMN_REORDER_EVENT_ID
To view the source code for com.vaadin.v7.shared.ui.table TableConstants COLUMN_REORDER_EVENT_ID.
Click Source Link
From source file:com.haulmont.cuba.web.widgets.client.grouptable.CubaGroupTableWidget.java
License:Apache License
@Override protected void reOrderColumn(String columnKey, int newIndex) { // CAUTION This method copied from VScrollTable // Added grouping support int oldIndex = getColIndexByKey(columnKey); // Change header order tHead.moveCell(oldIndex, newIndex);// www .jav a2 s . c o m // Change body order scrollBody.moveCol(oldIndex, newIndex); // Change footer order tFoot.moveCell(oldIndex, newIndex); /* * Build new columnOrder and update it to server Note that columnOrder * also contains collapsed columns so we cannot directly build it from * cells vector Loop the old columnOrder and append in order to new * array unless on moved columnKey. On new index also put the moved key * i == index on columnOrder, j == index on newOrder */ // Grouping support final int groupDividerIndex = getColIndexByKey(GROUP_DIVIDER_COLUMN_KEY); if (isGroupColumn(columnKey)) { if (newIndex > 0 && newIndex >= groupDividerIndex) { removeGroupColumn(columnKey); newIndex--; } } else { if (newIndex <= groupDividerIndex) { addGroupColumn(columnKey); } if (newIndex > 0 && newIndex > groupDividerIndex) { newIndex--; } } String oldKeyOnNewIndex = visibleColOrder[newIndex]; if (showRowHeaders) { newIndex--; // columnOrder don't have rowHeader } if (!GROUP_DIVIDER_COLUMN_KEY.equals(oldKeyOnNewIndex)) { for (int i = 0; i < columnOrder.length; i++) { if (columnOrder[i].equals(oldKeyOnNewIndex)) { break; // break loop at target } if (isCollapsedColumn(columnOrder[i])) { newIndex++; } } } // finally we can build the new columnOrder for server String[] newOrder = new String[columnOrder.length]; for (int i = 0, j = 0; j < newOrder.length; i++) { if (j == newIndex) { newOrder[j] = columnKey; j++; } if (i == columnOrder.length) { break; } if (columnOrder[i].equals(columnKey)) { continue; } newOrder[j] = columnOrder[i]; j++; } columnOrder = newOrder; // also update visibleColumnOrder int colIndex = showRowHeaders ? 1 : 0; boolean dividerPainted = false; for (int j = 0; j < newOrder.length; j++) { final String cid = newOrder[j]; if (!isGroupColumn(cid) && !dividerPainted) { //paint group columns divider visibleColOrder[colIndex++] = GROUP_DIVIDER_COLUMN_KEY; dividerPainted = true; } if (!isCollapsedColumn(cid)) { visibleColOrder[colIndex++] = cid; } } // Grouping support if (groupColumns != null) { // collect new grouped columns final String[] groupedColumns = new String[groupColumns.size()]; for (int i = 0, j = 0; i < columnOrder.length; i++) { final String colKey = columnOrder[i]; if (isGroupColumn(colKey)) { groupedColumns[j++] = colKey; } if (j == groupedColumns.length) { break; } } client.updateVariable(paintableId, "groupedcolumns", groupedColumns, false); } // CAUTION we use immediate update of column order client.updateVariable(paintableId, "columnorder", columnOrder, true); if (client.hasEventListeners(this, TableConstants.COLUMN_REORDER_EVENT_ID)) { client.sendPendingVariableChanges(); } }