use of javax.swing.RowSorter.SortKey in project JMRI by JMRI.
the class JmriJTablePersistenceManager method initialize.
@Override
public void initialize(Profile profile) throws InitializationException {
try {
Element element = JDOMUtil.toJDOMElement(ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).getConfigurationFragment(TABLES_ELEMENT, TABLES_NAMESPACE, false));
element.getChildren("table").stream().forEach((table) -> {
String tableName = table.getAttributeValue("name");
int sortColumn = -1;
SortOrder sortOrder = SortOrder.UNSORTED;
Element sortElement = table.getChild(SORT_ORDER);
if (sortElement != null) {
List<SortKey> keys = new ArrayList<>();
for (Element sortKey : sortElement.getChildren()) {
sortOrder = SortOrder.valueOf(sortKey.getAttributeValue(SORT_ORDER));
try {
sortColumn = sortKey.getAttribute("column").getIntValue();
SortKey key = new SortKey(sortColumn, sortOrder);
keys.add(key);
} catch (DataConversionException ex) {
log.error("Unable to get sort column as integer");
}
}
this.sortKeys.put(tableName, keys);
}
log.debug("Table {} column {} is sorted {}", tableName, sortColumn, sortOrder);
for (Element column : table.getChild("columns").getChildren()) {
String columnName = column.getAttribute("name").getValue();
int order = -1;
int width = -1;
boolean hidden = false;
try {
if (column.getAttributeValue("order") != null) {
order = column.getAttribute("order").getIntValue();
}
if (column.getAttributeValue("width") != null) {
width = column.getAttribute("width").getIntValue();
}
if (column.getAttribute("hidden") != null) {
hidden = column.getAttribute("hidden").getBooleanValue();
}
} catch (DataConversionException ex) {
log.error("Unable to parse column \"{}\"", columnName);
continue;
}
if (sortColumn == order) {
this.setPersistedState(tableName, columnName, order, width, sortOrder, hidden);
} else {
this.setPersistedState(tableName, columnName, order, width, SortOrder.UNSORTED, hidden);
}
}
});
} catch (NullPointerException ex) {
log.info("Table preferences not found.\nThis is expected on the first time the \"{}\" profile is used on this computer.", ProfileManager.getDefault().getActiveProfile().getName());
}
this.setInitialized(profile, true);
}
use of javax.swing.RowSorter.SortKey in project JMRI by JMRI.
the class RowSorterUtil method setSortOrder.
/**
* Set the sort order for a table using the specified column given a
* RowSorter for the TableModel containing the column.
* <p>
* This makes all other columns unsorted, even if the specified column is
* also specified to be unsorted.
*
* @param rowSorter the sorter
* @param column the column index in the model, not the view
* @param sortOrder the sort order
*/
public static void setSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column, @Nonnull SortOrder sortOrder) {
List<SortKey> keys = new ArrayList<>();
if (!sortOrder.equals(SortOrder.UNSORTED)) {
keys.add(new RowSorter.SortKey(column, sortOrder));
}
rowSorter.setSortKeys(keys);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method fixLastRowWithAscendingValue.
@Test
public void fixLastRowWithAscendingValue() {
sorter.fixLastRow().setSortKey(new SortKey(1, SortOrder.ASCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(b2(), a3(), d4(), c1());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method sortKeyAscending.
@Test
public void sortKeyAscending() {
sorter.setSortKey(new SortKey(0, SortOrder.ASCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(a3(), b2(), c1(), d4());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method fixLastRowWithDescendingKey.
@Test
public void fixLastRowWithDescendingKey() {
sorter.fixLastRow().setSortKey(new SortKey(0, SortOrder.DESCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(d4(), b2(), a3(), c1());
assertRowOrderAndIndexes(expected);
}
Aggregations