Search in sources :

Example 1 with TableViewState

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();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 2 with TableViewState

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();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 3 with TableViewState

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);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ExecutionException(java.util.concurrent.ExecutionException) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 4 with TableViewState

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);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 5 with TableViewState

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));
}
Also used : TableViewTopComponent(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent) EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Orientation(javafx.geometry.Orientation) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) ToolBar(javafx.scene.control.ToolBar) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) Side(javafx.geometry.Side) Platform(javafx.application.Platform) Separator(javafx.scene.control.Separator) ActionEvent(javafx.event.ActionEvent) Insets(javafx.geometry.Insets) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ToggleButton(javafx.scene.control.ToggleButton) ImageView(javafx.scene.image.ImageView) HelpCtx(org.openide.util.HelpCtx) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) Tooltip(javafx.scene.control.Tooltip) Insets(javafx.geometry.Insets) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ToolBar(javafx.scene.control.ToolBar) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Separator(javafx.scene.control.Separator)

Aggregations

TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)65 Test (org.testng.annotations.Test)50 Graph (au.gov.asd.tac.constellation.graph.Graph)24 Platform (javafx.application.Platform)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)14 ObservableList (javafx.collections.ObservableList)14 Attribute (au.gov.asd.tac.constellation.graph.Attribute)13 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)12 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)10 TableColumn (javafx.scene.control.TableColumn)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)7 ListChangeListener (javafx.collections.ListChangeListener)7 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)6 TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)5 ArrayList (java.util.ArrayList)5