use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableToolbarNGTest method selectedOnlyModeActionChecks.
/**
* When the selected only mode button is pressed, the table switches between
* "Selected Only Mode" ON and OFF. This verifies that as the button is
* pressed that transition between ON and OFF happens and the update state
* plugin is executed triggering the required changes.
*
* @param selectedOnlyModeInitialState the initial status of the "Selected
* Only Mode", the expected status after the button is pressed will be the
* inverse
* @param expectedNewIcon the new image that is expected to be on the button
* after it was clicked
*/
private void selectedOnlyModeActionChecks(final boolean selectedOnlyModeInitialState, final Image expectedNewIcon) {
try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
final ActionEvent actionEvent = mock(ActionEvent.class);
final TableViewState tableViewState = new TableViewState();
tableViewState.setSelectedOnly(selectedOnlyModeInitialState);
when(tableTopComponent.getCurrentState()).thenReturn(tableViewState);
final ArgumentCaptor<UpdateStatePlugin> captor = ArgumentCaptor.forClass(UpdateStatePlugin.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(captor.capture())).thenReturn(pluginExecution);
tableToolbar.getSelectedOnlyButton().getOnAction().handle(actionEvent);
final UpdateStatePlugin updatePlugin = captor.getValue();
final ImageView buttonIcon = (ImageView) tableToolbar.getSelectedOnlyButton().getGraphic();
assertTrue(isImageEqual(expectedNewIcon, buttonIcon.getImage()));
assertEquals(!selectedOnlyModeInitialState, updatePlugin.getTableViewState().isSelectedOnly());
verify(pluginExecution).executeLater(graph);
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewPageFactoryNGTest method updateSelectionGraphNull.
@Test
public void updateSelectionGraphNull() {
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
tableViewPageFactory.restoreSelectionFromGraph(null, new TableViewState(), null);
platformMockedStatic.verifyNoInteractions();
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class UpdateStatePluginNGTest method updateStatePlugin.
@Test
public void updateStatePlugin() throws InterruptedException, PluginException {
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(GraphElementType.META);
final UpdateStatePlugin updateStatePlugin = new UpdateStatePlugin(tableViewState);
updateStatePlugin.edit(graph, null, null);
final ArgumentCaptor<TableViewState> captor = ArgumentCaptor.forClass(TableViewState.class);
verify(graph).setObjectValue(eq(0), eq(0), captor.capture());
assertEquals(tableViewState, captor.getValue());
assertNotSame(tableViewState, captor.getValue());
assertEquals("Table View: Update State", updateStatePlugin.getName());
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponent method handleNewGraph.
/**
* Update the current state with the new state pulled from the passed
* graph's attributes and update the attribute handlers so that the table is
* only notified for attribute changes that it cares about. Then trigger a
* table refresh using the new graph as its source of truth.
*
* @param graph the new graph
*/
@Override
protected void handleNewGraph(final Graph graph) {
if (!needsUpdate()) {
return;
}
// Take a copy of the current state that is associated with the current graph
final TableViewState previousState = currentState;
// Update the current state by pulling the table state attribute from
// the new graph
updateState(graph);
// Determine the visible column changes
final Set<Tuple<String, Attribute>> removedColumnAttributes = getRemovedAttributes(previousState, currentState);
final Set<Tuple<String, Attribute>> addedColumnAttributes = getAddedAttributes(previousState, currentState);
// with the state associated with the new graph
if (columnAttributeMonitors != null && !removedColumnAttributes.isEmpty()) {
final Set<AttributeValueMonitor> removeMonitors = columnAttributeMonitors.stream().filter(monitor -> removedColumnAttributes.stream().anyMatch(columnAttributeTuple -> columnAttributeTuple.getSecond().getElementType() == monitor.getElementType() && columnAttributeTuple.getSecond().getName().equals(monitor.getName()))).collect(Collectors.toSet());
removeMonitors.forEach(monitor -> {
removeAttributeValueChangeHandler(monitor);
columnAttributeMonitors.remove(monitor);
});
}
// Update the table data, columns and selection with the new graph
pane.updateTable(graph, currentState);
// the table should have its data refreshed
if (currentState != null && currentState.getColumnAttributes() != null && !addedColumnAttributes.isEmpty()) {
addedColumnAttributes.forEach(attributeTuple -> columnAttributeMonitors.add(addAttributeValueChangeHandler(attributeTuple.getSecond().getElementType(), attributeTuple.getSecond().getName(), g -> executorService.submit(new TriggerDataUpdateTask(pane, g, getCurrentState())))));
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class ActiveTableReference method updateVisibleColumns.
/**
* Updates the visible columns in the table's state. Once the new state is
* determined the it is updated in the graph.
* <p/>
* The following are the different ways in which the visible columns can be
* updated
* <ul>
* <li>
* <b>ADD:</b> the passed columns are added on top of existing visible
* columns in the current state.
* </li>
* <li>
* <b>REMOVE:</b> the passed columns are removed from the visible columns in
* the current state.
* </li>
* <li>
* <b>REPLACE:</b> the passed columns become the new visible columns
* </li>
* </ul>
*
* @param graph the graph to update with the new state
* @param state the current table state
* @param columnAttributes the column attributes to update the state with
* @param updateState the manner in which the state will be updated with the
* column attributes
* @return a {@link Future<?>} object of the plugin execution.
*/
public Future<?> updateVisibleColumns(final Graph graph, final TableViewState state, final List<Tuple<String, Attribute>> columnAttributes, final UpdateMethod updateState) {
if (graph != null && state != null) {
final TableViewState newState = new TableViewState(state);
final List<Tuple<String, Attribute>> newColumnAttributes = new ArrayList<>();
switch(updateState) {
case ADD:
if (newState.getColumnAttributes() != null) {
newColumnAttributes.addAll(newState.getColumnAttributes());
}
newColumnAttributes.addAll(columnAttributes);
break;
case REMOVE:
if (newState.getColumnAttributes() != null) {
newColumnAttributes.addAll(newState.getColumnAttributes());
}
newColumnAttributes.removeAll(columnAttributes);
break;
case REPLACE:
newColumnAttributes.addAll(columnAttributes);
break;
}
newState.setColumnAttributes(newColumnAttributes);
return PluginExecution.withPlugin(new UpdateStatePlugin(newState)).executeLater(graph);
}
return CompletableFuture.completedFuture(null);
}
Aggregations