Search in sources :

Example 1 with AttributeValueMonitor

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

the class ListeningTopComponent method newActiveGraph.

@Override
public final void newActiveGraph(final Graph graph) {
    LOGGER.finer("NewActiveGraph");
    if (currentGraph != graph) {
        if (currentGraph != null) {
            currentGraph.removeGraphChangeListener(this);
            currentGraph = null;
        }
        if (graph != null) {
            currentGraph = graph;
            currentGraph.addGraphChangeListener(this);
            ReadableGraph readableGraph = currentGraph.getReadableGraph();
            try {
                final Map<GlobalMonitor, Consumer<Graph>> globalMonitorsCopy;
                synchronized (globalMonitors) {
                    globalMonitorsCopy = new HashMap<>(globalMonitors);
                }
                globalMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
                final Map<StructureMonitor, Consumer<Graph>> structureMonitorsCopy;
                synchronized (globalMonitors) {
                    structureMonitorsCopy = new HashMap<>(structureMonitors);
                }
                structureMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
                final Map<AttributeCountMonitor, Consumer<Graph>> attributeCountMonitorsCopy;
                synchronized (globalMonitors) {
                    attributeCountMonitorsCopy = new HashMap<>(attributeCountMonitors);
                }
                attributeCountMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
                final Map<AttributeValueMonitor, Tuple<Consumer<Graph>, MonitorTransitionFilter>> attributeMonitorsCopy;
                synchronized (globalMonitors) {
                    attributeMonitorsCopy = new HashMap<>(attributeValueMonitors);
                }
                attributeMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
            } finally {
                readableGraph.release();
            }
            graphChanged(null);
        }
    }
    handleNewGraph(graph);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AttributeCountMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor) AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor) GlobalMonitor(au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) Consumer(java.util.function.Consumer) StructureMonitor(au.gov.asd.tac.constellation.graph.monitor.StructureMonitor) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 2 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} this top component should
 * listen to.
 * @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.
 * @param filter a {@link MonitorTransitionFilter} describing which
 * {@link MonitorTransition} objects this top component should react to.
 * @return the {@link AttributeValueMonitor} attached to your handler.
 */
protected AttributeValueMonitor addAttributeValueChangeHandler(final SchemaAttribute attribute, final Consumer<Graph> handler, final MonitorTransitionFilter filter) {
    final AttributeValueMonitor attributeValueMonitor = new AttributeValueMonitor(attribute);
    initialiseMonitor(attributeValueMonitor);
    attributeValueMonitors.put(attributeValueMonitor, Tuple.create(handler, filter));
    LOGGER.log(Level.FINE, ADDED_MONITOR_COUNT_FORMAT, attributeValueMonitors.size());
    return attributeValueMonitor;
}
Also used : AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)

Example 3 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 elementType a {@link GraphElementType} representing the type of
 * attribute this top component should listen to.
 * @param attributeName a {@link String} representing the name of the
 * attribute this top component should listen to.
 * @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 GraphElementType elementType, final String attributeName, final Consumer<Graph> handler) {
    final AttributeValueMonitor attributeValueMonitor = new AttributeValueMonitor(elementType, attributeName);
    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 4 with AttributeValueMonitor

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

the class ListeningTopComponent method graphChanged.

@Override
public final void graphChanged(final GraphChangeEvent event) {
    LOGGER.finer("GraphChange");
    if (event != null && ignoredEvents.contains(event.getDescription())) {
        LOGGER.log(Level.FINER, "IgnoringEvent::{0}", event.getDescription());
        return;
    }
    ReadableGraph readableGraph = currentGraph.getReadableGraph();
    try {
        final Map<GlobalMonitor, Consumer<Graph>> globalMonitorsCopy;
        synchronized (globalMonitors) {
            globalMonitorsCopy = new HashMap<>(globalMonitors);
        }
        globalMonitorsCopy.forEach((monitor, handler) -> {
            LOGGER.finer("GraphChanged::CheckGlobal");
            if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
                LOGGER.finer("GraphChanged::UpdateGlobal");
                if (handler != null) {
                    handler.accept(currentGraph);
                }
            }
        });
        final Map<StructureMonitor, Consumer<Graph>> structureMonitorsCopy;
        synchronized (globalMonitors) {
            structureMonitorsCopy = new HashMap<>(structureMonitors);
        }
        structureMonitorsCopy.forEach((monitor, handler) -> {
            LOGGER.finer("GraphChanged::CheckStructure");
            if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
                LOGGER.finer("GraphChanged::UpdateStructure");
                if (handler != null) {
                    handler.accept(currentGraph);
                }
            }
        });
        final Map<AttributeCountMonitor, Consumer<Graph>> attributeCountMonitorsCopy;
        synchronized (globalMonitors) {
            attributeCountMonitorsCopy = new HashMap<>(attributeCountMonitors);
        }
        attributeCountMonitorsCopy.forEach((monitor, handler) -> {
            LOGGER.finer("GraphChanged::CheckAttributeCount");
            if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
                LOGGER.finer("GraphChanged::UpdateAttributeCount");
                if (handler != null) {
                    handler.accept(currentGraph);
                }
            }
        });
        final Map<AttributeValueMonitor, Tuple<Consumer<Graph>, MonitorTransitionFilter>> attributeMonitorsCopy;
        synchronized (globalMonitors) {
            attributeMonitorsCopy = new HashMap<>(attributeValueMonitors);
        }
        attributeMonitorsCopy.forEach((monitor, handlerPair) -> {
            LOGGER.finer("GraphChanged::CheckAttribute");
            final Consumer<Graph> handler = handlerPair.getFirst();
            final MonitorTransitionFilter transitionFilter = handlerPair.getSecond();
            monitor.update(readableGraph);
            if (transitionFilter.matchesTransitions(monitor)) {
                LOGGER.log(Level.FINER, "GraphChanged::UpdateAttribute::{0}", monitor.getName());
                if (handler != null) {
                    handler.accept(currentGraph);
                }
            }
        });
    } finally {
        readableGraph.release();
    }
    handleGraphChange(event);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AttributeCountMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor) AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor) GlobalMonitor(au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) MonitorTransitionFilter(au.gov.asd.tac.constellation.graph.monitor.MonitorTransitionFilter) Consumer(java.util.function.Consumer) StructureMonitor(au.gov.asd.tac.constellation.graph.monitor.StructureMonitor) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 5 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. This method will return the {@link AttributeValueMonitor}
 * attached to your handler, which you can later use to change or remove
 * that handler.
 *
 * @param elementType a {@link GraphElementType} representing the type of
 * attribute this top component should listen to.
 * @param attributeName a {@link String} representing the name of the
 * attribute this top component should listen to.
 * @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.
 * @param filter a {@link MonitorTransitionFilter} describing which
 * {@link MonitorTransition} objects this top component should react to.
 * @return the {@link AttributeValueMonitor} attached to your handler.
 */
protected AttributeValueMonitor addAttributeValueChangeHandler(final GraphElementType elementType, final String attributeName, final Consumer<Graph> handler, final MonitorTransitionFilter filter) {
    final AttributeValueMonitor attributeValueMonitor = new AttributeValueMonitor(elementType, attributeName);
    initialiseMonitor(attributeValueMonitor);
    attributeValueMonitors.put(attributeValueMonitor, Tuple.create(handler, filter));
    LOGGER.log(Level.FINE, ADDED_MONITOR_COUNT_FORMAT, attributeValueMonitors.size());
    return attributeValueMonitor;
}
Also used : AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)

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