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);
}
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();
}
};
}
Aggregations