Search in sources :

Example 26 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class DiagramUpdaterTest method beforeTest.

@Before
public void beforeTest() {
    testModel.setModel(newBO(newBO(newBO(2), newBO(4), newBO(newBO(6), newBO(8), newBO(10))), newBO(newBO(12))));
    diagram = new AgeDiagram();
    diagramUpdater = new DiagramUpdater(testModel, testModel, new SimpleActionExecutor(), testModel, testModel);
}
Also used : SimpleActionExecutor(org.osate.ge.internal.services.impl.SimpleActionExecutor) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) Before(org.junit.Before)

Example 27 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class FlowContributionItem method refresh.

void refresh() {
    final ComboViewer comboViewer = getComboViewer();
    final Map<String, HighlightableFlowInfo> highlightableFlowElements = new TreeMap<>((o1, o2) -> o1.toLowerCase().compareTo(o2.toLowerCase()));
    if (comboViewer != null) {
        final Map.Entry<String, HighlightableFlowInfo> nullMapEntry = new AbstractMap.SimpleEntry<>(getNullValueString(), new HighlightableFlowInfo(null, FlowSegmentState.COMPLETE));
        highlightableFlowElements.put(nullMapEntry.getKey(), nullMapEntry.getValue());
        Map.Entry<String, HighlightableFlowInfo> selectedValue = nullMapEntry;
        final String selectedFlowName = editor == null ? null : editor.getPartProperty(SELECTED_FLOW_PROPERTY_KEY);
        // Clear the combo box
        comboViewer.setInput(null);
        if (editor == null) {
            return;
        }
        final AgeDiagram diagram = editor.getDiagram();
        if (diagram != null) {
            final QueryService queryService = ContributionUtil.getQueryService(editor);
            if (queryService != null) {
                // Determine which flows have elements contained in the diagram and whether the flow is partial.
                queryService.getResults(FLOW_CONTAINER_QUERY, diagram, null).stream().flatMap(flowContainerQueryable -> {
                    if (flowContainerQueryable.getBusinessObject() instanceof ComponentInstance) {
                        return AadlInstanceObjectUtil.getComponentInstance(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
                    } else {
                        return AadlClassifierUtil.getComponentImplementation(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
                    }
                }).map(HighlightableFlowInfo::create).filter(Predicates.notNull()).forEachOrdered(highlightableFlowElement -> {
                    highlightableFlowElements.put(getName(highlightableFlowElement.highlightableFlowElement), highlightableFlowElement);
                });
                // Determine which value should be selected
                final Optional<Entry<String, HighlightableFlowInfo>> tmpSelectedValue = highlightableFlowElements.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(selectedFlowName)).findAny();
                if (tmpSelectedValue.isPresent()) {
                    selectedValue = tmpSelectedValue.get();
                }
                comboViewer.setInput(highlightableFlowElements.entrySet());
            }
        }
        showFlowContributionItem.updateShowFlowItem(selectedValue.getValue());
        editFlowContributionItem.updateEditFlowItem(selectedValue.getValue());
        deleteFlowContributionItem.updateDeleteFlowItem(selectedValue.getValue());
        final StructuredSelection newSelection = new StructuredSelection(selectedValue);
        if (!Objects.equal(newSelection, comboViewer.getSelection())) {
            comboViewer.setSelection(newSelection);
            onSelection(newSelection.getFirstElement());
        }
    }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SwtUtil(org.osate.ge.swt.SwtUtil) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AadlFlowSpecificationUtil(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Composite(org.eclipse.swt.widgets.Composite) ComboContributionItem(org.osate.ge.internal.ui.editor.ComboContributionItem) Map(java.util.Map) Predicates(com.google.common.base.Predicates) Subcomponent(org.osate.aadl2.Subcomponent) Objects(com.google.common.base.Objects) IEditorPart(org.eclipse.ui.IEditorPart) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Collectors(java.util.stream.Collectors) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AbstractMap(java.util.AbstractMap) Stream(java.util.stream.Stream) UiUtil(org.osate.ge.internal.ui.util.UiUtil) QueryService(org.osate.ge.services.QueryService) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Optional(java.util.Optional) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedElement(org.osate.aadl2.NamedElement) ExecutableQuery(org.osate.ge.query.ExecutableQuery) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) QueryService(org.osate.ge.services.QueryService) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Example 28 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram 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 29 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class ShowConnectedElementsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = getDiagramEditor(event);
    final List<BusinessObjectContext> selectedElements = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(boc -> isSubcomponentOrConnectionEnd(boc)).collect(Collectors.toList());
    referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
    final BusinessObjectTreeUpdater treeUpdater = editor.getBoTreeUpdater();
    final BusinessObjectNode boTree = getBoTree(editor, treeUpdater);
    for (final BusinessObjectContext selectedElement : selectedElements) {
        final BusinessObjectNode selectedNode = getSelectedNode(boTree, selectedElement);
        final Object selectedBo = selectedNode.getBusinessObject();
        if (selectedBo instanceof ConnectionEnd) {
            final SimpleEntry<Optional<ComponentClassifier>, BusinessObjectNode> classifierToConnectionEnd = getClassifierToConnectionEnd(selectedNode);
            final Optional<ComponentClassifier> compImplOpt = classifierToConnectionEnd.getKey();
            final BusinessObjectNode conEndNode = classifierToConnectionEnd.getValue();
            // Determine component implementation of selected node
            final BusinessObjectNode compNode = selectedBo instanceof Subcomponent && conEndNode == selectedNode ? selectedNode : conEndNode.getParent();
            // Internal Connections to Connection End
            compImplOpt.ifPresent(ci -> {
                if (ci instanceof ComponentImplementation) {
                    enableInternalConnections((ComponentImplementation) ci, conEndNode.getBusinessObject(), selectedBo, compNode);
                }
            });
            // Parent Connections to Connection End
            AadlClassifierUtil.getComponentImplementation(compNode.getParent()).ifPresent(ci -> {
                enableParentConnections(ci, conEndNode.getBusinessObject(), selectedBo, compNode);
            });
        }
        if (selectedBo instanceof Subcomponent) {
            final BusinessObjectNode parent = selectedNode.getParent();
            // Parent Connections to Subcomponent
            AadlClassifierUtil.getComponentImplementation(parent).ifPresent(compImpl -> enableComponentImplementationConnections(compImpl, parent, selectedNode));
            // Internal Connections to Subcomponent
            AadlClassifierUtil.getComponentImplementation(selectedBo).ifPresent(compImpl -> enableSelectedElementConnections(compImpl, selectedNode));
        } else if (selectedBo instanceof InstanceObject) {
            if (selectedBo instanceof ComponentInstance) {
                final ComponentInstance compInstance = (ComponentInstance) selectedBo;
                enableComponentInstanceConnections(compInstance, boTree);
            }
            if (selectedBo instanceof ConnectionInstanceEnd) {
                final InstanceObject selectedConnectionEnd = (InstanceObject) selectedBo;
                enableInstanceEndConnections(selectedConnectionEnd, boTree);
            }
        }
    }
    final AgeDiagram diagram = editor.getDiagram();
    final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    // Update the diagram
    editor.getActionExecutor().execute("Show Connected Elements", ExecutionMode.NORMAL, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram, boTree);
        // Update layout
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
        return null;
    });
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) Element(org.osate.aadl2.Element) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ComponentImplementation(org.osate.aadl2.ComponentImplementation) HashMap(java.util.HashMap) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) ComponentClassifier(org.osate.aadl2.ComponentClassifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Map(java.util.Map) LinkedList(java.util.LinkedList) Subcomponent(org.osate.aadl2.Subcomponent) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) SimpleEntry(java.util.AbstractMap.SimpleEntry) IEditorPart(org.eclipse.ui.IEditorPart) ConnectionEnd(org.osate.aadl2.ConnectionEnd) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) Context(org.osate.aadl2.Context) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) Connection(org.osate.aadl2.Connection) UUID(java.util.UUID) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AbstractMap(java.util.AbstractMap) List(java.util.List) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Stream(java.util.stream.Stream) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) Optional(java.util.Optional) Queue(java.util.Queue) AbstractHandler(org.eclipse.core.commands.AbstractHandler) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) ConnectedElement(org.osate.aadl2.ConnectedElement) InstanceObject(org.osate.aadl2.instance.InstanceObject) ComponentImplementation(org.osate.aadl2.ComponentImplementation) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Optional(java.util.Optional) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) InstanceObject(org.osate.aadl2.instance.InstanceObject) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionEnd(org.osate.aadl2.ConnectionEnd) BusinessObjectContext(org.osate.ge.BusinessObjectContext) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 30 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class DefaultDiagramService method createDiagram.

