Search in sources :

Example 1 with BehaviorState

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

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

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

the class BehaviorStateItemProvider method getImage.

/**
 * This returns BehaviorState.gif.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 */
@Override
public Object getImage(Object object) {
    BehaviorState state = (BehaviorState) object;
    byte code = 0;
    String imgFile = null;
    if (state.isInitial())
        code = 1;
    if (state.isComplete())
        code += 10;
    if (state.isFinal())
        code += 100;
    switch(code) {
        case 0:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "e_state_16";
                break;
            }
        case 1:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "i_state_16";
                break;
            }
        case 10:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "c_state_16";
                break;
            }
        case 11:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "ic_state_16";
                break;
            }
        case 100:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "f_state_16";
                break;
            }
        case 101:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "if_state_16";
                break;
            }
        case 110:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "cf_state_16";
                break;
            }
        case 111:
            {
                imgFile = BehaviorElementItemProvider.IMG_PATH + "icf_state_16";
                break;
            }
    }
    return overlayImage(object, getResourceLocator().getImage(imgFile));
}
Also used : BehaviorState(org.osate.ba.aadlba.BehaviorState)

Example 4 with BehaviorState

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

the class BehaviorTransitionImpl method basicSetSourceState.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetSourceState(BehaviorState newSourceState, NotificationChain msgs) {
    BehaviorState oldSourceState = sourceState;
    sourceState = newSourceState;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AadlBaPackage.BEHAVIOR_TRANSITION__SOURCE_STATE, oldSourceState, newSourceState);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) BehaviorState(org.osate.ba.aadlba.BehaviorState)

Example 5 with BehaviorState

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

BehaviorState (org.osate.ba.aadlba.BehaviorState)23 Identifier (org.osate.ba.declarative.Identifier)9 BehaviorAnnex (org.osate.ba.aadlba.BehaviorAnnex)6 DeclarativeBehaviorTransition (org.osate.ba.declarative.DeclarativeBehaviorTransition)6 BehaviorTransition (org.osate.ba.aadlba.BehaviorTransition)5 Optional (java.util.Optional)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 Mode (org.osate.aadl2.Mode)3 NamedElement (org.osate.aadl2.NamedElement)3 NamedValue (org.osate.aadl2.NamedValue)3 BehaviorVariable (org.osate.ba.aadlba.BehaviorVariable)3 ArrayableIdentifier (org.osate.ba.declarative.ArrayableIdentifier)3 ArrayList (java.util.ArrayList)2 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)2 Element (org.osate.aadl2.Element)2 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)2 AadlBaPackage (org.osate.ba.aadlba.AadlBaPackage)2 IntegerValue (org.osate.ba.aadlba.IntegerValue)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1