use of org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel 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();
});
}));
}
Aggregations