Search in sources :

Example 6 with AttributeValueMonitor

use of au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor in project constellation by constellation-app.

the class ListeningTopComponent method addAttributeValueChangeHandler.

/**
 * Defines how your TopComponent handles changes to special attributes which
 * affect it.
 *
 * @param attribute a {@link SchemaAttribute} representing the state of *
 * this top component.
 * @param handler a {@link Consumer} of {@link Graph} objects which
 * determines how this top component should respond to changes to the value
 * of the specified attribute.
 * @return the {@link AttributeValueMonitor} attached to your handler.
 */
protected AttributeValueMonitor addAttributeValueChangeHandler(final SchemaAttribute attribute, final Consumer<Graph> handler) {
    final AttributeValueMonitor attributeValueMonitor = new AttributeValueMonitor(attribute);
    initialiseMonitor(attributeValueMonitor);
    attributeValueMonitors.put(attributeValueMonitor, Tuple.create(handler, getDefaultTransitionFilter()));
    LOGGER.log(Level.FINE, ADDED_MONITOR_COUNT_FORMAT, attributeValueMonitors.size());
    return attributeValueMonitor;
}
Also used : AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)

Example 7 with AttributeValueMonitor

use of au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor 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

AttributeValueMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)7 Graph (au.gov.asd.tac.constellation.graph.Graph)3 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)3 AttributeCountMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor)2 GlobalMonitor (au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor)2 StructureMonitor (au.gov.asd.tac.constellation.graph.monitor.StructureMonitor)2 Consumer (java.util.function.Consumer)2 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 MonitorTransitionFilter (au.gov.asd.tac.constellation.graph.monitor.MonitorTransitionFilter)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)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