Search in sources :

Example 1 with SelectSubprogramDialog

use of org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog 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();
        });
    }));
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) AadlOperationBuilder(org.osate.ge.aadl2.ui.AadlOperationBuilder) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) ComponentImplementation(org.osate.aadl2.ComponentImplementation) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Display(org.eclipse.swt.widgets.Display) CalledSubprogram(org.osate.aadl2.CalledSubprogram) Window(org.eclipse.jface.window.Window) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) AadlCategories(org.osate.ge.aadl2.AadlCategories) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) CallContext(org.osate.aadl2.CallContext) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCall(org.osate.aadl2.SubprogramCall) Aadl2Package(org.osate.aadl2.Aadl2Package) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) BusinessObjectContext(org.osate.ge.BusinessObjectContext) CallContext(org.osate.aadl2.CallContext) CalledSubprogram(org.osate.aadl2.CalledSubprogram) SubprogramCall(org.osate.aadl2.SubprogramCall) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog)

Aggregations

Optional (java.util.Optional)1 Window (org.eclipse.jface.window.Window)1 Display (org.eclipse.swt.widgets.Display)1 Aadl2Package (org.osate.aadl2.Aadl2Package)1 BehavioredImplementation (org.osate.aadl2.BehavioredImplementation)1 CallContext (org.osate.aadl2.CallContext)1 CalledSubprogram (org.osate.aadl2.CalledSubprogram)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 SubprogramCall (org.osate.aadl2.SubprogramCall)1 SubprogramCallSequence (org.osate.aadl2.SubprogramCallSequence)1 BusinessObjectContext (org.osate.ge.BusinessObjectContext)1 AadlCategories (org.osate.ge.aadl2.AadlCategories)1 AadlImportsUtil (org.osate.ge.aadl2.AadlImportsUtil)1 AadlImages (org.osate.ge.aadl2.internal.AadlImages)1 AadlNamingUtil (org.osate.ge.aadl2.internal.AadlNamingUtil)1 AadlOperationBuilder (org.osate.ge.aadl2.ui.AadlOperationBuilder)1 DefaultSelectSubprogramDialogModel (org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel)1 SelectSubprogramDialog (org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog)1 Operation (org.osate.ge.operations.Operation)1 StepResult (org.osate.ge.operations.StepResult)1