Search in sources :

Example 6 with DiagramNode

use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.

the class CreateConnectionInteraction method handleEvent.

@Override
public HandledEvent handleEvent(final InputEvent e) {
    if (e.getEventType() != MouseEvent.MOUSE_PRESSED) {
        return null;
    }
    // Retrieve the active palette command
    final PaletteCommand cmd = editor.getPaletteModel().getActivePaletteCommand();
    if (cmd == null) {
        return null;
    }
    final MouseEvent me = (MouseEvent) e;
    if (me.getButton() == MouseButton.PRIMARY) {
        if (cmd instanceof TargetedPaletteCommand) {
            final TargetedPaletteCommand tc = (TargetedPaletteCommand) cmd;
            createGetTargetedOperationContext((MouseEvent) e).ifPresent(c -> {
                final Node sceneNode = editor.getSceneNode((DiagramNode) c.getTarget());
                final Point2D p = getTargetPosition(sceneNode, me.getSceneX(), me.getSceneY());
                class CreateAction implements AgeAction {

                    @Override
                    public AgeAction execute() {
                        final DiagramNode targetNode = (DiagramNode) c.getTarget();
                        tc.getOperation(c).ifPresent(operation -> {
                            // Perform modification
                            final OperationExecutor opExecutor = new OperationExecutor(editor.getAadlModificationService(), editor.getReferenceService());
                            OperationResultsProcessor.processResults(editor, targetNode, GefAgeDiagramUtil.toAgePoint(p), opExecutor.execute(operation));
                        });
                        return null;
                    }
                }
                final CreateAction createAction = new CreateAction();
                editor.getActionExecutor().execute("Create " + cmd.getLabel(), ExecutionMode.NORMAL, createAction);
                // Deactivate the current palette item and select the "Select" item
                editor.getPaletteModel().deactivateNonSelectItem();
            });
            return HandledEvent.consumed();
        } else if (cmd instanceof CreateConnectionPaletteCommand) {
            final CreateConnectionPaletteCommand createCmd = (CreateConnectionPaletteCommand) cmd;
            final CanStartConnectionContext ctx = createCanStartConnectionContext(me).orElse(null);
            if (ctx == null || !createCmd.canStartConnection(ctx)) {
                return null;
            }
            return HandledEvent.newInteraction(new CreateConnectionInteraction(createCmd, (DiagramElement) ctx.getSource(), editor, me));
        }
    } else if (me.getButton() == MouseButton.SECONDARY) {
        editor.getPaletteModel().deactivateNonSelectItem();
    }
    return null;
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) MouseEvent(javafx.scene.input.MouseEvent) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) Point2D(javafx.geometry.Point2D) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) AgeAction(org.osate.ge.internal.services.AgeAction) GeometryNode(org.eclipse.gef.fx.nodes.GeometryNode) Node(javafx.scene.Node) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) PaletteCommand(org.osate.ge.palette.PaletteCommand) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand)

Example 7 with DiagramNode

use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.

the class GefAgeDiagram method updateDiagramFromSceneGraph.

/**
 * Triggers a layout of the scene graph nodes and then updates the diagram based on the layout of the scene graph nodes.
 * Updates position and size. Optionally updates bendpoints.
 * Should only be called after the root node has been added to a scene.
 * @param updateBendpoints whether to update bendpoints in addition to the position and size of elements.
 */
