use of org.osate.ge.gef.DockedShape in project osate2 by osate.
the class Overlays method refresh.
/**
* Refreshes the overlays based on the current selection
* This should be called by the editor whenever a change could affect the overlay.
* Specifically, it needs to be called whenever the diagram changes. Connection diagram elements may change to shapes and vice versa
* which would cause the nodes to change without changing the selected diagram elements.
* @param selection the current selection.
*/
@SuppressWarnings("unchecked")
public void refresh(final IStructuredSelection selection) {
Display.getCurrent().asyncExec(() -> {
final ImmutableMap.Builder<DiagramElement, SelectedNodeOverlay> newDiagramElementToSelectedNodeOverlayMapBuilder = ImmutableMap.builderWithExpectedSize(selection.size());
final ArrayList<DiagramElement> selectedDiagramElements = selectionToDiagramElements(selection);
// Add existing selected node overlays for selected diagram elements to new map.
for (final Entry<DiagramElement, SelectedNodeOverlay> existingEntry : diagramElementToSelectedNodeOverlayMap.entrySet()) {
if (selectedDiagramElements.contains(existingEntry.getKey()) && gefDiagram.getSceneNode(existingEntry.getKey()) == existingEntry.getValue().getSelectedNode()) {
newDiagramElementToSelectedNodeOverlayMapBuilder.put(existingEntry.getKey(), existingEntry.getValue());
}
}
// Create selected node overlays for newly selected nodes.
for (int i = 0; i < selectedDiagramElements.size(); i++) {
final DiagramElement selectedDiagramElement = selectedDiagramElements.get(i);
final boolean primary = i == selectedDiagramElements.size() - 1;
final SelectedNodeOverlay existingOverlay = diagramElementToSelectedNodeOverlayMap.get(selectedDiagramElement);
if (diagramElementToSelectedNodeOverlayMap.containsKey(selectedDiagramElement)) {
// Set whether it is primary
existingOverlay.setPrimary(primary);
} else {
final Node selectedNode = gefDiagram.getSceneNode(selectedDiagramElement);
if (selectedNode != null) {
if (selectedNode instanceof ContainerShape || selectedNode instanceof DockedShape || selectedNode instanceof LabelNode) {
newDiagramElementToSelectedNodeOverlayMapBuilder.put(selectedDiagramElement, new SelectedShapeOverlay(this, selectedDiagramElement, selectedNode, primary));
} else if (selectedNode instanceof BaseConnectionNode) {
// Create overlay for connection nodes
newDiagramElementToSelectedNodeOverlayMapBuilder.put(selectedDiagramElement, new SelectedConnectionOverlay(this, selectedDiagramElement, (BaseConnectionNode) selectedNode, primary));
}
}
}
}
diagramElementToSelectedNodeOverlayMap = newDiagramElementToSelectedNodeOverlayMapBuilder.build();
// Update children to reflect the new nodes.
selectionOverlays.getChildren().setAll((Collection<? extends Node>) diagramElementToSelectedNodeOverlayMap.values());
});
}
Aggregations