Search in sources :

Example 1 with Operation

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);
            }));
        });
    });
}
Also used : DefaultCreateSelectClassifierDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel) StepResult(org.osate.ge.operations.StepResult) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ClassifierOperationDialog(org.osate.ge.aadl2.ui.internal.dialogs.ClassifierOperationDialog) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) IProject(org.eclipse.core.resources.IProject) EClass(org.eclipse.emf.ecore.EClass) Classifier(org.osate.aadl2.Classifier) ImmutableList(com.google.common.collect.ImmutableList) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) Aadl2Package(org.osate.aadl2.Aadl2Package) EnumSet(java.util.EnumSet) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ClassifierOperationPartType(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) Operation(org.osate.ge.operations.Operation) Collection(java.util.Collection) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) Display(org.eclipse.swt.widgets.Display) ProjectUtil(org.osate.ge.ProjectUtil) QueryService(org.osate.ge.services.QueryService) ComponentCategory(org.osate.aadl2.ComponentCategory) StringUtil(org.osate.ge.StringUtil) AadlCategories(org.osate.ge.aadl2.AadlCategories) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ClassifierOperationPart(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPart) ExecutableQuery(org.osate.ge.query.ExecutableQuery) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) AadlPackage(org.osate.aadl2.AadlPackage) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) EObject(org.eclipse.emf.ecore.EObject) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IProject(org.eclipse.core.resources.IProject)

Example 2 with Operation

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();
    }));
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectAndExtra(org.osate.ge.operations.BusinessObjectAndExtra) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger) ComponentClassifier(org.osate.aadl2.ComponentClassifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) ModeTransition(org.osate.aadl2.ModeTransition) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) ModeTransitionTriggerSelectionDialog(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog) Operation(org.osate.ge.operations.Operation) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) QueryService(org.osate.ge.services.QueryService) AadlCategories(org.osate.ge.aadl2.AadlCategories) ModeTransitionTriggerInfo(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ExecutableQuery(org.osate.ge.query.ExecutableQuery) Collections(java.util.Collections) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Mode(org.osate.aadl2.Mode) BusinessObjectAndExtra(org.osate.ge.operations.BusinessObjectAndExtra) ModeTransition(org.osate.aadl2.ModeTransition) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ModeTransitionTriggerInfo(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 3 with Operation

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

Example 4 with Operation

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());
}
Also used : BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorState(org.osate.ba.aadlba.BehaviorState) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) QueryService(org.osate.ge.services.QueryService) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) Optional(java.util.Optional) ExecutableQuery(org.osate.ge.query.ExecutableQuery) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) BehaviorState(org.osate.ba.aadlba.BehaviorState) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Example 5 with Operation

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();
            });
        });
    });
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorAnnexUtil.getPackage(org.osate.ge.ba.util.BehaviorAnnexUtil.getPackage) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorAnnexUtil(org.osate.ge.ba.util.BehaviorAnnexUtil) Optional(java.util.Optional) OperationBuilder(org.osate.ge.operations.OperationBuilder) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) DataClassifier(org.osate.aadl2.DataClassifier) StepResult(org.osate.ge.operations.StepResult)

Aggregations

Optional (java.util.Optional)13 Operation (org.osate.ge.operations.Operation)13 BasePaletteCommand (org.osate.ge.palette.BasePaletteCommand)12 BusinessObjectContext (org.osate.ge.BusinessObjectContext)11 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)11 List (java.util.List)6 CanStartConnectionContext (org.osate.ge.palette.CanStartConnectionContext)6 URI (org.eclipse.emf.common.util.URI)5 EObject (org.eclipse.emf.ecore.EObject)5 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)5 Display (org.eclipse.swt.widgets.Display)5 AadlPackage (org.osate.aadl2.AadlPackage)5 AadlGraphicalEditorException (org.osate.ge.aadl2.AadlGraphicalEditorException)5 StepResult (org.osate.ge.operations.StepResult)5 CreateConnectionPaletteCommand (org.osate.ge.palette.CreateConnectionPaletteCommand)5 GetCreateConnectionOperationContext (org.osate.ge.palette.GetCreateConnectionOperationContext)5 GetTargetedOperationContext (org.osate.ge.palette.GetTargetedOperationContext)5 TargetedPaletteCommand (org.osate.ge.palette.TargetedPaletteCommand)5 ErrorModelFactory (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4