use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponentNGTest method updateStateNotPresentInGraphAttributes.
@Test
public void updateStateNotPresentInGraphAttributes() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
doCallRealMethod().when(tableViewTopComponent).getCurrentState();
final Graph graph = mock(Graph.class);
final Graph currentGraph = mock(Graph.class);
final ReadableGraph readableGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(readableGraph);
when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
when(readableGraph.getObjectValue(42, 0)).thenReturn(null);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
assertEquals(new TableViewState(), plugin.getTableViewState());
return pluginExecution;
});
tableViewTopComponent.updateState(graph);
verify(pluginExecution).executeLater(currentGraph);
}
assertEquals(new TableViewState(), tableViewTopComponent.getCurrentState());
verify(graph).getReadableGraph();
verify(readableGraph).release();
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponentNGTest method updateStatePresentInGraphAttributes.
@Test
public void updateStatePresentInGraphAttributes() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
doCallRealMethod().when(tableViewTopComponent).getCurrentState();
final Graph graph = mock(Graph.class);
final ReadableGraph readableGraph = mock(ReadableGraph.class);
final TableViewState state = new TableViewState();
// <-- Non Default Value
state.setElementType(GraphElementType.META);
when(graph.getReadableGraph()).thenReturn(readableGraph);
when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
when(readableGraph.getObjectValue(42, 0)).thenReturn(state);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
tableViewTopComponent.updateState(graph);
pluginExecutionMockedStatic.verifyNoInteractions();
}
assertEquals(state, tableViewTopComponent.getCurrentState());
tableViewTopComponent.updateState(null);
assertEquals(null, tableViewTopComponent.getCurrentState());
// Should only be called once. Second call has null graph
verify(graph).getReadableGraph();
verify(readableGraph).release();
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewTopComponentNGTest method showSelected.
@Test
public void showSelected() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
final TableViewState currentState = new TableViewState();
final Graph currentGraph = mock(Graph.class);
final TableViewState expectedNewState = new TableViewState();
expectedNewState.setElementType(GraphElementType.META);
expectedNewState.setSelectedOnly(true);
final TablePane tablePane = mock(TablePane.class);
final Table table = mock(Table.class);
doCallRealMethod().when(tableViewTopComponent).showSelected(any(GraphElementType.class), anyInt());
when(tableViewTopComponent.getCurrentState()).thenReturn(currentState);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
when(tableViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
when(tablePane.getTable()).thenReturn(table);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
when(pluginExecution.executeLater(any(Graph.class))).thenReturn(CompletableFuture.completedFuture(null));
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
assertEquals(expectedNewState, plugin.getTableViewState());
// Change the mock now that the "Update Plugin" has run
when(tableViewTopComponent.getCurrentState()).thenReturn(expectedNewState);
return pluginExecution;
});
final Future<?> updateTask = tableViewTopComponent.showSelected(GraphElementType.META, 42);
// Ensure that the update selection task is completed
try {
updateTask.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
fail("The submitted task in show selected did not complete in the " + "allowed time. Something is probably wrong.");
}
verify(pluginExecution).executeLater(currentGraph);
verify(table).updateSelection(currentGraph, expectedNewState);
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class ActiveTableReferenceNGTest method updateVisibleColumnsRemove.
@Test
public void updateVisibleColumnsRemove() {
try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final Graph graph = mock(Graph.class);
final Attribute attribute = mock(Attribute.class);
final PluginExecution pluginExecution = mock(PluginExecution.class);
final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute));
final TableViewState tableViewState = new TableViewState();
tableViewState.setColumnAttributes(stateColumnAttributes);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("stateAttr", attribute))));
activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.REMOVE);
verify(pluginExecution).executeLater(graph);
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableToolbar method init.
/**
* Initializes the export menu. Until this method is called, all menu UI
* components will be null.
*/
public void init() {
columnVisibilityButton = createButton(COLUMNS_ICON, COLUMN_VISIBILITY, e -> {
final ColumnVisibilityContextMenu columnVisibilityMenu = createColumnVisibilityContextMenu();
columnVisibilityMenu.getContextMenu().show(columnVisibilityButton, Side.RIGHT, 0, 0);
e.consume();
});
selectedOnlyButton = createToggleButton(getSelectedOnlyInitialIcon(), SELECTED_ONLY, e -> {
if (getTableViewTopComponent().getCurrentState() != null) {
getActiveTableReference().getSelectedOnlySelectedRows().clear();
final TableViewState newState = new TableViewState(getTableViewTopComponent().getCurrentState());
newState.setSelectedOnly(!getTableViewTopComponent().getCurrentState().isSelectedOnly());
selectedOnlyButton.setGraphic(newState.isSelectedOnly() ? SELECTED_VISIBLE_ICON : ALL_VISIBLE_ICON);
PluginExecution.withPlugin(new UpdateStatePlugin(newState)).executeLater(getTableViewTopComponent().getCurrentGraph());
}
e.consume();
});
elementTypeButton = createButton(getElementTypeInitialIcon(), ELEMENT_TYPE, e -> {
if (getTableViewTopComponent().getCurrentState() != null) {
final TableViewState newState = new TableViewState(getTableViewTopComponent().getCurrentState());
newState.setElementType(getTableViewTopComponent().getCurrentState().getElementType() == GraphElementType.TRANSACTION ? GraphElementType.VERTEX : GraphElementType.TRANSACTION);
elementTypeButton.setGraphic(newState.getElementType() == GraphElementType.TRANSACTION ? TRANSACTION_ICON : VERTEX_ICON);
PluginExecution.withPlugin(new UpdateStatePlugin(newState)).executeLater(getTableViewTopComponent().getCurrentGraph());
}
e.consume();
});
copyMenu = createCopyMenu();
exportMenu = createExportMenu();
preferencesMenu = createPreferencesMenu();
helpButton = createButton(HELP_ICON, HELP, e -> {
getHelpContext().display();
e.consume();
});
toolbar = new ToolBar(columnVisibilityButton, selectedOnlyButton, elementTypeButton, new Separator(), copyMenu.getCopyButton(), exportMenu.getExportButton(), preferencesMenu.getPreferencesButton(), helpButton);
toolbar.setOrientation(Orientation.VERTICAL);
toolbar.setPadding(new Insets(5));
}
Aggregations