public void updateDiagramFromSceneGraph(final boolean updateBendpoints) {
    updatingDiagramFromSceneGraph = true;
    forceSceneGraphLayout();
    diagram.modify("Update Diagram from Scene Graph", m -> {
        for (final Entry<DiagramElement, GefDiagramElement> e : this.diagramElementToGefDiagramElementMap.entrySet()) {
            final DiagramElement de = e.getKey();
            final GefDiagramElement ge = e.getValue();
            final Node sceneNode = ge.sceneNode;
            final DiagramNode parent = de.getParent();
            if (DiagramElementPredicates.isMoveable(de)) {
                if (parent instanceof DiagramElement && DiagramElementPredicates.isConnection((DiagramElement) parent)) {
                    // Store the preferred position.
                    final Point2D p = PreferredPosition.get(sceneNode);
                    m.setPosition(de, GefAgeDiagramUtil.toAgePoint(p));
                } else {
                    final double newX = sceneNode.getLayoutX();
                    final double newY = sceneNode.getLayoutY();
                    if (de.hasPosition() || (newX != 0.0 || newY != 0)) {
                        m.setPosition(de, new Point(newX, newY));
                    }
                }
                if (sceneNode instanceof DockedShape && ge.parentDiagramNodeSceneNode instanceof ContainerShape) {
                    final DockedShape ds = (DockedShape) sceneNode;
                    final DockSide side = ds.getSide();
                    if (side != null) {
                        m.setDockArea(de, GefAgeDiagramUtil.toDockArea(side));
                    }
                }
            }
            // Set the size for all elements. Even for non-resizable elements, the layout engine uses the sizes in the diagram.
            // This is important for secondary labels of connections.
            final Bounds layoutBounds = sceneNode.getLayoutBounds();
            if (de.hasSize() || (layoutBounds.getWidth() != 0.0 || layoutBounds.getHeight() != 0)) {
                m.setSize(de, new Dimension(layoutBounds.getWidth(), layoutBounds.getHeight()));
            }
            if (DiagramElementPredicates.isConnection(de) && sceneNode instanceof BaseConnectionNode) {
                final BaseConnectionNode cn = (BaseConnectionNode) sceneNode;
                // Primary label position
                if (!cn.getPrimaryLabels().isEmpty()) {
                    // Store the preferred position of the connection label
                    final Node primaryLabel = cn.getPrimaryLabels().get(0);
                    final Point2D p = PreferredPosition.get(primaryLabel);
                    m.setConnectionPrimaryLabelPosition(de, GefAgeDiagramUtil.toAgePoint(p));
                }
                // Bendpoints
                if (updateBendpoints) {
                    final List<org.eclipse.gef.geometry.planar.Point> controlPoints = cn.getInnerConnection().getControlPoints();
                    if (!controlPoints.isEmpty() || !de.getBendpoints().isEmpty()) {
                        final Point controlPointOrigin = getControlPointOriginFromSceneGraph(sceneNode);
                        m.setBendpoints(de, cn.getInnerConnection().getControlPoints().stream().map(p -> new Point(p.x + controlPointOrigin.x, p.y + controlPointOrigin.y)).collect(Collectors.toList()));
                    }
                }
            }
        }
    });
    updatingDiagramFromSceneGraph = false;
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramRootNode(org.osate.ge.gef.DiagramRootNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) FeatureGroupNode(org.osate.ge.gef.FeatureGroupNode) LabelNode(org.osate.ge.gef.LabelNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) DockedShape(org.osate.ge.gef.DockedShape) Bounds(javafx.geometry.Bounds) Point(org.osate.ge.graphics.Point) Dimension(org.osate.ge.graphics.Dimension) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DockSide(org.osate.ge.gef.DockSide) Point2D(javafx.geometry.Point2D) ContainerShape(org.osate.ge.gef.ContainerShape) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode)

Example 8 with DiagramNode

use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.

the class GefDiagramExportService method getExportNodes.

/**
 * Returns a list of nodes to export. The nodes will be in draw order.
 * @param diagram the diagram being export
 * @param exportRootDiagramNode the root node being exported.
 * @return the list of nodes to export.
 */
