Search in sources :

Example 16 with EndToEndFlow

use of org.osate.aadl2.EndToEndFlow in project osate2 by osate.

the class ComponentInstanceImpl method isSameOrRefined.

private static boolean isSameOrRefined(EndToEndFlow e2e1, EndToEndFlow e2e2) {
    if (e2e1 == e2e2) {
        return true;
    }
    EndToEndFlow rsub = e2e1;
    while (rsub != null) {
        if (e2e2 == rsub) {
            return true;
        }
        rsub = rsub.getRefined();
    }
    rsub = e2e2;
    while (rsub != null) {
        if (e2e1 == rsub) {
            return true;
        }
        rsub = rsub.getRefined();
    }
    return false;
}
Also used : EndToEndFlow(org.osate.aadl2.EndToEndFlow)

Example 17 with EndToEndFlow

use of org.osate.aadl2.EndToEndFlow in project osate2 by osate.

the class Aadl2LinkingService method doGetLinkedObjects.

private List<EObject> doGetLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
    NamedElement annex = AadlUtil.getContainingAnnex(context);
    if (annex != null && !(reference == Aadl2Package.eINSTANCE.getModalElement_InMode())) {
        String annexName = annex.getName();
        if (annexName != null) {
            if (annexlinkingserviceregistry == null) {
                initAnnexLinkingServiceRegistry();
            }
            if (annexlinkingserviceregistry != null) {
                AnnexLinkingService linkingservice = annexlinkingserviceregistry.getAnnexLinkingService(annexName);
                if (linkingservice != null) {
                    return linkingservice.resolveAnnexReference(annexName, context, reference, node);
                }
            }
        }
        return Collections.<EObject>emptyList();
    }
    final EClass requiredType = reference.getEReferenceType();
    if (requiredType == null) {
        return Collections.<EObject>emptyList();
    }
    Aadl2Package.eINSTANCE.getPropertyType();
    final EClass cl = Aadl2Package.eINSTANCE.getClassifier();
    final EClass sct = Aadl2Package.eINSTANCE.getSubcomponentType();
    final String name = getCrossRefNodeAsString(node);
    if (sct.isSuperTypeOf(requiredType) || cl.isSuperTypeOf(requiredType)) {
        // XXX: this code can be replicated in Aadl2LinkingService as it is called often in the core
        // resolve classifier reference
        EObject e = findClassifier(context, reference, name);
        if (e != null) {
            // the result satisfied the expected class
            return Collections.singletonList(e);
        }
        if (!(context instanceof Generalization) && sct.isSuperTypeOf(requiredType)) {
            // need to resolve prototype
            Classifier containingClassifier = AadlUtil.getContainingClassifier(context);
            /*
				 * This test was put here as a quick and dirty fix to a NullPointerException that was
				 * being thrown while typing up a component type renames statement. Need to figure out
				 * what we should really be doing for renames.
				 */
            if (containingClassifier != null) {
                EObject res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
                if (Aadl2Package.eINSTANCE.getDataPrototype() == reference) {
                    if (res instanceof DataPrototype) {
                        return Collections.singletonList(res);
                    }
                } else if (res instanceof ComponentPrototype) {
                    return Collections.singletonList(res);
                }
            }
        }
        return Collections.emptyList();
    } else if (Aadl2Package.eINSTANCE.getFeatureClassifier().isSuperTypeOf(requiredType)) {
        // prototype for feature or component, or data,bus,subprogram, subprogram group classifier
        EObject e = findClassifier(context, reference, name);
        if (Aadl2Util.isNull(e) && !(context instanceof Generalization) && !Aadl2Package.eINSTANCE.getComponentType().isSuperTypeOf(requiredType)) {
            // look for prototype
            e = AadlUtil.getContainingClassifier(context).findNamedElement(name);
            // TODO-phf: this can be removed if the FeatureClassifier class handles it
            if (!(e instanceof FeaturePrototype || e instanceof ComponentPrototype)) {
                e = null;
            }
        }
        if (e != null && requiredType.isSuperTypeOf(e.eClass())) {
            return Collections.singletonList(e);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getFeaturePrototype() == requiredType) {
        // look for prototype
        EObject e = AadlUtil.getContainingClassifier(context).findNamedElement(name);
        // TODO-phf: this can be removed if the FeatureClassifier class handles it
        if (e instanceof FeaturePrototype) {
            return Collections.singletonList(e);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getConnectionEnd() == requiredType) {
        // resolve connection end
        ConnectionEnd ce = null;
        if (context.eContainer() instanceof ConnectedElement) {
            ConnectedElement contextParent = (ConnectedElement) context.eContainer();
            if (contextParent.getConnectionEnd() instanceof FeatureGroup) {
                ce = findElementInContext(contextParent, (FeatureGroup) contextParent.getConnectionEnd(), name, ConnectionEnd.class);
            }
        } else {
            ConnectedElement connectedElement = (ConnectedElement) context;
            ce = findElementInContext(connectedElement, connectedElement.getContext(), name, ConnectionEnd.class);
        }
        if (ce != null) {
            return Collections.singletonList((EObject) ce);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getTriggerPort() == requiredType) {
        if (context instanceof ModeTransitionTrigger) {
            ModeTransitionTrigger trigger = (ModeTransitionTrigger) context;
            TriggerPort triggerPort = findElementInContext(trigger, trigger.getContext(), name, TriggerPort.class);
            if (triggerPort != null) {
                return Collections.singletonList((EObject) triggerPort);
            }
        }
        return Collections.emptyList();
    } else if (Aadl2Package.eINSTANCE.getPort().isSuperTypeOf(requiredType)) {
        Classifier ns = AadlUtil.getContainingClassifier(context);
        if (context instanceof Feature) {
            // component being extended
            if (ns.getExtended() != null) {
                ns = ns.getExtended();
            } else {
                return Collections.emptyList();
            }
        // } else if (context instanceof ModeTransitionTrigger){
        // // we are a mode transition trigger
        // Context triggerContext = ((ModeTransitionTrigger)context).getContext();
        // if (triggerContext instanceof Subcomponent){
        // // look up the feature in the ComponentType
        // ComponentType ct = ((Subcomponent)triggerContext).getComponentType();
        // if (ct != null)
        // ns = ct;
        // }
        // if (triggerContext instanceof FeatureGroup){
        // // look up the feature in the FeaturegroupType
        // FeatureGroupType ct = ((FeatureGroup)triggerContext).getFeatureGroupType();
        // if (ct != null)
        // ns = ct;
        // }
        }
        EObject searchResult = AadlUtil.findNamedElementInList(ns.getAllFeatures(), name);
        if (searchResult != null && searchResult instanceof Port) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getContext() == requiredType) {
        // represents connection source/dest context as well as flowspec
        // context
        // also used in triggerport
        EObject searchResult = AadlUtil.getContainingClassifier(context).findNamedElement(name);
        if (searchResult instanceof Context) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getCallContext() == requiredType) {
        EObject searchResult = AadlUtil.getContainingClassifier(context).findNamedElement(name);
        if (searchResult != null && requiredType.isSuperTypeOf(searchResult.eClass())) {
            return Collections.singletonList(searchResult);
        }
        searchResult = findClassifier(context, reference, name);
        if (searchResult != null) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getCalledSubprogram() == requiredType) {
        Classifier ns = AadlUtil.getContainingClassifier(context);
        EObject searchResult;
        if (!(context instanceof SubprogramCall) || (context instanceof SubprogramCall && ((SubprogramCall) context).getContext() == null)) {
            // first check whether it is a reference to a classifier
            searchResult = findClassifier(context, reference, name);
            if (searchResult != null && requiredType.isSuperTypeOf(searchResult.eClass())) {
                return Collections.singletonList(searchResult);
            }
            // if it was a qualified component type name it would have been found before
            if (name.contains("::")) {
                // Qualified classifier should have been found before
                return Collections.<EObject>emptyList();
            }
            // no package qualifier. Look up in local name space, e.g., subprogram access feature or subprogram subcomponent
            searchResult = ns.findNamedElement(name);
            if (searchResult != null && requiredType.isSuperTypeOf(searchResult.eClass())) {
                return Collections.singletonList(searchResult);
            }
        }
        // lets first find it in its context
        if (context instanceof SubprogramCall) {
            // we have a context
            // lets set it and find the called subprogram
            SubprogramCall callSpec = (SubprogramCall) context;
            CallContext callContext = callSpec.getContext();
            if (callContext instanceof ComponentType) {
                // first try to find subprogram implementation
                ComponentType ct = (ComponentType) callContext;
                String implname = ct.getQualifiedName() + "." + name;
                searchResult = findClassifier(context, reference, implname);
                if (searchResult != null && searchResult instanceof ComponentImplementation) {
                    return Collections.singletonList(searchResult);
                }
                ns = (ComponentType) callContext;
            } else if (callContext instanceof SubprogramGroupSubcomponent) {
                ns = ((SubprogramGroupSubcomponent) callContext).getComponentType();
                if (Aadl2Util.isNull(ns)) {
                    return Collections.<EObject>emptyList();
                }
            } else if (callContext instanceof SubprogramGroupAccess && ((SubprogramGroupAccess) callContext).getKind() == AccessType.REQUIRES) {
                SubprogramGroupSubcomponentType sst = ((SubprogramGroupAccess) callContext).getSubprogramGroupFeatureClassifier();
                if (sst instanceof Classifier) {
                    ns = (Classifier) sst;
                }
                if (Aadl2Util.isNull(ns)) {
                    return Collections.<EObject>emptyList();
                }
            } else if (callContext instanceof FeatureGroup) {
                ns = ((FeatureGroup) callContext).getFeatureGroupType();
                if (Aadl2Util.isNull(ns)) {
                    return Collections.<EObject>emptyList();
                }
            }
            searchResult = ns.findNamedElement(name);
            if (!Aadl2Util.isNull(searchResult) && requiredType.isSuperTypeOf(searchResult.eClass())) {
                return Collections.singletonList(searchResult);
            }
            // it might be a component implementation. The type is already recorded in the context
            if (callContext instanceof SubprogramType) {
                String contextName = ((SubprogramType) callContext).getName();
                searchResult = findClassifier(context, reference, contextName + "." + name);
                if (!Aadl2Util.isNull(searchResult)) {
                    return Collections.singletonList(searchResult);
                }
                return Collections.<EObject>emptyList();
            }
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getPrototype() == requiredType) {
        // if context prototype then find in extension source (refined)
        // prototype binding as context
        EObject searchResult = null;
        Classifier ns = null;
        if (context.eContainer() instanceof Subcomponent) {
            Subcomponent sub = (Subcomponent) context.eContainer();
            ns = sub.getAllClassifier();
            if (!Aadl2Util.isNull(ns)) {
                searchResult = ns.findNamedElement(name);
            }
        } else if (context.eContainer() instanceof ComponentPrototypeActual) {
            ComponentPrototypeActual cpa = (ComponentPrototypeActual) context.eContainer();
            SubcomponentType subT = cpa.getSubcomponentType();
            if (subT instanceof ComponentClassifier) {
                searchResult = ((ComponentClassifier) subT).findNamedElement(name);
            }
        } else if (context.eContainer() instanceof FeatureGroupPrototypeActual) {
            FeatureGroupPrototypeActual cpa = (FeatureGroupPrototypeActual) context.eContainer();
            FeatureType subT = cpa.getFeatureType();
            if (subT instanceof FeatureGroupType) {
                searchResult = ((FeatureGroupType) subT).findNamedElement(name);
            }
        } else if (context.eContainer() instanceof ComponentImplementationReference) {
            ns = ((ComponentImplementationReference) context.eContainer()).getImplementation();
            if (!Aadl2Util.isNull(ns)) {
                searchResult = ns.findNamedElement(name);
            }
        } else {
            // If resolving a prototype binding formal, don't resolve to a local prototype. Go to the generals.
            // We could be in a prototype refinement. Go to the generals so that we don't resolve to context.
            ns = AadlUtil.getContainingClassifier(context);
            for (Iterator<Classifier> iter = ns.getGenerals().iterator(); searchResult == null && iter.hasNext(); ) {
                searchResult = iter.next().findNamedElement(name);
            }
        }
        if (!Aadl2Util.isNull(searchResult) && searchResult instanceof Prototype) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getFlowElement() == requiredType) {
        // look for flow element in flow segment
        FlowSegment fs = (FlowSegment) context;
        FlowElement flowElement = findElementInContext(fs, fs.getContext(), name, FlowElement.class);
        if (flowElement != null) {
            return Collections.singletonList((EObject) flowElement);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getEndToEndFlowElement() == requiredType) {
        // look for flow element in flow segment
        EndToEndFlowSegment fs = (EndToEndFlowSegment) context;
        EndToEndFlowElement flowElement = findElementInContext(fs, fs.getContext(), name, EndToEndFlowElement.class);
        if (flowElement != null) {
            return Collections.singletonList((EObject) flowElement);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getModeTransition() == requiredType) {
        // referenced by in modes
        EObject searchResult = AadlUtil.getContainingClassifier(context).findNamedElement(name);
        if (searchResult != null && searchResult instanceof ModeTransition) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getModeFeature() == requiredType) {
        // referenced by inmodes in connections and flows
        EObject searchResult = AadlUtil.getContainingClassifier(context).findNamedElement(name);
        if (searchResult != null && searchResult instanceof ModeFeature) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getFlowSpecification() == requiredType) {
        // refined flow spec
        // referenced by flow implementation
        // also referenced in flow elements in impl and etef
        Classifier ns = AadlUtil.getContainingClassifier(context);
        if (context instanceof FlowSpecification) {
            // we need to resolve a refinement
            if (ns.getExtended() != null) {
                ns = ns.getExtended();
            } else {
                return Collections.emptyList();
            }
        }
        EObject searchResult = ns.findNamedElement(name);
        if (searchResult != null && searchResult instanceof FlowSpecification) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getEndToEndFlow() == requiredType) {
        // refined flow spec
        // referenced by flow implementation
        // also referenced in flow elements in impl and etef
        Classifier ns = AadlUtil.getContainingClassifier(context);
        if (context instanceof EndToEndFlow) {
            // we need to resolve a refinement
            if (ns.getExtended() != null) {
                ns = ns.getExtended();
            } else {
                return Collections.emptyList();
            }
        }
        EObject searchResult = ns.findNamedElement(name);
        if (searchResult != null && searchResult instanceof EndToEndFlow) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getConnection() == requiredType) {
        // refined to, flow elements
        Classifier ns = AadlUtil.getContainingClassifier(context);
        if (context instanceof Connection) {
            // we need to resolve a refinement
            if (ns.getExtended() != null) {
                ns = ns.getExtended();
            } else {
                return Collections.emptyList();
            }
        }
        EObject searchResult = ns.findNamedElement(name);
        if (searchResult != null && searchResult instanceof Connection) {
            return Collections.singletonList(searchResult);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getFeatureType() == requiredType) {
        // feature group type or prototype
        FeatureGroupType fgt = findFeatureGroupType(context, name, reference);
        if (Aadl2Util.isNull(fgt)) {
            // need to resolve prototype
            EObject res = AadlUtil.getContainingClassifier(context).findNamedElement(name);
            if (res instanceof FeatureGroupPrototype) {
                return Collections.singletonList(res);
            }
        } else {
            return Collections.singletonList((EObject) fgt);
        }
        return Collections.<EObject>emptyList();
    } else if (Aadl2Package.eINSTANCE.getArraySizeProperty() == requiredType) {
        // reference to a property constant or property
        // look for property definition in property set
        List<EObject> result = findPropertyDefinitionAsList(context, reference, name);
        if (result.isEmpty()) {
            result = findPropertyConstant(context, reference, name);
        }
        return result;
    } else {
        List<EObject> res = super.getLinkedObjects(context, reference, node);
        return res;
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureType(org.osate.aadl2.FeatureType) FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Prototype(org.osate.aadl2.Prototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) DataPrototype(org.osate.aadl2.DataPrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) SubcomponentType(org.osate.aadl2.SubcomponentType) SubprogramGroupSubcomponentType(org.osate.aadl2.SubprogramGroupSubcomponentType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ModeTransition(org.osate.aadl2.ModeTransition) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) Generalization(org.osate.aadl2.Generalization) Feature(org.osate.aadl2.Feature) ModeFeature(org.osate.aadl2.ModeFeature) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) EClass(org.eclipse.emf.ecore.EClass) FlowSpecification(org.osate.aadl2.FlowSpecification) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) EObject(org.eclipse.emf.ecore.EObject) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ConnectedElement(org.osate.aadl2.ConnectedElement) SubprogramGroupSubcomponentType(org.osate.aadl2.SubprogramGroupSubcomponentType) SubprogramCall(org.osate.aadl2.SubprogramCall) Context(org.osate.aadl2.Context) CallContext(org.osate.aadl2.CallContext) EndToEndFlow(org.osate.aadl2.EndToEndFlow) ComponentType(org.osate.aadl2.ComponentType) ComponentImplementationReference(org.osate.aadl2.ComponentImplementationReference) TriggerPort(org.osate.aadl2.TriggerPort) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) Connection(org.osate.aadl2.Connection) DataPrototype(org.osate.aadl2.DataPrototype) CallContext(org.osate.aadl2.CallContext) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) AnnexLinkingService(org.osate.annexsupport.AnnexLinkingService) FeaturePrototype(org.osate.aadl2.FeaturePrototype) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) SubprogramType(org.osate.aadl2.SubprogramType) ConnectionEnd(org.osate.aadl2.ConnectionEnd) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) FlowSegment(org.osate.aadl2.FlowSegment) NamedElement(org.osate.aadl2.NamedElement) ModeFeature(org.osate.aadl2.ModeFeature) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 18 with EndToEndFlow

use of org.osate.aadl2.EndToEndFlow in project osate2 by osate.

the class EditFlowContributionItem method createControl.

@Override
protected Control createControl(final Composite parent) {
    editFlowBtn = new Button(parent, SWT.PUSH);
    editFlowBtn.setImage(editIcon.createImage());
    editFlowBtn.setToolTipText("Edit...");
    updateButton();
    editFlowBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            segmentNodes.clear();
            final DiagramElement container = selectedHighlightableFlow.getDiagramElementContainer();
            final NamedElement flowSegment = AgeAadlUtil.getRootRefinedElement(selectedHighlightableFlow.getFlowSegment());
            final ComponentImplementation ci = FlowContributionItemUtil.getComponentImplementation(container.getBusinessObject());
            // Set focus to editor for activating create flow tool
            editor.setFocus();
            editor.selectDiagramNodes(Collections.singletonList(editor.getDiagram()));
            final UiService uiService = Adapters.adapt(editor, UiService.class);
            // Create dialog and activate appropriate flow tool
            if (flowSegment instanceof EndToEndFlow) {
                final EndToEndFlow endToEndFlow = AgeEmfUtil.resolveOrNull(flowSegment, EndToEndFlow.class, ci.eResource().getResourceSet());
                // Activate tool
                uiService.activateTool(new CreateEndToEndFlowSpecificationTool(editor, container, endToEndFlow));
            } else if (flowSegment instanceof FlowSpecification) {
                final FlowSpecification fs = AgeEmfUtil.resolveOrNull(flowSegment, FlowSpecification.class, ci.eResource().getResourceSet());
                getFlowImplementation(ci, fs).ifPresent(fi -> {
                    uiService.activateTool(new CreateFlowImplementationTool(editor, container, fi));
                });
            } else {
                throw new RuntimeException("Unsupported flow type.");
            }
        }

        private Optional<FlowImplementation> getFlowImplementation(final ComponentImplementation ci, final FlowSpecification flowSpec) {
            final List<FlowImplementation> flowImpls = ci.getAllFlowImplementations().stream().filter(fi -> fi.getSpecification() == flowSpec).collect(Collectors.toList());
            if (flowImpls.size() == 1) {
                return Optional.of(flowImpls.get(0));
            } else {
                final FlowImplementationSelectionDialog dlg = new FlowImplementationSelectionDialog(Display.getCurrent().getActiveShell(), flowImpls, "Select", "Choose the flow implementation to edit.");
                if (dlg.open() == Window.OK) {
                    return Optional.ofNullable(dlg.getSelectedFlowImplementation());
                }
            }
            return Optional.empty();
        }
    });
    return editFlowBtn;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) EndToEndFlow(org.osate.aadl2.EndToEndFlow) CreateFlowImplementationTool(org.osate.ge.aadl2.ui.internal.tools.CreateFlowImplementationTool) Optional(java.util.Optional) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FlowImplementationSelectionDialog(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItemUtil.FlowImplementationSelectionDialog) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) UiService(org.osate.ge.internal.services.UiService) CreateEndToEndFlowSpecificationTool(org.osate.ge.aadl2.ui.internal.tools.CreateEndToEndFlowSpecificationTool) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) NamedElement(org.osate.aadl2.NamedElement)

