List of usage examples for javax.swing RowSorter.SortKey RowSorter.SortKey
public SortKey(int column, SortOrder sortOrder)
SortKey
for the specified column with the specified sort order. From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
protected void applyColumnSettings(Element element, boolean sortable) { final Element columnsElem = element.element("columns"); // do not allow duplicates Collection<Table.Column> sequence = new LinkedHashSet<>(); for (Element colElem : Dom4j.elements(columnsElem, "column")) { String id = colElem.attributeValue("id"); Table.Column column = getColumn(id); if (column != null) { sequence.add(column);//from w ww .ja va 2 s . c o m TableColumnExt tableColumn = table.getColumnExt(column); if (tableColumn != null) { String width = colElem.attributeValue("width"); if (StringUtils.isNotEmpty(width)) { tableColumn.setPreferredWidth(Integer.parseInt(width)); } String visible = colElem.attributeValue("visible"); if (StringUtils.isNotEmpty(visible)) { tableColumn.setVisible(Boolean.valueOf(visible)); } } } } table.setColumnSequence(sequence.toArray(new Object[sequence.size()])); if (sortable && table.getRowSorter() != null) { String sortColumn = columnsElem.attributeValue("sortColumn"); if (sortColumn != null) { SortOrder sortOrder = SortOrder.valueOf(columnsElem.attributeValue("sortOrder")); int sortColumnIndex = -1; if (!StringUtils.isNumeric(sortColumn)) { Table.Column column = getColumn(sortColumn); if (column != null) { sortColumnIndex = columns.indexOf(column); } } else { // backward compatibility sortColumnIndex = Integer.parseInt(sortColumn); } if (sortColumnIndex >= 0) { table.getRowSorter().setSortKeys( Collections.singletonList(new RowSorter.SortKey(sortColumnIndex, sortOrder))); } } else { table.getRowSorter().setSortKeys(null); } } table.revalidate(); table.repaint(); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
@Override public void sortBy(Object propertyId, boolean ascending) { if (isSortable()) { for (int i = 0; i < columnsOrder.size(); i++) { Column column = columnsOrder.get(i); if (column.getId().equals(propertyId)) { SortOrder sortOrder = ascending ? SortOrder.ASCENDING : SortOrder.DESCENDING; tableModel.sort(singletonList(new RowSorter.SortKey(i, sortOrder))); onDataChange();/* w w w . j a v a 2 s.c o m*/ packRows(); break; } } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
@Override public void sort(String columnId, SortDirection direction) { Column column = getColumn(columnId); if (column == null) { throw new IllegalArgumentException("Unable to find column " + columnId); }/*from w w w . j av a 2s .c o m*/ if (isSortable()) { SortOrder sortOrder = direction == SortDirection.ASCENDING ? SortOrder.ASCENDING : SortOrder.DESCENDING; int columnIndex = columnsOrder.indexOf(column); tableModel.sort(singletonList(new RowSorter.SortKey(columnIndex, sortOrder))); onDataChange(); packRows(); } }