Search in sources :

Example 56 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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 57 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableViewPageFactoryNGTest method updateSelectionGraphNull.

@Test
public void updateSelectionGraphNull() {
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        tableViewPageFactory.restoreSelectionFromGraph(null, new TableViewState(), null);
        platformMockedStatic.verifyNoInteractions();
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 58 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class UpdateStatePluginNGTest method updateStatePlugin.

@Test
public void updateStatePlugin() throws InterruptedException, PluginException {
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.META);
    final UpdateStatePlugin updateStatePlugin = new UpdateStatePlugin(tableViewState);
    updateStatePlugin.edit(graph, null, null);
    final ArgumentCaptor<TableViewState> captor = ArgumentCaptor.forClass(TableViewState.class);
    verify(graph).setObjectValue(eq(0), eq(0), captor.capture());
    assertEquals(tableViewState, captor.getValue());
    assertNotSame(tableViewState, captor.getValue());
    assertEquals("Table View: Update State", updateStatePlugin.getName());
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 59 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableViewTopComponent method handleNewGraph.

/**
 * Update the current state with the new state pulled from the passed
 * graph's attributes and update the attribute handlers so that the table is
 * only notified for attribute changes that it cares about. Then trigger a
 * table refresh using the new graph as its source of truth.
 *
 * @param graph the new graph
 */
@Override
protected void handleNewGraph(final Graph graph) {
    if (!needsUpdate()) {
        return;
    }
    // Take a copy of the current state that is associated with the current graph
    final TableViewState previousState = currentState;
    // Update the current state by pulling the table state attribute from
    // the new graph
    updateState(graph);
    // Determine the visible column changes
    final Set<Tuple<String, Attribute>> removedColumnAttributes = getRemovedAttributes(previousState, currentState);
    final Set<Tuple<String, Attribute>> addedColumnAttributes = getAddedAttributes(previousState, currentState);
    // with the state associated with the new graph
    if (columnAttributeMonitors != null && !removedColumnAttributes.isEmpty()) {
        final Set<AttributeValueMonitor> removeMonitors = columnAttributeMonitors.stream().filter(monitor -> removedColumnAttributes.stream().anyMatch(columnAttributeTuple -> columnAttributeTuple.getSecond().getElementType() == monitor.getElementType() && columnAttributeTuple.getSecond().getName().equals(monitor.getName()))).collect(Collectors.toSet());
        removeMonitors.forEach(monitor -> {
            removeAttributeValueChangeHandler(monitor);
            columnAttributeMonitors.remove(monitor);
        });
    }
    // Update the table data, columns and selection with the new graph
    pane.updateTable(graph, currentState);
    // the table should have its data refreshed
    if (currentState != null && currentState.getColumnAttributes() != null && !addedColumnAttributes.isEmpty()) {
        addedColumnAttributes.forEach(attributeTuple -> columnAttributeMonitors.add(addAttributeValueChangeHandler(attributeTuple.getSecond().getElementType(), attributeTuple.getSecond().getName(), g -> executorService.submit(new TriggerDataUpdateTask(pane, g, getCurrentState())))));
    }
}
Also used : TopComponent(org.openide.windows.TopComponent) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) ActionID(org.openide.awt.ActionID) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ActionReference(org.openide.awt.ActionReference) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) TriggerSelectionUpdateTask(au.gov.asd.tac.constellation.views.tableview.tasks.TriggerSelectionUpdateTask) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Graph(au.gov.asd.tac.constellation.graph.Graph) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableViewConcept(au.gov.asd.tac.constellation.views.tableview.state.TableViewConcept) SelectionToGraphPlugin(au.gov.asd.tac.constellation.views.tableview.plugins.SelectionToGraphPlugin) Attribute(au.gov.asd.tac.constellation.graph.Attribute) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ExecutorService(java.util.concurrent.ExecutorService) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) TriggerDataUpdateTask(au.gov.asd.tac.constellation.views.tableview.tasks.TriggerDataUpdateTask) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) ActionReferences(org.openide.awt.ActionReferences) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Messages(org.openide.util.NbBundle.Messages) JavaFxTopComponent(au.gov.asd.tac.constellation.views.JavaFxTopComponent) TriggerDataUpdateTask(au.gov.asd.tac.constellation.views.tableview.tasks.TriggerDataUpdateTask) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 60 with TableViewState

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

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