Search in sources :

Example 6 with DockedShape

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());
    });
}
Also used : LabelNode(org.osate.ge.gef.LabelNode) LabelNode(org.osate.ge.gef.LabelNode) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Node(javafx.scene.Node) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) DockedShape(org.osate.ge.gef.DockedShape) ImmutableMap(com.google.common.collect.ImmutableMap) Point(org.eclipse.gef.geometry.planar.Point) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ContainerShape(org.osate.ge.gef.ContainerShape) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode)

Aggregations

Node (javafx.scene.Node)6 ContainerShape (org.osate.ge.gef.ContainerShape)6 DockedShape (org.osate.ge.gef.DockedShape)6 BaseConnectionNode (org.osate.ge.gef.BaseConnectionNode)5 FlowIndicatorNode (org.osate.ge.gef.FlowIndicatorNode)5 LabelNode (org.osate.ge.gef.LabelNode)5 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 ConnectionNode (org.osate.ge.gef.ConnectionNode)4 DockSide (org.osate.ge.gef.DockSide)4 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)4 Bounds (javafx.geometry.Bounds)3 Point2D (javafx.geometry.Point2D)3 DiagramRootNode (org.osate.ge.gef.DiagramRootNode)3 FeatureGroupNode (org.osate.ge.gef.FeatureGroupNode)3 Transform (javafx.scene.transform.Transform)2 Dimension (org.osate.ge.graphics.Dimension)2 Point (org.osate.ge.graphics.Point)2 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Group (javafx.scene.Group)1