Search in sources :

Example 6 with UpdateStatePlugin

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();
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ActionEvent(javafx.event.ActionEvent) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) ImageView(javafx.scene.image.ImageView)

Example 7 with UpdateStatePlugin

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();
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ActionEvent(javafx.event.ActionEvent) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) ImageView(javafx.scene.image.ImageView)

Example 8 with UpdateStatePlugin

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);
}
Also used : TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

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