Search in sources :

Example 1 with OperationExecutor

use of org.osate.ge.internal.operations.OperationExecutor in project osate2 by osate.

the class PropertySectionUtil method execute.

/**
 * Executes an operation in a context which is not associated with a diagram.
 * As such, elements are not added to the diagram based on the hints provided by the step results.
 * @param operation the operation to execute.
 */
public static void execute(final Operation operation) {
    if (operation != null) {
        final Bundle bundle = FrameworkUtil.getBundle(PropertySectionUtil.class);
        final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
        final AadlModificationService aadlModService = Objects.requireNonNull(context.getActive(AadlModificationService.class), "Unable to retrieve AADL modification service");
        final ReferenceBuilderService referenceBuilder = Objects.requireNonNull(context.getActive(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
        final OperationExecutor operationExecutor = new OperationExecutor(aadlModService, referenceBuilder);
        operationExecutor.execute(operation);
    }
}
Also used : AadlModificationService(org.osate.ge.internal.services.AadlModificationService) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Bundle(org.osgi.framework.Bundle) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor)

Example 2 with OperationExecutor

use of org.osate.ge.internal.operations.OperationExecutor 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 3 with OperationExecutor

use of org.osate.ge.internal.operations.OperationExecutor 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 4 with OperationExecutor

use of org.osate.ge.internal.operations.OperationExecutor in project osate2 by osate.

the class OperationTest method testSplit.

@Test
public void testSplit() {
    DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    b.map(pr -> StepResultBuilder.create(pr + 2).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create(prevResult + 1).build();
    }).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 2).build();
    });
    b.map(pr -> StepResultBuilder.create(pr + 6).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 3).build();
    });
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    final OperationResults results = executor.execute(firstStep);
    // Verify that results were created from both paths
    final ImmutableSet<Integer> expectedBosToShow = ImmutableSet.of(6, 10);
    final Set<?> bosToShow = results.getContainerToBoToShowDetailsMap().values().stream().map(v -> v.bo).collect(Collectors.toSet());
    assertEquals(expectedBosToShow, bosToShow);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Example 5 with OperationExecutor

use of org.osate.ge.internal.operations.OperationExecutor in project osate2 by osate.

the class OperationTest method testSequential.

/**
 * Tests a simple sequential modification
 */
@Test
public void testSequential() {
    DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    b.map(pr -> StepResultBuilder.create(pr + 2).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create(prevResult + 1).build();
    }).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 2).build();
    });
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    final OperationResults results = executor.execute(firstStep);
    // Verify that result was created.
    final ImmutableSet<Integer> expectedBosToShow = ImmutableSet.of(6);
    final Set<?> bosToShow = results.getContainerToBoToShowDetailsMap().values().stream().map(v -> v.bo).collect(Collectors.toSet());
    assertEquals(expectedBosToShow, bosToShow);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Aggregations

OperationExecutor (org.osate.ge.internal.operations.OperationExecutor)9 AadlModificationService (org.osate.ge.internal.services.AadlModificationService)7 ReferenceBuilderService (org.osate.ge.services.ReferenceBuilderService)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Collection (java.util.Collection)6 Collections (java.util.Collections)6 List (java.util.List)6 Set (java.util.Set)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Collectors (java.util.stream.Collectors)6 EObject (org.eclipse.emf.ecore.EObject)6 Assert (org.junit.Assert)6 Test (org.junit.Test)6 BusinessObjectContext (org.osate.ge.BusinessObjectContext)6 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)6 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)6 Point (org.osate.ge.diagram.Point)6 DefaultOperationBuilder (org.osate.ge.internal.operations.DefaultOperationBuilder)6 OperationResults (org.osate.ge.internal.operations.OperationResults)6 Step (org.osate.ge.internal.operations.Step)6