use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin in project constellation by constellation-app.
the class TableToolbarNGTest method elementTypeChangeActionChecks.
/**
* When the element type button is pressed the tables state is switched
* between VERTEX and TRANSACTION. This verifies that as the button is
* pressed that transition happens and the update state plugin is executed
* triggering the required changes. The buttons icon should also change to
* the element type now set in the state.
*
* @param elementTypeInitialState the initial element type in the state
* before the button is pressed
* @param elementTypeEndState the expected element type in the state after
* the button is pressed
* @param expectedNewIcon the expected image to be now on the element type
* change button
*/
private void elementTypeChangeActionChecks(final GraphElementType elementTypeInitialState, final GraphElementType elementTypeEndState, 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.setElementType(elementTypeInitialState);
when(tableTopComponent.getCurrentState()).thenReturn(tableViewState);
final ArgumentCaptor<UpdateStatePlugin> captor = ArgumentCaptor.forClass(UpdateStatePlugin.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(captor.capture())).thenReturn(pluginExecution);
tableToolbar.getElementTypeButton().getOnAction().handle(actionEvent);
final UpdateStatePlugin updatePlugin = captor.getValue();
final ImageView buttonIcon = (ImageView) tableToolbar.getElementTypeButton().getGraphic();
assertTrue(isImageEqual(expectedNewIcon, buttonIcon.getImage()));
assertEquals(elementTypeEndState, updatePlugin.getTableViewState().getElementType());
verify(pluginExecution).executeLater(graph);
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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.plugins.UpdateStatePlugin 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