use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method sortValueDescending.
@Test
public void sortValueDescending() {
sorter.setSortKey(new SortKey(1, SortOrder.DESCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(d4(), a3(), b2(), c1());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method sortValueAscending.
@Test
public void sortValueAscending() {
sorter.setSortKey(new SortKey(1, SortOrder.ASCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(c1(), b2(), a3(), d4());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project JMRI by JMRI.
the class RowSorterUtil method addSingleSortableColumnListener.
/**
* Add a RowSorterListener to the rowSorter that prevents multiple columns
* from being considered while sorting.
*
* @param rowSorter the sorter to add the listener to
* @return the added listener
* @throws NullPointerException if rowSorter is null
*/
public static RowSorterListener addSingleSortableColumnListener(@Nonnull RowSorter<? extends TableModel> rowSorter) {
Objects.requireNonNull(rowSorter, "rowSorter must be nonnull.");
RowSorterListener listener = new RowSorterListener() {
List<? extends SortKey> priorSortKeys = new ArrayList<>();
@Override
public void sorterChanged(RowSorterEvent e) {
if (e.getType().equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) {
List<? extends SortKey> newSortKeys = new ArrayList<>(e.getSource().getSortKeys());
newSortKeys.removeAll(priorSortKeys);
if (!newSortKeys.isEmpty()) {
priorSortKeys = newSortKeys;
e.getSource().setSortKeys(priorSortKeys);
e.getSource().allRowsChanged();
}
}
}
};
rowSorter.addRowSorterListener(listener);
return listener;
}
use of javax.swing.RowSorter.SortKey in project JMRI by JMRI.
the class JmriJTablePersistenceManager method savePreferences.
@Override
public synchronized void savePreferences(Profile profile) {
log.debug("Saving preferences (dirty={})...", this.dirty);
Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
if (!this.columns.isEmpty()) {
this.columns.entrySet().stream().map((entry) -> {
Element table = new Element("table").setAttribute("name", entry.getKey());
Element columnsElement = new Element("columns");
entry.getValue().entrySet().stream().map((column) -> {
Element columnElement = new Element("column").setAttribute("name", column.getKey());
if (column.getValue().getOrder() != -1) {
columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
}
if (column.getValue().getWidth() != -1) {
columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
}
columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
return columnElement;
}).forEach((columnElement) -> {
columnsElement.addContent(columnElement);
});
table.addContent(columnsElement);
List<SortKey> keys = this.sortKeys.get(entry.getKey());
if (keys != null) {
Element sorter = new Element(SORT_ORDER);
keys.stream().forEach((key) -> {
sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
});
table.addContent(sorter);
}
return table;
}).forEach((table) -> {
element.addContent(table);
});
}
try {
ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
} catch (JDOMException ex) {
log.error("Unable to save user preferences", ex);
}
this.dirty = false;
}
use of javax.swing.RowSorter.SortKey in project JMRI by JMRI.
the class JmriJTablePersistenceManager method setTableColumnPreferences.
/**
* Transition support for the standard {@link jmri.UserPreferencesManager}
* instance (a {@link jmri.managers.JmriUserPreferencesManager}) so it does
* not need to maintain separate knowledge of table column state.
*
* @param table the table name
* @param column the column name
* @param order order of the column
* @param width column width
* @param sort how the column is sorted
* @param hidden true if column is hidden
* @throws NullPointerException if either name is null
* @deprecated since 4.5.2
*/
@Deprecated
public void setTableColumnPreferences(String table, String column, int order, int width, SortOrder sort, boolean hidden) {
Objects.requireNonNull(table, "table name must be nonnull");
if (sort != SortOrder.UNSORTED) {
List<SortKey> keys = new ArrayList<>();
keys.add(new SortKey(order, sort));
this.sortKeys.put(table, keys);
}
this.setPersistedState(table, column, order, width, sort, hidden);
}
Aggregations