Search in sources :

Example 1 with BehaviorTransition

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

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

the class BehaviorTransitionHandler method getRelativeReference.

@Override
public RelativeBusinessObjectReference getRelativeReference(final ReferenceContext ctx) {
    final BehaviorTransition behaviorTransition = ctx.getBusinessObject(BehaviorTransition.class).orElseThrow();
    final String refSeg = getTransitionReference((BehaviorAnnex) behaviorTransition.getOwner(), behaviorTransition);
    return BehaviorAnnexReferenceUtil.getTransitionRelativeReference(refSeg);
}
Also used : DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Example 3 with BehaviorTransition

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

use of org.osate.ba.aadlba.BehaviorTransition 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)

Example 5 with BehaviorTransition

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

the class AadlBaNameResolver method parentComponentIdentifiersUniquenessCheck.

/**
 * Check behavior annex's sub component uniqueness within behavior annex's
 * parent component scope. Conflicts are reported.
 */
private boolean parentComponentIdentifiersUniquenessCheck() {
    boolean result = true;
    EList<org.osate.aadl2.NamedElement> lcc = new BasicEList<org.osate.aadl2.NamedElement>(0);
    // Merges parent component' subcomponents lists.
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Data.class));
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Mode.class));
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Feature.class));
    EList<BehaviorVariable> lvars = _ba.getVariables();
    EList<BehaviorState> lstates = _ba.getStates();
    EList<BehaviorTransition> ltrans = _ba.getTransitions();
    // Check uniqueness within the parent component.
    for (org.osate.aadl2.NamedElement ne : lcc) {
        for (BehaviorVariable v : lvars) {
            String bvName = v.getName();
            String neName = ne.getName();
            if (bvName.equalsIgnoreCase(neName)) {
                reportDuplicateNameError(v, ne);
                result = false;
            }
        }
        for (BehaviorState s : lstates) {
            String bsName = s.getName();
            if (bsName.equalsIgnoreCase(ne.getName())) {
                // Links the identifier with the mode.
                if (ne instanceof Mode) {
                    if (s.isComplete() == false) {
                        _errManager.error(s, "Behavior state " + bsName + " must be declared complete in order to represent " + "mode " + ne.getName() + " located at line " + Aadl2Utils.getLocationReference(ne).getLine());
                        result = false;
                    } else {
                        s.setBindedMode((Mode) ne);
                    }
                } else {
                    reportDuplicateNameError(s, ne);
                    result = false;
                }
            }
        }
        for (BehaviorTransition t : ltrans) {
            String btName = t.getName();
            if (btName != null && btName.equalsIgnoreCase(ne.getName())) {
                reportDuplicateNameError(t, ne);
                result = false;
            }
        }
    }
    return result;
}
Also used : BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BasicEList(org.eclipse.emf.common.util.BasicEList) Mode(org.osate.aadl2.Mode) Data(org.osate.aadl2.Data) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorState(org.osate.ba.aadlba.BehaviorState) NamedElement(org.osate.aadl2.NamedElement) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

BehaviorTransition (org.osate.ba.aadlba.BehaviorTransition)13 DeclarativeBehaviorTransition (org.osate.ba.declarative.DeclarativeBehaviorTransition)10 BehaviorAnnex (org.osate.ba.aadlba.BehaviorAnnex)5 BehaviorState (org.osate.ba.aadlba.BehaviorState)5 BehaviorVariable (org.osate.ba.aadlba.BehaviorVariable)3 Optional (java.util.Optional)2 NamedElement (org.osate.aadl2.NamedElement)2 BehaviorActionBlock (org.osate.ba.aadlba.BehaviorActionBlock)2 DispatchCondition (org.osate.ba.aadlba.DispatchCondition)2 ValueExpression (org.osate.ba.aadlba.ValueExpression)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Adapters (org.eclipse.core.runtime.Adapters)1 AbstractEnumerator (org.eclipse.emf.common.util.AbstractEnumerator)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 Enumerator (org.eclipse.emf.common.util.Enumerator)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 IFilter (org.eclipse.jface.viewers.IFilter)1