Example 19 with EndToEndFlow

use of org.osate.aadl2.EndToEndFlow in project osate2 by osate.

the class ShowFlowContributionItem method createControl.

@Override
protected Control createControl(final Composite parent) {
    showFlowBtn = new Button(parent, SWT.PUSH);
    showFlowBtn.setImage(showIcon.createImage());
    showFlowBtn.setToolTipText("Show");
    updateButton();
    showFlowBtn.addSelectionListener(new SelectionAdapter() {

        private ProjectReferenceService referenceService;

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (editor != null && selectedFlow != null) {
                referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
                final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
                final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
                final BusinessObjectNode boTree = getBoTree(boTreeUpdater);
                final BusinessObjectNode containerNode = boTree.getAllDescendants().filter(q -> q.getBusinessObject() == selectedFlow.getContainer().getBusinessObject()).findAny().map(BusinessObjectNode.class::cast).orElseThrow(() -> new RuntimeException("Cannot find container for highlightable flow: " + selectedFlow.getFlowSegment().getName()));
                final Object component = getContainerComponent(selectedFlow.getContainer().getBusinessObject());
                ensureFlowSegmentsExist(component, selectedFlow.getFlowSegment(), containerNode);
                final AgeDiagram diagram = editor.getDiagram();
                final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
                editor.getActionExecutor().execute("Show Flow Elements", ExecutionMode.NORMAL, () -> {
                    // Update the diagram
                    diagramUpdater.updateDiagram(diagram, boTree);
                    // Update layout
                    diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
                    return null;
                });
            }
        }

        private List<FlowSegmentReference> findFlowSegments(final FlowSegmentReference flowElementRef) {
            if (flowElementRef.flowSegmentElement instanceof FlowSpecification) {
                // Check if flow specification has flow implementation(s)
                return AadlClassifierUtil.getComponentImplementation(flowElementRef.container.getBusinessObject()).map(ci -> ci.getAllFlowImplementations().stream().filter(cfi -> flowElementRef.flowSegmentElement == cfi.getSpecification()).flatMap(cfi -> cfi.getOwnedFlowSegments().stream()).map(flowSegment -> createFlowSegmentReference(flowSegment, (BusinessObjectNode) flowElementRef.container))).orElse(Stream.empty()).collect(Collectors.toList());
            } else if (flowElementRef.flowSegmentElement instanceof EndToEndFlow) {
                final EndToEndFlow endToEndFlow = (EndToEndFlow) flowElementRef.flowSegmentElement;
                final BusinessObjectNode containerNode = (BusinessObjectNode) flowElementRef.container;
                return AadlClassifierUtil.getComponentImplementation(containerNode.getBusinessObject()).map(ci -> ci.getAllEndToEndFlows().stream().filter(ownedEndToEndFlow -> ownedEndToEndFlow == endToEndFlow).flatMap(ete -> ete.getAllFlowSegments().stream().flatMap(flowSegment -> {
                    final EndToEndFlowElement endToEndFlowElement = flowSegment.getFlowElement();
                    if (endToEndFlowElement instanceof EndToEndFlow) {
                        // Find segments of a segment that is an end to end flow
                        return ((EndToEndFlow) endToEndFlowElement).getAllFlowSegments().stream();
                    }
                    return Stream.of(flowSegment);
                })).map(endToEndFlowSegment -> createFlowSegmentReference(endToEndFlowSegment, containerNode))).orElse(Stream.empty()).collect(Collectors.toList());
            } else if (flowElementRef.flowSegmentElement instanceof EndToEndFlowInstance) {
                return AadlInstanceObjectUtil.getComponentInstance(flowElementRef.container.getBusinessObject()).map(ci -> ci.getEndToEndFlows().stream().filter(ete -> ete == flowElementRef.flowSegmentElement).flatMap(ete -> {
                    return ete.getFlowElements().stream().flatMap(fei -> {
                        if (fei instanceof ConnectionInstance) {
                            return ((ConnectionInstance) fei).getConnectionReferences().stream().map(cr -> createFlowSegmentReference(cr, (BusinessObjectNode) flowElementRef.container));
                        } else {
                            return Stream.of(createFlowSegmentReference(fei, (BusinessObjectNode) flowElementRef.container));
                        }
                    });
                })).orElse(Stream.empty()).collect(Collectors.toList());
            } else {
                return Collections.emptyList();
            }
        }

        private void ensureFlowSegmentsExist(final Object component, final NamedElement flow, final BusinessObjectNode containerNode) {
            if (component instanceof ComponentImplementation) {
                final ComponentImplementation ci = (ComponentImplementation) component;
                if (flow instanceof FlowSpecification) {
                    ci.getAllFlowImplementations().stream().filter(fi -> flow.getName().equalsIgnoreCase(fi.getSpecification().getName())).findAny().ifPresent(flowImpl -> {
                        final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(flowImpl.getSpecification(), containerNode);
                        enableFlowSegments(findFlowSegments(flowSegmentRef));
                    });
                } else {
                    final String eteName = flow.getName();
                    final Optional<EndToEndFlow> eteFlow = ci.getAllEndToEndFlows().stream().filter(etef -> eteName.equalsIgnoreCase(etef.getName())).findAny();
                    eteFlow.ifPresent(endToEndFlow -> {
                        final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(endToEndFlow, containerNode);
                        enableFlowSegments(findFlowSegments(flowSegmentRef));
                    });
                }
            } else if (component instanceof ComponentInstance) {
                // ETE Flows only
                final EndToEndFlowInstance eteFlowInstance = (EndToEndFlowInstance) flow;
                final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(eteFlowInstance, containerNode);
                enableFlowSegments(findFlowSegments(flowSegmentRef));
            }
        }

        private void enableFlowSegments(final List<FlowSegmentReference> highlightableFlowElements) {
            highlightableFlowElements.stream().filter(Predicates.notNull()).forEach(highlightableFlowElement -> {
                final NamedElement flowSegmentElement = highlightableFlowElement.flowSegmentElement;
                final BusinessObjectContext flowSegmentContainer = highlightableFlowElement.container;
                // Find segments for flow and remove cycles
                final List<FlowSegmentReference> flowSegmentReferences = findFlowSegments(highlightableFlowElement).stream().filter(flowSegmentReference -> flowSegmentReference.flowSegmentElement != flowSegmentElement && flowSegmentReference.container != flowSegmentContainer).collect(Collectors.toList());
                enableFlowSegments(flowSegmentReferences);
            });
        }

        private Object getContainerComponent(final Object container) {
            if (container instanceof Subcomponent) {
                final Subcomponent sc = (Subcomponent) container;
                return sc.getComponentImplementation();
            }
            return container;
        }

        private BusinessObjectNode getBoTree(final BusinessObjectTreeUpdater treeUpdater) {
            BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(editor.getDiagram());
            return treeUpdater.updateTree(editor.getDiagram().getConfiguration(), boTree);
        }

        private FlowSegmentReference createFlowSegmentReference(final Object bo, final BusinessObjectNode container) {
            if (bo instanceof FlowSegment) {
                final FlowSegment flowSegment = (FlowSegment) bo;
                final FlowElement flowElement = flowSegment.getFlowElement();
                if (flowSegment.getContext() == null) {
                    return createFlowSegmentReference(flowElement, container);
                } else {
                    final BusinessObjectNode contextNode = ensureEnabledChild(flowSegment.getContext(), container);
                    return createFlowSegmentReference(flowElement, contextNode);
                }
            } else if (bo instanceof EndToEndFlowSegment) {
                final EndToEndFlowSegment flowSegment = (EndToEndFlowSegment) bo;
                if (flowSegment.getFlowElement() instanceof FlowElement) {
                    final FlowElement flowElement = (FlowElement) flowSegment.getFlowElement();
                    if (flowSegment.getContext() == null) {
                        return createFlowSegmentReference(flowElement, container);
                    } else {
                        final BusinessObjectNode contextNode = ensureEnabledChild(flowSegment.getContext(), container);
                        return createFlowSegmentReference(flowElement, contextNode);
                    }
                }
                return createFlowSegmentReference(flowSegment.getFlowElement(), container);
            } else if (bo instanceof InstanceObject) {
                final InstanceObject io = (InstanceObject) bo;
                if (bo instanceof EndToEndFlowInstance) {
                    return new FlowSegmentReference(io, container);
                } else {
                    final Map<Object, BusinessObjectContext> descendantBoToQueryable = container.getAllDescendants().collect(Collectors.toMap(BusinessObjectContext::getBusinessObject, Function.identity()));
                    if (bo instanceof FlowSpecificationInstance) {
                        final FlowSpecificationInstance fsi = (FlowSpecificationInstance) bo;
                        enableFlowSpecificationInstanceNodes(descendantBoToQueryable, fsi);
                    }
                    if (bo instanceof ConnectionReference) {
                        final ConnectionReference cr = (ConnectionReference) bo;
                        enableConnectionReferenceNodes(descendantBoToQueryable, cr);
                    }
                    return new FlowSegmentReference(io, container);
                }
            } else if (bo instanceof NamedElement) {
                final RelativeBusinessObjectReference ref = getRelativeBusinessObjectReference(bo);
                if (ref != null) {
                    ensureEnabledChild(bo, container);
                }
                if (bo instanceof FlowSpecification) {
                    final FlowSpecification fs = (FlowSpecification) bo;
                    if (fs.getAllInEnd() != null) {
                        enableFlowEnd(fs.getAllInEnd(), container);
                    }
                    if (fs.getAllOutEnd() != null) {
                        enableFlowEnd(fs.getAllOutEnd(), container);
                    }
                } else if (bo instanceof Connection) {
                    final Connection connection = (Connection) bo;
                    final ConnectionEnd dstEnd = connection.getAllDestination();
                    final Context dstContext = connection.getAllDestinationContext();
                    final RelativeBusinessObjectReference dstEndRef = getRelativeBusinessObjectReference(dstEnd);
                    // Destination context
                    BusinessObjectNode ctxContainer = getContextContainer(dstContext, container);
                    if (ctxContainer.getChild(dstEndRef) == null) {
                        createNode(ctxContainer, dstEndRef, dstEnd);
                    }
                    final ConnectionEnd srcEnd = connection.getAllSource();
                    final Context srcContext = connection.getAllSourceContext();
                    // Source context
                    ctxContainer = getContextContainer(srcContext, container);
                    final RelativeBusinessObjectReference srcEndRef = getRelativeBusinessObjectReference(srcEnd);
                    if (ctxContainer.getChild(srcEndRef) == null) {
                        createNode(ctxContainer, srcEndRef, srcEnd);
                    }
                }
                return new FlowSegmentReference((NamedElement) bo, container);
            } else {
                throw new RuntimeException("Unexpected business object: " + bo);
            }
        }

        private BusinessObjectNode getContextContainer(final Context context, final BusinessObjectNode contextContainer) {
            if (context != null) {
                // Ensure context container is created
                final RelativeBusinessObjectReference contextRef = getRelativeBusinessObjectReference(context);
                if (contextContainer.getChild(contextRef) == null) {
                    // Show context
                    createNode(contextContainer, contextRef, context);
                }
                return contextContainer.getChild(contextRef);
            }
            return contextContainer;
        }

        private void enableFlowEnd(final FlowEnd flowEnd, BusinessObjectNode containerNode) {
            final Feature feature = (Feature) flowEnd.getFeature();
            if (flowEnd.getContext() != null) {
                containerNode = ensureEnabledChild(flowEnd.getContext(), containerNode);
            }
            ensureEnabledChild(feature, containerNode);
        }

        private void enableFlowSpecificationInstanceNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final FlowSpecificationInstance fsi) {
            enableAncestorNodes(descendantBoToQueryable, fsi);
            if (fsi.getDestination() != null) {
                enableAncestorNodes(descendantBoToQueryable, fsi.getDestination());
            }
            if (fsi.getSource() != null) {
                enableAncestorNodes(descendantBoToQueryable, fsi.getSource());
            }
        }

        private void enableConnectionReferenceNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final ConnectionReference cr) {
            Element tmpElement = cr;
            // Ancestors to ensure are enabled on the diagram
            final Queue<Element> ancestors = Collections.asLifoQueue(new LinkedList<Element>());
            if (!descendantBoToQueryable.containsKey(tmpElement)) {
                ancestors.add(tmpElement);
                tmpElement = tmpElement.getOwner();
                // First owner of connection reference is connection instance
                if (tmpElement instanceof ConnectionInstance) {
                    tmpElement = tmpElement.getOwner();
                }
            }
            // Connection reference
            populateAncestorsQueue(descendantBoToQueryable, ancestors, tmpElement);
            enableAncestorNodes(descendantBoToQueryable, ancestors, ancestors.poll());
            // Enable source and destination nodes
            enableAncestorNodes(descendantBoToQueryable, cr.getSource());
            enableAncestorNodes(descendantBoToQueryable, cr.getDestination());
        }

        // Gets the first element ancestor that is enabled
        private void populateAncestorsQueue(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Queue<Element> ancestors, Element ancestor) {
            while (!descendantBoToQueryable.containsKey(ancestor)) {
                ancestors.add(ancestor);
                ancestor = ancestor.getOwner();
            }
            ancestors.add(ancestor);
        }

        // Find ancestors and create if necessary
        private void enableAncestorNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Element ancestor) {
            final Queue<Element> ancestors = Collections.asLifoQueue(new LinkedList<Element>());
            populateAncestorsQueue(descendantBoToQueryable, ancestors, ancestor);
            enableAncestorNodes(descendantBoToQueryable, ancestors, ancestors.poll());
        }

        // Create ancestor nodes
        private void enableAncestorNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Queue<Element> ancestors, final Element ancestor) {
            BusinessObjectNode ancestorNode = (BusinessObjectNode) descendantBoToQueryable.get(ancestor);
            for (final Element ancestorToEnable : ancestors) {
                final RelativeBusinessObjectReference ancestorRef = getRelativeBusinessObjectReference(ancestorToEnable);
                if (ancestorNode.getChild(ancestorRef) == null) {
                    ancestorNode = createNode(ancestorNode, ancestorRef, ancestorToEnable);
                }
            }
        }

        private BusinessObjectNode ensureEnabledChild(final Object childBo, final BusinessObjectNode parent) {
            final RelativeBusinessObjectReference childRef = getRelativeBusinessObjectReference(childBo);
            final BusinessObjectNode childNode = parent.getChild(childRef);
            if (childRef != null && childNode == null) {
                return createNode(parent, childRef, childBo);
            }
            return Objects.requireNonNull(childNode, "Child node does not exist");
        }

        private BusinessObjectNode createNode(final BusinessObjectNode parent, final RelativeBusinessObjectReference childRef, final Object childBo) {
            return new BusinessObjectNode(parent, UUID.randomUUID(), childRef, childBo, Completeness.UNKNOWN, false);
        }

        private RelativeBusinessObjectReference getRelativeBusinessObjectReference(final Object bo) {
            final RelativeBusinessObjectReference result = referenceService.getRelativeReference(bo);
            return result;
        }
    });
    return showFlowBtn;
}
Also used : Element(org.osate.aadl2.Element) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) BusinessObjectContext(org.osate.ge.BusinessObjectContext) FlowSegmentState(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.FlowSegmentState) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) IEditorPart(org.eclipse.ui.IEditorPart) ConnectionEnd(org.osate.aadl2.ConnectionEnd) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) Connection(org.osate.aadl2.Connection) UUID(java.util.UUID) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) SWT(org.eclipse.swt.SWT) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) Optional(java.util.Optional) Queue(java.util.Queue) EndToEndFlow(org.osate.aadl2.EndToEndFlow) InstanceObject(org.osate.aadl2.instance.InstanceObject) FlowSegment(org.osate.aadl2.FlowSegment) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) Feature(org.osate.aadl2.Feature) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Function(java.util.function.Function) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) HighlightableFlowInfo(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.HighlightableFlowInfo) Predicates(com.google.common.base.Predicates) FlowEnd(org.osate.aadl2.FlowEnd) LinkedList(java.util.LinkedList) Subcomponent(org.osate.aadl2.Subcomponent) Activator(org.osate.ge.internal.Activator) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ControlContribution(org.eclipse.jface.action.ControlContribution) Context(org.osate.aadl2.Context) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) FlowElement(org.osate.aadl2.FlowElement) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ComponentImplementation(org.osate.aadl2.ComponentImplementation) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) Element(org.osate.aadl2.Element) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) NamedElement(org.osate.aadl2.NamedElement) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) Feature(org.osate.aadl2.Feature) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) InstanceObject(org.osate.aadl2.instance.InstanceObject) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Subcomponent(org.osate.aadl2.Subcomponent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) List(java.util.List) LinkedList(java.util.LinkedList) Queue(java.util.Queue) EndToEndFlow(org.osate.aadl2.EndToEndFlow) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Context(org.osate.aadl2.Context) Optional(java.util.Optional) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) Connection(org.osate.aadl2.Connection) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) LinkedList(java.util.LinkedList) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionEnd(org.osate.aadl2.ConnectionEnd) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) FlowSegment(org.osate.aadl2.FlowSegment) NamedElement(org.osate.aadl2.NamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Map(java.util.Map) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) FlowEnd(org.osate.aadl2.FlowEnd)