private static List<Node> getExportNodes(final GefAgeDiagram diagram, final DiagramNode exportRootDiagramNode) {
    // final GefAgeDiagram diagram,
    final Node exportRootSceneNode = diagram.getSceneNode(exportRootDiagramNode);
    if (exportRootSceneNode == null) {
        throw new AgeGefRuntimeException("Unable to find scene node for specified diagram node");
    }
    final List<Node> exportNodes = new ArrayList<>();
    addNonConnectionExportNodes(exportRootSceneNode, exportNodes);
    addConnectionExportNodes(diagram.getSceneNode(), exportRootSceneNode, exportNodes);
    return exportNodes;
}
Also used : BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Example 9 with DiagramNode

use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.

the class DiagramElementReference method addReferenceToBuilder.

private static void addReferenceToBuilder(final ImmutableList.Builder<RelativeBusinessObjectReference> builder, final DiagramElement element) {
    if (element != null) {
        final DiagramNode parent = element.getParent();
        if (parent instanceof DiagramElement) {
            addReferenceToBuilder(builder, (DiagramElement) parent);
        }
        builder.add(element.getRelativeReference());
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode)

Example 10 with DiagramNode

use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.

the class OperationResultsProcessor method processResults.

/**
 * @param editor the editor which is displaying the diagram for which the operation was executed
 * @param targetNode is the node to which the targetPosition is relative.
 * @param targetPosition the position at which the operation was executed. Relative to the target node. This is used to position
 * a newly created diagram element.
 * @param results the results to process
 */
public static void processResults(final InternalDiagramEditor editor, final DiagramNode targetNode, final Point targetPosition, final OperationResults results) {
    Objects.requireNonNull(editor, "diagram must not be null");
    boolean update = false;
    // Notify the diagram updater to add the element on the next update
    for (final Entry<BusinessObjectContext, OperationResults.BusinessObjectToShowDetails> containerToBoEntry : results.getContainerToBoToShowDetailsMap().entries()) {
        if (containerToBoEntry.getKey() instanceof DiagramNode) {
            final DiagramNode containerNode = (DiagramNode) containerToBoEntry.getKey();
            final OperationResults.BusinessObjectToShowDetails newValue = containerToBoEntry.getValue();
            // Don't set the position if multiple items are being added.
            // Don't set the position if the incremental layout mode is set to diagram.
            // This will ensure the shape is laid out even if it is a docked shape.
            final Point position;
            if (results.getContainerToBoToShowDetailsMap().size() == 1 && LayoutPreferences.getCurrentIncrementalLayoutMode() != IncrementalLayoutMode.LAYOUT_DIAGRAM && containerNode == targetNode) {
                position = targetPosition;
            } else {
                position = null;
            }
            // If the BO being added is an embedded business object, it must be provided to the diagram updater.
            final EmbeddedBusinessObject embeddedBo = (newValue.bo instanceof EmbeddedBusinessObject) ? (EmbeddedBusinessObject) newValue.bo : null;
            editor.getDiagramUpdater().addToNextUpdate(containerNode, newValue.ref, new FutureElementInfo(position, embeddedBo));
            if (embeddedBo != null) {
                update = true;
            }
        }
    }
    // If an embedded business object was added, then update the diagram to ensure it was updated.
    if (update) {
        editor.updateDiagram();
    }
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) FutureElementInfo(org.osate.ge.internal.diagram.runtime.updating.FutureElementInfo) OperationResults(org.osate.ge.internal.operations.OperationResults) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)29 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)18 List (java.util.List)13 Point (org.osate.ge.graphics.Point)13 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)13 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)13 Objects (java.util.Objects)12 IEditorPart (org.eclipse.ui.IEditorPart)11 Collection (java.util.Collection)10 Collections (java.util.Collections)10 BusinessObjectContext (org.osate.ge.BusinessObjectContext)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 DiagramModification (org.osate.ge.internal.diagram.runtime.DiagramModification)8 Stream (java.util.stream.Stream)7 Node (javafx.scene.Node)7 IStatus (org.eclipse.core.runtime.IStatus)7 Status (org.eclipse.core.runtime.Status)7 DiagramNodePredicates (org.osate.ge.internal.diagram.runtime.DiagramNodePredicates)7 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)7