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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations