Search in sources :

Example 1 with BehaviorTransitionTrunk

use of org.osate.ge.errormodel.model.BehaviorTransitionTrunk in project osate2 by osate.

the class CreateTransitionPaletteCommand method buildCreateOperation.

private Operation buildCreateOperation(final BusinessObjectContext srcBoc, final ErrorBehaviorState targetStateReadonly) {
    final Object srcBo = srcBoc.getBusinessObject();
    final URI targetStateUri = EcoreUtil.getURI(targetStateReadonly);
    if (srcBo instanceof ErrorBehaviorState) {
        final ErrorBehaviorState srcStateReadonly = (ErrorBehaviorState) srcBo;
        final URI srcStateUri = EcoreUtil.getURI(srcStateReadonly);
        return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(getStateMachine(srcStateReadonly))).modifyPreviousResult(stateMachine -> {
            final ErrorBehaviorState targetState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(targetStateUri, true);
            final ErrorBehaviorState srcState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(srcStateUri, true);
            final NamedElementCollectionSingleSelectorModel<ErrorBehaviorEvent> model = new NamedElementCollectionSingleSelectorModel<>(stateMachine.getEvents());
            if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Event", new LabelFilteringListSelectorModel<>(model))) {
                return null;
            }
            final ErrorBehaviorEvent event = model.getSelectedElement();
            // Create the transition
            final ErrorBehaviorTransition newTransition = ErrorModelFactory.eINSTANCE.createErrorBehaviorTransition();
            newTransition.setSource(srcState);
            // Set the target
            if (srcState == targetState) {
                newTransition.setSteadyState(true);
            } else {
                newTransition.setTarget(targetState);
            }
            newTransition.setName(ErrorModelNamingUtil.buildUniqueIdentifier(stateMachine, "new_transition"));
            final ConditionElement conditionElement = ErrorModelFactory.eINSTANCE.createConditionElement();
            newTransition.setCondition(conditionElement);
            final EMV2PathElement conditionPathElement = ErrorModelFactory.eINSTANCE.createEMV2PathElement();
            conditionPathElement.setNamedElement(event);
            final QualifiedErrorEventOrPropagation errorEventOrPropogation = ErrorModelFactory.eINSTANCE.createQualifiedErrorEventOrPropagation();
            errorEventOrPropogation.setEmv2Target(conditionPathElement);
            conditionElement.setQualifiedErrorPropagationReference(errorEventOrPropogation);
            stateMachine.getTransitions().add(newTransition);
            return StepResultBuilder.create().showNewBusinessObject(srcBoc.getParent(), newTransition).build();
        }));
    } else if (srcBo instanceof ErrorBehaviorTransition || srcBo instanceof BehaviorTransitionTrunk || srcBo instanceof TransitionBranch) {
        // Get the transition to modify
        final ErrorBehaviorTransition transitionReadonly;
        if (srcBo instanceof ErrorBehaviorTransition) {
            transitionReadonly = (ErrorBehaviorTransition) srcBo;
        } else if (srcBo instanceof BehaviorTransitionTrunk) {
            transitionReadonly = ((BehaviorTransitionTrunk) srcBo).getTransition();
        } else if (srcBo instanceof TransitionBranch) {
            transitionReadonly = (ErrorBehaviorTransition) ((TransitionBranch) srcBo).eContainer();
        } else {
            throw new AadlGraphicalEditorException("Unexpected case: " + srcBo);
        }
        return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(transitionReadonly)).modifyPreviousResult(transition -> {
            final ErrorBehaviorState targetState = (ErrorBehaviorState) transition.eResource().getResourceSet().getEObject(targetStateUri, true);
            // Convert from using steady state and target field to using branches.
            if (transition.getDestinationBranches().isEmpty()) {
                final TransitionBranch firstBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
                final BranchValue firstBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
                firstBranchValue.setRealvalue("1.0");
                if (transition.isSteadyState()) {
                    firstBranch.setSteadyState(true);
                } else {
                    firstBranch.setTarget(transition.getTarget());
                }
                firstBranch.setValue(firstBranchValue);
                transition.getDestinationBranches().add(firstBranch);
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_Target());
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_TargetToken());
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_SteadyState());
            }
            // Create the new branch
            final TransitionBranch newBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
            final BranchValue newBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
            newBranchValue.setRealvalue("1.0");
            // Set the target
            if (transition.getSource() == targetState) {
                newBranch.setSteadyState(true);
            } else {
                newBranch.setTarget(targetState);
            }
            newBranch.setValue(newBranchValue);
            transition.getDestinationBranches().add(newBranch);
            return StepResultBuilder.create().build();
        }));
    } else {
        throw new AadlGraphicalEditorException("Unsupported case: " + srcBo);
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) URI(org.eclipse.emf.common.util.URI) StepResult(org.osate.ge.operations.StepResult) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) EObject(org.eclipse.emf.ecore.EObject) Display(org.eclipse.swt.widgets.Display) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) FilteringSelectorDialog(org.osate.ge.swt.selectors.FilteringSelectorDialog) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) Optional(java.util.Optional) ErrorModelPackage(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelPackage) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) URI(org.eclipse.emf.common.util.URI) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) EObject(org.eclipse.emf.ecore.EObject) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk)

Example 2 with BehaviorTransitionTrunk

use of org.osate.ge.errormodel.model.BehaviorTransitionTrunk in project osate2 by osate.

the class ErrorModelBusinessObjectProvider method getChildBusinessObjects.

@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
    final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
    if (bo instanceof AadlPackage) {
        return ErrorModelGeUtil.getErrorModelLibrary((AadlPackage) bo).map(lib -> Stream.concat(Stream.concat(lib.getTypes().stream(), lib.getTypesets().stream()), lib.getBehaviors().stream())).orElseGet(Stream::empty);
    } else if (bo instanceof ErrorBehaviorStateMachine) {
        final ErrorBehaviorStateMachine stateMachine = (ErrorBehaviorStateMachine) bo;
        return Stream.concat(Stream.concat(stateMachine.getEvents().stream(), stateMachine.getStates().stream()), stateMachine.getTransitions().stream());
    } else if (bo instanceof ErrorBehaviorTransition) {
        // See ErrorBehaviorTransitionHandler for details regarding how the business objects related to error behavior transitions are represented.
        final ErrorBehaviorTransition t = (ErrorBehaviorTransition) bo;
        return t.getDestinationBranches().isEmpty() ? Stream.empty() : Stream.concat(Stream.of(new BehaviorTransitionTrunk(t)), t.getDestinationBranches().stream());
    } else if (bo instanceof ErrorType) {
        final ErrorType errorType = (ErrorType) bo;
        if (errorType.getSuperType() != null) {
            return Stream.of(new ErrorTypeExtension(errorType.getSuperType(), errorType));
        }
    } else if (bo instanceof Classifier || bo instanceof Subcomponent) {
        // Anytime the children of a classifier or subcomponent is requested, process of error model subclauses
        // in the element or extended elements and cache the result.
        // Ideally, we would only do this if the classifier has changed but it would require a reliable means to
        // determine if a classifier or any classifiers it extends has changed. If extended classifiers are in another
        // package, the classifier be the same instance.
        // The object is cached so it is available when calling the business object provider on children.
        final Classifier classifier = ErrorModelGeUtil.getClassifier(ctx.getBusinessObjectContext()).orElse(null);
        if (classifier != null) {
            final CombinedErrorModelSubclause cacheEntry = CombinedErrorModelSubclause.create(classifier);
            classifierCache.put(classifier, cacheEntry);
            if (cacheEntry.subclauseExists()) {
                final Set<KeywordPropagationPointType> usedKeywordTypes = cacheEntry.getUsedKeywordPropagations();
                return Stream.of(cacheEntry.getPoints(), cacheEntry.getPaths(), cacheEntry.getFlows(), Arrays.stream(KeywordPropagationPointType.values()).map(t -> new KeywordPropagationPoint(classifier, t, usedKeywordTypes.contains(t)))).flatMap(Function.identity());
            }
        }
    } else if (bo instanceof Feature || bo instanceof PropagationPoint || bo instanceof KeywordPropagationPoint) {
        // Propagation(and containment) objects
        final CombinedErrorModelSubclause cacheEntry = getClassifierCacheEntry(ctx.getBusinessObjectContext());
        return PropagationTreeUtil.getPropagationsForBusinessObjectContext(cacheEntry.getPropagations(), ctx.getBusinessObjectContext());
    }
    return Stream.empty();
}
Also used : Arrays(java.util.Arrays) Feature(org.osate.aadl2.Feature) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) Set(java.util.Set) BusinessObjectProviderContext(org.osate.ge.BusinessObjectProviderContext) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) AadlPackage(org.osate.aadl2.AadlPackage) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Function(java.util.function.Function) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) PropagationTreeUtil(org.osate.ge.errormodel.combined.PropagationTreeUtil) Stream(java.util.stream.Stream) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Classifier(org.osate.aadl2.Classifier) BusinessObjectProvider(org.osate.ge.BusinessObjectProvider) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Subcomponent(org.osate.aadl2.Subcomponent) WeakHashMap(java.util.WeakHashMap) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) AadlPackage(org.osate.aadl2.AadlPackage) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) Subcomponent(org.osate.aadl2.Subcomponent) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Stream(java.util.stream.Stream) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType)

Aggregations

BusinessObjectContext (org.osate.ge.BusinessObjectContext)2 BehaviorTransitionTrunk (org.osate.ge.errormodel.model.BehaviorTransitionTrunk)2 ErrorBehaviorStateMachine (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine)2 ErrorBehaviorTransition (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition)2 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 Display (org.eclipse.swt.widgets.Display)1 AadlPackage (org.osate.aadl2.AadlPackage)1 Classifier (org.osate.aadl2.Classifier)1 Feature (org.osate.aadl2.Feature)1 Subcomponent (org.osate.aadl2.Subcomponent)1 BusinessObjectProvider (org.osate.ge.BusinessObjectProvider)1 BusinessObjectProviderContext (org.osate.ge.BusinessObjectProviderContext)1