Search in sources :

Example 1 with TriggerDataUpdateTask

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

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 AttributeValueMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)1 JavaFxTopComponent (au.gov.asd.tac.constellation.views.JavaFxTopComponent)1 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)1 SelectionToGraphPlugin (au.gov.asd.tac.constellation.views.tableview.plugins.SelectionToGraphPlugin)1 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)1 TableViewConcept (au.gov.asd.tac.constellation.views.tableview.state.TableViewConcept)1 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)1 TriggerDataUpdateTask (au.gov.asd.tac.constellation.views.tableview.tasks.TriggerDataUpdateTask)1 TriggerSelectionUpdateTask (au.gov.asd.tac.constellation.views.tableview.tasks.TriggerSelectionUpdateTask)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1