use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewStateIoProvider method writeObject.
@Override
public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) {
final TableViewState state = (TableViewState) graph.getObjectValue(attribute.getId(), elementId);
if (state == null) {
jsonGenerator.writeNullField(attribute.getName());
} else {
jsonGenerator.writeObjectFieldStart(attribute.getName());
jsonGenerator.writeBooleanField("selectedOnly", state.isSelectedOnly());
jsonGenerator.writeStringField("elementType", state.getElementType().name());
if (state.getTransactionColumnAttributes() == null) {
jsonGenerator.writeNullField(TRANSACTION_COLUMN_ATTRIBUTES);
} else {
jsonGenerator.writeArrayFieldStart(TRANSACTION_COLUMN_ATTRIBUTES);
for (final Tuple<String, Attribute> columnAttribute : state.getTransactionColumnAttributes()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(ATTRIBUTE_PREFIX, columnAttribute.getFirst());
jsonGenerator.writeStringField(ATTRIBUTE_ELEMENT_TYPE, columnAttribute.getSecond().getElementType().name());
jsonGenerator.writeStringField(ATTRIBUTE_NAME, columnAttribute.getSecond().getName());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
}
if (state.getVertexColumnAttributes() == null) {
jsonGenerator.writeNullField(VERTEX_COLUMN_ATTRIBUTES);
} else {
jsonGenerator.writeArrayFieldStart(VERTEX_COLUMN_ATTRIBUTES);
for (final Tuple<String, Attribute> columnAttribute : state.getVertexColumnAttributes()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(ATTRIBUTE_PREFIX, columnAttribute.getFirst());
jsonGenerator.writeStringField(ATTRIBUTE_ELEMENT_TYPE, columnAttribute.getSecond().getElementType().name());
jsonGenerator.writeStringField(ATTRIBUTE_NAME, columnAttribute.getSecond().getName());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
}
jsonGenerator.writeEndObject();
}
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponent method showSelected.
/**
* Copy's the existing table view state and sets the new state's element
* type to the passed value. Also ensures the new state is in "Selected
* Only" mode. The graph table view state attribute is updated with the new
* state and then the table's selection is updated.
*
* @param elementType the element type to set to the new state
* @param elementId can be anything, not used
*/
public Future<?> showSelected(final GraphElementType elementType, final int elementId) {
final TableViewState stateSnapshot = getCurrentState();
final Future<?> stateLock;
if (getCurrentState() != null && getCurrentState().getElementType() != elementType) {
final TableViewState newState = new TableViewState(getCurrentState());
newState.setElementType(elementType);
newState.setSelectedOnly(true);
stateLock = PluginExecution.withPlugin(new UpdateStatePlugin(newState)).executeLater(getCurrentGraph());
} else {
stateLock = null;
}
if (stateLock != null) {
try {
stateLock.get();
} catch (final ExecutionException ex) {
// DO NOTHING
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
return getExecutorService().submit(() -> {
while (stateLock != null && getCurrentState() == stateSnapshot) {
try {
// TODO: remove sleep
// ...but there is an async issue which needs to be
// resolved first. When showSelected() is called, the
// order of operations is to update the Table View
// state (if required) and then to select the rows in
// the table based on the current graph selection. The
// issue is that the state is updated by writing a
// TableViewState object to the graph and letting a
// Table View listener respond to that. Unfortunately,
// there is no obvious way for this operation to know
// when the Table View listener has finished responding,
// so for now we just wait until the currentState object
// matches the state object we updated it to.
Thread.sleep(10);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
getTablePane().getTable().updateSelection(getCurrentGraph(), getCurrentState());
});
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponent method updateState.
/**
* Update the current table state with the table state stored in the passed
* graph attributes. If a table state does not exist in the graph attribute
* then it will crate and new state and set it to the current state in the
* table.
*
* @param graph the graph that the new state will be extracted from
*/
protected void updateState(final Graph graph) {
TableViewState state = null;
boolean newState = false;
if (graph == null) {
currentState = state;
} else {
final ReadableGraph readableGraph = graph.getReadableGraph();
try {
final int stateAttribute = TableViewConcept.MetaAttribute.TABLE_VIEW_STATE.get(readableGraph);
if (stateAttribute == Graph.NOT_FOUND) {
state = new TableViewState();
newState = true;
} else {
state = readableGraph.getObjectValue(stateAttribute, 0);
if (state == null) {
state = new TableViewState();
newState = true;
}
}
if (newState) {
PluginExecution.withPlugin(new UpdateStatePlugin(state)).executeLater(getCurrentGraph());
}
} finally {
readableGraph.release();
}
}
currentState = state;
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableNGTest method testUpdateData.
/**
* Tests the update data method. If the initial state's element type is
* vertex, then the parameters transaction row 1 and 2 can be null. And vice
* versa.
*
* @param stateElementType the initial element type in the table state
* @param isSelectedOnlyMode true if the table's initial state is in
* selected only mode, false otherwise
* @param transactionRow1 row 1 that represents a transaction element in the
* graph
* @param transactionRow2 row 2 that represents a transaction element in the
* graph
* @param vertexRow1 row 1 that represents a vertex element in the graph
* @param vertexRow2 row 2 that represents a vertex element in the graph
* @param expectedRows the expected rows that will be added to the table
*/
private void testUpdateData(final GraphElementType stateElementType, final boolean isSelectedOnlyMode, final ObservableList<String> transactionRow1, final ObservableList<String> transactionRow2, final ObservableList<String> vertexRow1, final ObservableList<String> vertexRow2, final List<ObservableList<String>> expectedRows) {
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(stateElementType);
tableViewState.setSelectedOnly(isSelectedOnlyMode);
final BorderPane progressPane = mock(BorderPane.class);
final ProgressBar progressBar = mock(ProgressBar.class);
when(progressBar.getProgressPane()).thenReturn(progressPane);
final ReadableGraph readableGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(readableGraph);
// Initialize row and element ID mappers and place some fake data in
// to ensure that it is cleared during the update
final Map<Integer, ObservableList<String>> elementIdToRowIndex = new HashMap<>();
elementIdToRowIndex.put(42, FXCollections.observableArrayList());
final Map<ObservableList<String>, Integer> rowToElementIdIndex = new HashMap<>();
rowToElementIdIndex.put(FXCollections.observableArrayList(), 42);
doReturn(elementIdToRowIndex).when(activeTableReference).getElementIdToRowIndex();
doReturn(rowToElementIdIndex).when(activeTableReference).getRowToElementIdIndex();
// Mock graph to extract transaction element IDs
when(readableGraph.getAttribute(stateElementType, "selected")).thenReturn(22);
when(readableGraph.getTransactionCount()).thenReturn(2);
when(readableGraph.getVertexCount()).thenReturn(2);
when(readableGraph.getTransaction(0)).thenReturn(101);
when(readableGraph.getTransaction(1)).thenReturn(102);
when(readableGraph.getVertex(0)).thenReturn(201);
when(readableGraph.getVertex(1)).thenReturn(202);
when(readableGraph.getBooleanValue(22, 101)).thenReturn(false);
when(readableGraph.getBooleanValue(22, 102)).thenReturn(true);
when(readableGraph.getBooleanValue(22, 201)).thenReturn(false);
when(readableGraph.getBooleanValue(22, 202)).thenReturn(true);
// Mock the transaction row creation
doReturn(transactionRow1).when(table).getRowDataForTransaction(readableGraph, 101);
doReturn(transactionRow2).when(table).getRowDataForTransaction(readableGraph, 102);
doReturn(vertexRow1).when(table).getRowDataForVertex(readableGraph, 201);
doReturn(vertexRow2).when(table).getRowDataForVertex(readableGraph, 202);
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).then(mockitoInvocation -> {
final Runnable runnable = (Runnable) mockitoInvocation.getArgument(0);
if (runnable instanceof UpdateDataTask) {
final UpdateDataTask updateDataTask = (UpdateDataTask) runnable;
// If this is not called then the test will halt forever
updateDataTask.getUpdateDataLatch().countDown();
assertEquals(expectedRows, updateDataTask.getRows());
} else {
// Progress Bar
runnable.run();
}
return null;
});
table.updateData(graph, tableViewState, progressBar);
}
assertTrue(elementIdToRowIndex.isEmpty());
assertTrue(rowToElementIdIndex.isEmpty());
verify(tablePane).setCenter(progressPane);
verify(readableGraph).release();
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableNGTest method updateSelectionOnFxThread.
@Test(expectedExceptions = IllegalStateException.class)
public void updateSelectionOnFxThread() {
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
table.updateSelection(graph, new TableViewState());
}
}
Aggregations