use of javax.swing.SortOrder in project JMRI by JMRI.
the class JmriJTablePersistenceManager method cacheState.
@Override
public void cacheState(JTable table) {
Objects.requireNonNull(table.getName(), "table name must be nonnull");
TableColumnModel model = table.getColumnModel();
Objects.requireNonNull(model, "table " + table.getName() + " has a null columnModel");
RowSorter sorter = table.getRowSorter();
boolean isXModel = model instanceof XTableColumnModel;
Enumeration<TableColumn> e = model.getColumns();
while (e.hasMoreElements()) {
TableColumn column = e.nextElement();
String name = column.getHeaderValue().toString();
int index = column.getModelIndex();
if (isXModel) {
index = ((XTableColumnModel) model).getColumnIndex(column.getIdentifier(), false);
}
int width = column.getPreferredWidth();
boolean hidden = false;
if (isXModel) {
hidden = !((XTableColumnModel) model).isColumnVisible(column);
}
SortOrder sorted = SortOrder.UNSORTED;
if (sorter != null) {
sorted = RowSorterUtil.getSortOrder(sorter, index);
log.trace("Column {} (model index {}) is {}", name, index, sorted);
}
this.setPersistedState(table.getName(), name, index, width, sorted, hidden);
}
if (sorter != null) {
this.sortKeys.put(table.getName(), new ArrayList<>(sorter.getSortKeys()));
}
this.dirty = true;
}
use of javax.swing.SortOrder 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.SortOrder in project JMRI by JMRI.
the class JmriJTablePersistenceManagerTest method testSetPersistedState.
/**
* Test of setPersistedState method, of class JmriJTablePersistenceManager.
*/
@Test
@Ignore
public void testSetPersistedState() {
System.out.println("setPersistedState");
String table = "";
String column = "";
int order = 0;
int width = 0;
SortOrder sort = null;
boolean hidden = false;
JmriJTablePersistenceManager instance = new JmriJTablePersistenceManager();
instance.setPersistedState(table, column, order, width, sort, hidden);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
Aggregations