Search in sources :

Example 1 with SortType

use of javafx.scene.control.TableColumn.SortType in project ParadoxosModManager by ThibautSF.

the class ListManager method updateList.

/**
 * @throws Exception
 */
private void updateList() throws Exception {
    userlistsXML.readFile(fileXML);
    userListArray = userlistsXML.getSavedList(availableMods);
    ObservableList<TableColumn<ModList, ?>> sortOrder = lists.getSortOrder();
    List<TableColumn<ModList, ?>> sortColumns = new ArrayList<TableColumn<ModList, ?>>();
    List<SortType> sortTypes = new ArrayList<SortType>();
    for (TableColumn<ModList, ?> tableColumn : sortOrder) {
        sortColumns.add(tableColumn);
        sortTypes.add(tableColumn.getSortType());
    }
    listOfLists.clear();
    listOfLists.addAll(userListArray);
    lists.setItems(listOfLists);
    lists.refresh();
    for (int i = 0; i < sortColumns.size(); i++) {
        lists.getSortOrder().add(sortColumns.get(i));
        sortColumns.get(i).setSortType(sortTypes.get(i));
    }
    lists.sort();
    // Loose selection after refresh
    modifyList.setDisable(true);
    delList.setDisable(true);
    applyList.setDisable(true);
    exportList.setDisable(true);
}
Also used : SortType(javafx.scene.control.TableColumn.SortType) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) ErrorPrint(debug.ErrorPrint) ModList(mod.ModList)

Example 2 with SortType

use of javafx.scene.control.TableColumn.SortType in project controlsfx by controlsfx.

the class JavaFXTableModels method wrap.

/**
 * Swing
 */
public static <S> JavaFXTableModel<S> wrap(final TableModel tableModel) {
    return new JavaFXTableModel<S>() {

        final TableRowSorter<TableModel> sorter;

        {
            sorter = new TableRowSorter<>(tableModel);
        }

        @SuppressWarnings("unchecked")
        @Override
        public S getValueAt(int rowIndex, int columnIndex) {
            return (S) tableModel.getValueAt(sorter.convertRowIndexToView(rowIndex), columnIndex);
        }

        @Override
        public void setValueAt(S value, int rowIndex, int columnIndex) {
            tableModel.setValueAt(value, rowIndex, columnIndex);
        }

        @Override
        public int getRowCount() {
            return tableModel.getRowCount();
        }

        @Override
        public int getColumnCount() {
            return tableModel.getColumnCount();
        }

        @Override
        public String getColumnName(int columnIndex) {
            return tableModel.getColumnName(columnIndex);
        }

        @Override
        public void sort(TableView<TableModelRow<S>> table) {
            List<SortKey> sortKeys = new ArrayList<>();
            for (TableColumn<TableModelRow<S>, ?> column : table.getSortOrder()) {
                final int columnIndex = table.getVisibleLeafIndex(column);
                final SortType sortType = column.getSortType();
                SortOrder sortOrder = sortType == SortType.ASCENDING ? SortOrder.ASCENDING : sortType == SortType.DESCENDING ? SortOrder.DESCENDING : SortOrder.UNSORTED;
                SortKey sortKey = new SortKey(columnIndex, sortOrder);
                sortKeys.add(sortKey);
                sorter.setComparator(columnIndex, column.getComparator());
            }
            sorter.setSortKeys(sortKeys);
            sorter.sort();
        }
    };
}
Also used : ArrayList(java.util.ArrayList) SortOrder(javax.swing.SortOrder) SortKey(javax.swing.RowSorter.SortKey) SortType(javafx.scene.control.TableColumn.SortType) TableRowSorter(javax.swing.table.TableRowSorter) TableView(javafx.scene.control.TableView)

Aggregations

ArrayList (java.util.ArrayList)2 SortType (javafx.scene.control.TableColumn.SortType)2 ErrorPrint (debug.ErrorPrint)1 TableColumn (javafx.scene.control.TableColumn)1 TableView (javafx.scene.control.TableView)1 SortKey (javax.swing.RowSorter.SortKey)1 SortOrder (javax.swing.SortOrder)1 TableRowSorter (javax.swing.table.TableRowSorter)1 ModList (mod.ModList)1