Example 20 with EndToEndFlow

use of org.osate.aadl2.EndToEndFlow in project osate2 by osate.

the class CreateEndToEndFlowSpecificationTool method activated.

@Override
public void activated(final ActivatedEvent ctx) {
    final UiService uiService = ctx.getUiService();
    try {
        ctx.getSelectedBoc().ifPresent(selectedBoc -> {
            final AadlModificationService aadlModService = ctx.getAadlModificatonService();
            final ColoringService coloringService = ctx.getColoringService();
            // Check for existing errors and warnings
            final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
            // Do not allow tool activation if there are errors in the models
            final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
            if (!errors.isEmpty()) {
                Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create End-To-End", errors).open());
            } else {
                // Create a coloring object that will allow adjustment of pictogram
                coloring = coloringService.adjustColors();
                // Create and update based on current selection
                createFlowDialog.create();
                if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
                    update(Collections.singletonList(selectedBoc));
                } else {
                    final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
                    while (segmentIt.hasNext()) {
                        final SegmentData segmentData = segmentIt.next();
                        setColor(segmentData, Color.MAGENTA.darker());
                    }
                    for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
                    }
                    update();
                }
                if (createFlowDialog.open() == Window.OK && createFlowDialog != null) {
                    createFlowDialog.getFlow().ifPresent(endToEndFlow -> {
                        if (createFlowDialog.eteFlowToEdit != null) {
                            // Editing end to end flow
                            final EndToEndFlow endToEndFlowToEdit = (EndToEndFlow) createFlowDialog.eteFlowToEdit;
                            aadlModService.modify(endToEndFlowToEdit, eTEFlowToEdit -> {
                                eTEFlowToEdit.getAllFlowSegments().clear();
                                eTEFlowToEdit.getAllFlowSegments().addAll(endToEndFlow.getAllFlowSegments());
                                eTEFlowToEdit.setName(endToEndFlow.getName());
                                eTEFlowToEdit.getInModeOrTransitions().clear();
                                eTEFlowToEdit.getInModeOrTransitions().addAll(endToEndFlow.getInModeOrTransitions());
                            });
                        } else {
                            // Creating end to end flow
                            createFlowDialog.getOwnerComponentImplementation().ifPresent(ownerCi -> {
                                aadlModService.modify(ownerCi, ci -> {
                                    ci.getOwnedEndToEndFlows().add(endToEndFlow);
                                    ci.setNoFlows(false);
                                });
                            });
                        }
                    });
                }
            }
        });
    } finally {
        uiService.deactivateActiveTool();
    }
}
Also used : EndToEndFlow(org.osate.aadl2.EndToEndFlow) UiService(org.osate.ge.internal.services.UiService) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ColoringService(org.osate.ge.internal.services.ColoringService)

Aggregations

EndToEndFlow (org.osate.aadl2.EndToEndFlow)16 EndToEndFlowSegment (org.osate.aadl2.EndToEndFlowSegment)7 FlowSpecification (org.osate.aadl2.FlowSpecification)6 NamedElement (org.osate.aadl2.NamedElement)6 ComponentImplementation (org.osate.aadl2.ComponentImplementation)5 Connection (org.osate.aadl2.Connection)5 EndToEndFlowElement (org.osate.aadl2.EndToEndFlowElement)5 FlowSegment (org.osate.aadl2.FlowSegment)5 FlowElement (org.osate.aadl2.FlowElement)4 List (java.util.List)3 Optional (java.util.Optional)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Button (org.eclipse.swt.widgets.Button)3 ConnectedElement (org.osate.aadl2.ConnectedElement)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 BasicEList (org.eclipse.emf.common.util.BasicEList)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2