Search in sources :

Example 1 with GetTargetedOperationContext

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

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

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

Example 4 with GetTargetedOperationContext

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();
}
Also used : URI(org.eclipse.emf.common.util.URI) Feature(org.osate.aadl2.Feature) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) PropagationTreeUtil(org.osate.ge.errormodel.combined.PropagationTreeUtil) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) ErrorModelUiUtil(org.osate.ge.errormodel.ui.ErrorModelUiUtil) BiConsumer(java.util.function.BiConsumer) DirectionType(org.osate.aadl2.DirectionType) Objects(com.google.common.base.Objects) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) Operation(org.osate.ge.operations.Operation) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Display(org.eclipse.swt.widgets.Display) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PropagationNode(org.osate.ge.errormodel.combined.PropagationNode) StringUtil(org.osate.ge.StringUtil) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) EObject(org.eclipse.emf.ecore.EObject) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) Feature(org.osate.aadl2.Feature) URI(org.eclipse.emf.common.util.URI) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference)

Example 5 with GetTargetedOperationContext

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());
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) BehaviorState(org.osate.ba.aadlba.BehaviorState) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Optional(java.util.Optional) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) BehaviorState(org.osate.ba.aadlba.BehaviorState)

Aggregations

GetTargetedOperationContext (org.osate.ge.palette.GetTargetedOperationContext)6 Optional (java.util.Optional)5 Operation (org.osate.ge.operations.Operation)5 BasePaletteCommand (org.osate.ge.palette.BasePaletteCommand)5 TargetedPaletteCommand (org.osate.ge.palette.TargetedPaletteCommand)5 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)4 Display (org.eclipse.swt.widgets.Display)3 AadlPackage (org.osate.aadl2.AadlPackage)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 StepResult (org.osate.ge.operations.StepResult)3 EObject (org.eclipse.emf.ecore.EObject)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)2 Aadl2Package (org.osate.aadl2.Aadl2Package)2 StringUtil (org.osate.ge.StringUtil)2 AadlCategories (org.osate.ge.aadl2.AadlCategories)2 AadlImportsUtil (org.osate.ge.aadl2.AadlImportsUtil)2 AadlImages (org.osate.ge.aadl2.internal.AadlImages)2 AadlNamingUtil (org.osate.ge.aadl2.internal.AadlNamingUtil)2 Objects (com.google.common.base.Objects)1