Search in sources :

Example 1 with UpdateStatePlugin

use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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 UpdateStatePlugin

use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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 3 with UpdateStatePlugin

use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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)

Example 4 with UpdateStatePlugin

use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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());
    });
}
Also used : TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with UpdateStatePlugin

use of au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin 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;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)

Aggregations

UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)8 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)8 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 ActionEvent (javafx.event.ActionEvent)3 ImageView (javafx.scene.image.ImageView)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.testng.annotations.Test)2 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)1 UserInterfaceIconProvider (au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider)1 TableViewTopComponent (au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent)1 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)1 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1