use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateClassifierPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(EObject.class).map(targetBo -> {
if (!(targetBo instanceof AadlPackage || isValidBaseClassifier(targetBo))) {
return null;
}
final BusinessObjectContext pkgBoc = getPackageBoc(ctx.getTarget(), ctx.getQueryService());
if (pkgBoc == null) {
return null;
}
final AadlPackage pkg = (AadlPackage) pkgBoc.getBusinessObject();
final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
final ResourceSet rs = targetBo.eResource().getResourceSet();
return Operation.createWithBuilder(builder -> {
builder.supply(() -> {
final ClassifierOperation args = buildCreateOperations(pkg, targetBo, project, rs);
if (args == null) {
return StepResult.abort();
}
return StepResult.forValue(args);
}).executeOperation(classifierOp -> Operation.createWithBuilder(innerBuilder -> {
final ClassifierOperationExecutor opExec = new ClassifierOperationExecutor(rs, project);
opExec.execute(innerBuilder, classifierOp, pkgBoc);
}));
});
});
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateModeTransitionPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
if (!ctx.getDestination().getBusinessObject(Mode.class).isPresent()) {
return Optional.empty();
}
final List<ComponentClassifier> potentialOwners = getPotentialOwners(ctx.getSource(), ctx.getDestination(), ctx.getQueryService());
if (potentialOwners.size() == 0) {
return Optional.empty();
}
final BusinessObjectContext container = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
if (container == null) {
return Optional.empty();
}
final Mode srcMode = ctx.getSource().getBusinessObject(Mode.class).get();
final Mode dstMode = ctx.getDestination().getBusinessObject(Mode.class).get();
return Optional.of(Operation.createPromptAndModifyWithExtra(() -> {
// Determine which classifier should own the new element
final ComponentClassifier selectedClassifier = AadlUiUtil.getBusinessObjectToModify(potentialOwners);
if (selectedClassifier == null) {
return Optional.empty();
}
// Prompt for transition triggers
final ModeTransitionTriggerInfo[] selectedTriggers = ModeTransitionTriggerSelectionDialog.promptForTriggers(selectedClassifier, null);
if (selectedTriggers == null) {
return Optional.empty();
}
return Optional.of(new BusinessObjectAndExtra<>(selectedClassifier, selectedTriggers));
}, args -> {
final ComponentClassifier cc = args.getBusinessObject();
// Determine the name for the new mode transition
final String newElementName = AadlNamingUtil.buildUniqueIdentifier(cc, "new_transition");
// Create the new mode transition
final ModeTransition newModeTransition = cc.createOwnedModeTransition();
// Clear the no modes flag
cc.setNoModes(false);
// Set the name
newModeTransition.setName(newElementName);
// Set the source and destination
newModeTransition.setSource(srcMode);
newModeTransition.setDestination(dstMode);
// Create Triggers
for (ModeTransitionTriggerInfo selectedPort : args.getExtra()) {
final ModeTransitionTrigger mtt = newModeTransition.createOwnedTrigger();
mtt.setTriggerPort(selectedPort.port);
mtt.setContext(selectedPort.context);
}
return StepResultBuilder.create().showNewBusinessObject(container, newModeTransition).build();
}));
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateSubprogramCallSequencePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final BusinessObjectContext targetBoc = ctx.getTarget();
final Object targetBo = targetBoc.getBusinessObject();
if (!getClassifierOpBuilder().canBuildOperation(targetBo)) {
return Optional.empty();
}
// Used to pass arguments between steps
class CreateArgs {
final BehavioredImplementation bi;
final CallContext callContext;
final CalledSubprogram calledSubprogram;
public CreateArgs(final BehavioredImplementation bi, final CallContext callContext, final CalledSubprogram calledSubprogram) {
this.bi = bi;
this.callContext = callContext;
this.calledSubprogram = calledSubprogram;
}
}
return Optional.of(Operation.createWithBuilder(createOp -> {
getClassifierOpBuilder().buildOperation(createOp, targetBo).map(ci -> {
final BehavioredImplementation bi = (BehavioredImplementation) ci;
final DefaultSelectSubprogramDialogModel subprogramSelectionModel = new DefaultSelectSubprogramDialogModel(bi);
final SelectSubprogramDialog dlg = new SelectSubprogramDialog(Display.getCurrent().getActiveShell(), subprogramSelectionModel);
if (dlg.open() == Window.CANCEL) {
return StepResult.abort();
}
// Get the CallContext and Called Subprogram
final CallContext callContext = subprogramSelectionModel.getCallContext(dlg.getSelectedContext());
final CalledSubprogram calledSubprogram = subprogramSelectionModel.getCalledSubprogram(dlg.getSelectedSubprogram());
return StepResult.forValue(new CreateArgs(bi, callContext, calledSubprogram));
}).modifyModel(null, (tag, createArgs) -> createArgs.bi, (tag, bi, createArgs) -> {
final String newScsName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call_sequence");
final String initialSubprogramCallName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call");
final SubprogramCallSequence newScs = bi.createOwnedSubprogramCallSequence();
newScs.setName(newScsName);
// Create an initial call. Needed because call sequences must have at least one call
final SubprogramCall initialSubprogramCall = newScs.createOwnedSubprogramCall();
initialSubprogramCall.setName(initialSubprogramCallName);
initialSubprogramCall.setContext(createArgs.callContext);
initialSubprogramCall.setCalledSubprogram(createArgs.calledSubprogram);
AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.callContext);
AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.calledSubprogram);
return StepResultBuilder.create().showNewBusinessObject(targetBoc, newScs).build();
});
}));
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateTransitionPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
if (!ctx.getDestination().getBusinessObject(BehaviorState.class).isPresent()) {
return Optional.empty();
}
final BusinessObjectContext srcContainer = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
if (srcContainer == null) {
return Optional.empty();
}
final BusinessObjectContext dstContainer = getOwnerBoc(ctx.getDestination(), ctx.getQueryService());
if (dstContainer != srcContainer) {
return Optional.empty();
}
final BehaviorState srcState = ctx.getSource().getBusinessObject(BehaviorState.class).orElseThrow();
final BehaviorState dstState = ctx.getDestination().getBusinessObject(BehaviorState.class).orElseThrow();
return srcContainer.getBusinessObject(BehaviorAnnex.class).map(ba -> Operation.createSimple(srcContainer, BehaviorAnnex.class, boToModify -> {
final BehaviorTransition baTransition = (BehaviorTransition) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorTransition());
final String srcName = srcState.getName();
final String dstName = dstState.getName();
if (srcName == null || dstName == null) {
return StepResultBuilder.create().abort().build();
}
// Set source and destination for transition
for (final BehaviorState behaviorState : boToModify.getStates()) {
final String name = behaviorState.getName();
if (srcName.equalsIgnoreCase(name)) {
// Source
baTransition.setSourceState(behaviorState);
}
if (dstName.equalsIgnoreCase(name)) {
// Destination
baTransition.setDestinationState(behaviorState);
}
}
// Add new transition
boToModify.getTransitions().add(baTransition);
final String name = getTransitionName(baTransition);
baTransition.setName(name);
// Show
return StepResultBuilder.create().showNewBusinessObject(srcContainer, baTransition).build();
})).orElse(Optional.empty());
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateVariablePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
if (section == null) {
return null;
}
return Operation.createWithBuilder(builder -> {
final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
return StepResult.forValue(dataClassifier);
});
addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
newVariable.setName(newName);
newVariable.setDataClassifier(prevResult);
behaviorAnnexToModify.getVariables().add(newVariable);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
});
});
});
}
Aggregations