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;
}
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())))));
}
}
Aggregations