Search in sources :

Example 1 with BehaviorAnnex

use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.

the class CreateSpecificationPaletteCommand method createBehaviorAnnex.

private static BehaviorAnnex createBehaviorAnnex(final Classifier c) {
    final String name = BehaviorAnnexReferenceUtil.ANNEX_NAME;
    final BehaviorAnnex ba = GraphicalAnnexUtil.createParsedAnnexSubclause(c, name, AadlBaPackage.eINSTANCE.getBehaviorAnnex(), BehaviorAnnex.class);
    ba.setName(name);
    return ba;
}
Also used : BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex)

Example 2 with BehaviorAnnex

use of org.osate.ba.aadlba.BehaviorAnnex 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 3 with BehaviorAnnex

use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.

the class BehaviorStateHandler method rename.

@Override
public void rename(final RenameContext ctx) {
    final BehaviorState behaviorState = ctx.getBusinessObject(BehaviorState.class).orElseThrow();
    final BehaviorAnnex behaviorAnnex = (BehaviorAnnex) behaviorState.getOwner();
    final String originalName = behaviorState.getName();
    final String newName = ctx.getNewName();
    // Handle DeclarativeBehaviorTransitions
    // Set the ID for source and destination states because they do not update if an invalid state name change occurs
    behaviorAnnex.getTransitions().stream().filter(DeclarativeBehaviorTransition.class::isInstance).forEach(transition -> {
        final DeclarativeBehaviorTransition dt = (DeclarativeBehaviorTransition) transition;
        final EList<Identifier> srcStates = dt.getSrcStates();
        if (!srcStates.isEmpty() && dt.getDestState() != null) {
            // Set id for source and destination
            setId(srcStates.get(0), originalName, newName);
            setId(dt.getDestState(), originalName, newName);
        }
    });
    behaviorState.setName(newName);
}
Also used : Identifier(org.osate.ba.declarative.Identifier) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorState(org.osate.ba.aadlba.BehaviorState)

Example 4 with BehaviorAnnex

use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.

the class BehaviorTransitionHandler method delete.

@Override
public void delete(final CustomDeleteContext ctx) {
    final BehaviorAnnex behaviorAnnex = ctx.getContainerBusinessObject(BehaviorAnnex.class).orElseThrow();
    // Find transition by URI.
    final BehaviorTransition behaviorTransition = (BehaviorTransition) behaviorAnnex.eResource().getResourceSet().getEObject(EcoreUtil.getURI(ctx.getReadonlyBoToDelete(BehaviorTransition.class).orElseThrow()), true);
    EcoreUtil.remove(behaviorTransition);
    if (behaviorAnnex.getTransitions().isEmpty()) {
        behaviorAnnex.unsetTransitions();
    }
}
Also used : BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Example 5 with BehaviorAnnex

use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.

the class BehaviorTransitionHandler method getCanonicalReference.

@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
    final BehaviorTransition behaviorTransition = ctx.getBusinessObject(BehaviorTransition.class).orElseThrow();
    final BehaviorAnnex behaviorAnnex = (BehaviorAnnex) behaviorTransition.getOwner();
    final int index = behaviorAnnex.getTransitions().indexOf(behaviorTransition);
    return new CanonicalBusinessObjectReference(BehaviorAnnexReferenceUtil.TRANSITION_TYPE, Integer.toString(index), ctx.getReferenceBuilder().getCanonicalReference(behaviorAnnex).encode());
}
Also used : BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Aggregations

BehaviorAnnex (org.osate.ba.aadlba.BehaviorAnnex)10 BehaviorTransition (org.osate.ba.aadlba.BehaviorTransition)4 BehaviorState (org.osate.ba.aadlba.BehaviorState)3 BehaviorVariable (org.osate.ba.aadlba.BehaviorVariable)3 DeclarativeBehaviorTransition (org.osate.ba.declarative.DeclarativeBehaviorTransition)3 DataClassifier (org.osate.aadl2.DataClassifier)2 Iterator (java.util.Iterator)1 Optional (java.util.Optional)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 AbstractEnumerator (org.eclipse.emf.common.util.AbstractEnumerator)1 Enumerator (org.eclipse.emf.common.util.Enumerator)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 AadlPackage (org.osate.aadl2.AadlPackage)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 ArrayDimension (org.osate.aadl2.ArrayDimension)1 Element (org.osate.aadl2.Element)1 NamedElement (org.osate.aadl2.NamedElement)1 NamedValue (org.osate.aadl2.NamedValue)1