Search in sources :

Example 1 with AgeAction

use of org.osate.ge.internal.services.AgeAction 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 2 with AgeAction

use of org.osate.ge.internal.services.AgeAction in project osate2 by osate.

the class CreateConnectionInteraction method onMousePressed.

@Override
protected Interaction.InteractionState onMousePressed(final MouseEvent e) {
    if (e.getButton() != MouseButton.PRIMARY || InputEventHandlerUtil.isScrollBar(e.getTarget())) {
        return super.onMousePressed(e);
    }
    // Get and execute the operation for creating the connection
    createGetCreateConnectionOperationContext(e).ifPresent(c -> {
        class CreateAction implements AgeAction {

            @Override
            public AgeAction execute() {
                cmd.getOperation(c).ifPresent(operation -> {
                    // Perform modification
                    final OperationExecutor opExecutor = new OperationExecutor(editor.getAadlModificationService(), editor.getReferenceService());
                    OperationResultsProcessor.processResults(editor, opExecutor.execute(operation));
                });
                return null;
            }
        }
        final CreateAction createAction = new CreateAction();
        editor.getActionExecutor().execute("Create " + cmd.getLabel(), ExecutionMode.NORMAL, createAction);
    });
    return InteractionState.COMPLETE;
}
Also used : AgeAction(org.osate.ge.internal.services.AgeAction) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor)

Example 3 with AgeAction

use of org.osate.ge.internal.services.AgeAction in project osate2 by osate.

the class DefaultAadlModificationService method performModifications.

// Assumes that the modification notifier is already locked
private void performModifications(final List<? extends Modification<?, ?>> modifications, final ModificationPostprocessor postProcessor) {
    class ModificationAction implements AgeAction {

        @Override
        public boolean canExecute() {
            return true;
        }

        @Override
        public AgeAction execute() {
            try (Lock lock = modelChangeNotifier.lock()) {
                final Set<IProject> projectsToBuild = new HashSet<>();
                boolean allSuccessful = true;
                final List<ModificationResult> modificationResults = new ArrayList<>();
                // Iterate over the input objects
                for (final Modification<?, ?> modification : modifications) {
                    final ModificationResult modificationResult = performModification(modification, projectsToBuild);
                    allSuccessful = modificationResult.modificationSuccessful;
                    if (!allSuccessful) {
                        break;
                    }
                    modificationResults.add(modificationResult);
                }
                // Build projects before unlocking. This will cause the post build notifications to be sent out before the lock is released.
                // This is desired to avoid multiple diagram updates for the same change.
                buildProjects(projectsToBuild);
                if (postProcessor != null) {
                    postProcessor.modificationCompleted(allSuccessful);
                }
                return modificationResults.isEmpty() ? null : new UndoAction(modificationResults);
            }
        }
    }
    actionService.execute("Modify Model", ActionExecutor.ExecutionMode.NORMAL, new ModificationAction());
}
Also used : AgeAction(org.osate.ge.internal.services.AgeAction) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) Lock(org.osate.ge.internal.services.ModelChangeNotifier.Lock) HashSet(java.util.HashSet)

Aggregations

AgeAction (org.osate.ge.internal.services.AgeAction)3 OperationExecutor (org.osate.ge.internal.operations.OperationExecutor)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Point2D (javafx.geometry.Point2D)1 Node (javafx.scene.Node)1 MouseEvent (javafx.scene.input.MouseEvent)1 IProject (org.eclipse.core.resources.IProject)1 GeometryNode (org.eclipse.gef.fx.nodes.GeometryNode)1 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)1 Lock (org.osate.ge.internal.services.ModelChangeNotifier.Lock)1 CanStartConnectionContext (org.osate.ge.palette.CanStartConnectionContext)1 CreateConnectionPaletteCommand (org.osate.ge.palette.CreateConnectionPaletteCommand)1 PaletteCommand (org.osate.ge.palette.PaletteCommand)1 TargetedPaletteCommand (org.osate.ge.palette.TargetedPaletteCommand)1