@Override
public void createDiagram(final IFile diagramFile, final DiagramType diagramType, final Object contextBo) {
    // Create an AgeDiagram object. This object doesn't have to be completely valid. It just needs to be able to be written.
    final AgeDiagram diagram = new AgeDiagram();
    // Build diagram configuration
    final CanonicalBusinessObjectReference contextBoCanonicalRef = contextBo == null ? null : Objects.requireNonNull(referenceService.getCanonicalReference(contextBo), "Unable to build canonical reference for business object: " + contextBo);
    diagram.modify("Configure Diagram", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagramType, true).contextBoReference(contextBoCanonicalRef).connectionPrimaryLabelsVisible(false).build()));
    final URI newDiagramUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
    DiagramSerialization.write(diagramFile.getProject(), diagram, newDiagramUri);
    try {
        diagramFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (final CoreException e) {
        throw new GraphicalEditorException(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) URI(org.eclipse.emf.common.util.URI) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Aggregations

AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)46 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)35 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)20 IEditorPart (org.eclipse.ui.IEditorPart)18 List (java.util.List)16 Objects (java.util.Objects)16 Collectors (java.util.stream.Collectors)12 BusinessObjectContext (org.osate.ge.BusinessObjectContext)12 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)11 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)10 Collections (java.util.Collections)9 Adapters (org.eclipse.core.runtime.Adapters)9 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)9 Collection (java.util.Collection)8 LinkedList (java.util.LinkedList)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 Point (org.osate.ge.graphics.Point)8 ArrayList (java.util.ArrayList)7 UiUtil (org.osate.ge.internal.ui.util.UiUtil)7