use of org.osate.ge.palette.GetTargetedOperationContext 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.palette.GetTargetedOperationContext 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.palette.GetTargetedOperationContext 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();
});
});
});
}
use of org.osate.ge.palette.GetTargetedOperationContext in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final Object bo = ctx.getTarget().getBusinessObject();
if (bo instanceof Feature) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the feature in the context of the EMV subclause. This is needed for reliable serialization.
final List<URI> path = ErrorModelGeUtil.createQualifiedPropagationPointPath(ctx.getTarget(), ErrorModelGeUtil.getClassifierSourceBoc(ctx.getTarget()).get(), new ArrayList<>());
newPropagation.setFeatureorPPRef(buildFeatureReference(subclause.eResource().getResourceSet(), path));
});
} else if (bo instanceof KeywordPropagationPoint) {
final KeywordPropagationPoint kw = (KeywordPropagationPoint) bo;
if (kw.getType() != KeywordPropagationPointType.ALL) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> newPropagation.setKind(kw.getType().getKind()));
}
} else if (bo instanceof PropagationPoint) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the propagation in the context of the EMV subclause.
// Check inherited subclauses as well. This is needed for reliable serialization.
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
final String boName = ((PropagationPoint) bo).getName();
final PropagationPoint pp = combined.getPoints().filter(p -> Objects.equal(p.getName(), boName)).findAny().orElseThrow(() -> new AadlGraphicalEditorException("Unable to find propagation point"));
final FeatureorPPReference ppRef = ErrorModelFactory.eINSTANCE.createFeatureorPPReference();
ppRef.setFeatureorPP(pp);
newPropagation.setFeatureorPPRef(ppRef);
});
}
return Optional.empty();
}
use of org.osate.ge.palette.GetTargetedOperationContext in project osate2 by osate.
the class CreateStatePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(ba -> Operation.createSimple(ctx.getTarget(), BehaviorAnnex.class, baToModify -> {
// Create the state
final BehaviorState newState = (BehaviorState) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorState());
final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(baToModify, "new_state");
newState.setName(newName);
// Add the new state to the behavior annex
baToModify.getStates().add(newState);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newState).build();
})).orElse(Optional.empty());
}
Aggregations