use of au.gov.asd.tac.constellation.views.tableview.utilities.ColumnIndexSort in project constellation by constellation-app.
the class Table method updateColumns.
/**
* Update the columns in the table using the graph and state. This will
* clear and refresh the column index and then trigger a refresh of the
* table view, populating from the new column index.
* <p/>
* If the table's state has an element type of VERTEX then all the columns
* will be prefixed with ".source".
* <p/>
* If the element type is TRANSACTION then the attributes belonging to
* transactions will be prefixed with ".transaction". The vertex attributes
* will also be added as columns in this case. When the state's element type
* is TRANSACTION the vertex attributes will be prefixed with both ".source"
* and ".destination" so that it is distinguishable on which end of the
* transaction those values are present.
* <p/>
* Note that column references are reused where possible to ensure certain
* toolbar/menu operations to work correctly.
* <p/>
* The entire method is synchronized so it should be thread safe and keeps
* the locking logic simpler. Maybe this method could be broken out further.
*
* @param graph the graph to retrieve data from.
* @param state the current table view state.
*/
public void updateColumns(final Graph graph, final TableViewState state) {
synchronized (TABLE_LOCK) {
if (graph != null && state != null) {
if (Platform.isFxApplicationThread()) {
throw new IllegalStateException(ATTEMPT_PROCESS_JAVAFX);
}
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException(ATTEMPT_PROCESS_EDT);
}
// Clear current columnIndex, but cache the column objects for reuse
final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = getColumnIndex().stream().collect(Collectors.toMap(column -> column.getTableColumn().getText(), column -> column.getTableColumn(), (e1, e2) -> e1));
getColumnIndex().clear();
// Update columnIndex based on graph attributes
final ReadableGraph readableGraph = graph.getReadableGraph();
try {
// Creates "source." columns from vertex attributes
getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.VERTEX, GraphRecordStoreUtilities.SOURCE, columnReferenceMap));
if (state.getElementType() == GraphElementType.TRANSACTION) {
// Creates "transaction." columns from transaction attributes
getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, GraphRecordStoreUtilities.TRANSACTION, columnReferenceMap));
// Creates "destination." columns from vertex attributes
getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.VERTEX, GraphRecordStoreUtilities.DESTINATION, columnReferenceMap));
}
} finally {
readableGraph.release();
}
// If there are no visible columns specified, write the key columns to the state
if (state.getColumnAttributes() == null) {
openColumnVisibilityMenu();
return;
}
// Sort columns in columnIndex by state, prefix and attribute name
getColumnIndex().sort(new ColumnIndexSort(state));
// Style and format columns in columnIndex
getColumnIndex().forEach(columnTuple -> {
final TableColumn<ObservableList<String>, String> column = columnTuple.getTableColumn();
// assign cells to columns
column.setCellValueFactory(cellData -> {
final int cellIndex = tableView.getColumns().indexOf(cellData.getTableColumn());
if (cellIndex < cellData.getValue().size()) {
return new SimpleStringProperty(cellData.getValue().get(cellIndex));
} else {
return null;
}
});
// Assign values and styles to cells
column.setCellFactory(cellColumn -> new TableCellFactory(cellColumn, this));
});
// calculated column changes
if (!Thread.currentThread().isInterrupted()) {
// The update columns task holds state between executions. So we need to
// reset some fields each time before it is run.
updateColumnsTask.reset(columnReferenceMap, state);
Platform.runLater(updateColumnsTask);
}
}
}
}
Aggregations