Search in sources :

Example 16 with DiagramElement

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

the class FlowToolUtil method createSegmentData.

/**
 * Creates a {@link SegmentData} instance for a flow end. The referenced {@link BusinessObjectContext} will be a {@link DiagramElement} if the flow end is in the diagram.
 * Otherwise, it will be an instance of a private implementation.
 * @return the new {@link SegmentData} instance. Will not return null.
 */
public static SegmentData createSegmentData(final ReferenceBuilderService referenceBuilder, final DiagramElement container, final FlowEnd flowEnd) {
    final DiagramElement tmp;
    if (flowEnd.getContext() == null) {
        tmp = container;
    } else {
        tmp = container.getChildByRelativeReference(referenceBuilder.getRelativeReference(flowEnd.getContext()));
        if (tmp == null) {
            return new SegmentData(new ChildlessBusinessObjectContext(new ChildlessBusinessObjectContext(container, flowEnd.getContext()), flowEnd.getFeature()));
        }
    }
    final DiagramElement flowEndDiagramElement = tmp.getChildByRelativeReference(referenceBuilder.getRelativeReference(flowEnd.getFeature()));
    if (flowEndDiagramElement == null) {
        return new SegmentData(new ChildlessBusinessObjectContext(tmp, flowEnd.getFeature()));
    }
    return new SegmentData(flowEndDiagramElement);
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData)

Example 17 with DiagramElement

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

the class FlowToolUtil method createSegmentData.

/**
 * Creates a {@link SegmentData} instance for an end to end flow segment. The referenced {@link BusinessObjectContext} will be a {@link DiagramElement} if the flow segment is in the diagram.
 * Otherwise, it will be an instance of a private implementation.
 * @return the new {@link SegmentData} instance. Will not return null.
 */
public static SegmentData createSegmentData(final ReferenceBuilderService referenceBuilder, final DiagramElement container, final EndToEndFlowSegment seg) {
    final DiagramElement tmp;
    if (seg.getContext() == null) {
        tmp = container;
    } else {
        tmp = container.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getContext()));
        if (tmp == null) {
            return new SegmentData(new ChildlessBusinessObjectContext(new ChildlessBusinessObjectContext(container, seg.getContext()), seg.getFlowElement()));
        }
    }
    if (seg.getFlowElement() instanceof EndToEndFlow) {
        final List<DiagramElement> highlightableSegments = new ArrayList<>();
        findSegmentDiagramElements((EndToEndFlow) AgeAadlUtil.getRootRefinedElement(seg.getFlowElement()), tmp, highlightableSegments);
        return new SegmentData(new ChildlessBusinessObjectContext(tmp, seg.getFlowElement()), highlightableSegments);
    } else {
        final DiagramElement flowElementDiagramElement = tmp.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getFlowElement()));
        if (flowElementDiagramElement == null) {
            return new SegmentData(new ChildlessBusinessObjectContext(tmp, seg.getFlowElement()));
        }
        return new SegmentData(flowElementDiagramElement);
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) EndToEndFlow(org.osate.aadl2.EndToEndFlow) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData) ArrayList(java.util.ArrayList)

Example 18 with DiagramElement

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

the class AgeBusinessObjectSelectionAdapterFactory method getAdapter.

@Override
public <T> T getAdapter(final Object adaptableObject, final Class<T> adapterType) {
    final ISelection selection = (ISelection) adaptableObject;
    if (BusinessObjectSelection.class.equals(adapterType)) {
        final Bundle bundle = FrameworkUtil.getBundle(getClass());
        final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
        final AadlModificationService modificationService = context.get(AadlModificationService.class);
        if (modificationService == null) {
            return null;
        }
        return adapterType.cast(new UiBusinessObjectSelection(SelectionUtil.getSelectedBusinessObjectContexts(selection), modificationService));
    } else if (IAadlPropertySource.class.equals(adapterType) && adaptableObject instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) adaptableObject;
        if (ss.getFirstElement() instanceof DiagramElement) {
            final DiagramElement de = (DiagramElement) ss.getFirstElement();
            // If the business object is an AADL Named Element
            if (de.getBusinessObject() instanceof NamedElement) {
                final NamedElement namedElement = (NamedElement) de.getBusinessObject();
                return adapterType.cast(new IAadlPropertySource() {

                    private final IXtextDocument document = AgeXtextUtil.getDocumentByRootElement(namedElement.getElementRoot());

                    private final NamedElement element = namedElement;

                    @Override
                    public IXtextDocument getDocument() {
                        return document;
                    }

                    @Override
                    public NamedElement getNamedElement() {
                        return element;
                    }
                });
            }
        }
    }
    return null;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) UiBusinessObjectSelection(org.osate.ge.ui.UiBusinessObjectSelection) Bundle(org.osgi.framework.Bundle) ISelection(org.eclipse.jface.viewers.ISelection) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IAadlPropertySource(org.osate.xtext.aadl2.ui.propertyview.IAadlPropertySource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NamedElement(org.osate.aadl2.NamedElement) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 19 with DiagramElement

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

the class NoteReferenceHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final NoteReference noteReference = boc.getBusinessObject(NoteReference.class).orElseThrow();
    // Require the note reference's parent to be a note. This prevents being able to paste a note reference into other objects.
    if (boc.getParent() == null || !(boc.getParent().getBusinessObject() instanceof Note)) {
        return Optional.empty();
    }
    // Try to get the referenced element
    final DiagramElement referencedElement = ctx.getDiagram().findElementById(noteReference.getReferencedDiagramElementId());
    if (referencedElement == null) {
        return Optional.empty();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).source(boc.getParent()).destination(referencedElement).style(style).build());
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) NoteReference(org.osate.ge.internal.model.NoteReference) Note(org.osate.ge.internal.model.Note) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 20 with DiagramElement

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

the class DiagramElementUtil method getUndockedDiagramElement.

/**
 * Finds the first undocked diagram element by checking the specified node and then its ancestors
 * @param n the diagram node which is the first node to check.
 * @return the first diagram element without a specified dock area. Returns null if a {@link DiagramNode} which is not a {@link DiagramElement} is encountered.
 * @see DiagramElement#getDockArea()
 */
public static DiagramElement getUndockedDiagramElement(DiagramNode n) {
    while (n instanceof DiagramElement) {
        final DiagramElement e = ((DiagramElement) n);
        if (e.getDockArea() == null) {
            return e;
        }
        n = e.getParent();
    }
    return null;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement)

Aggregations

DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)131 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)45 List (java.util.List)31 Point (org.osate.ge.graphics.Point)29 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)29 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)26 Objects (java.util.Objects)25 IEditorPart (org.eclipse.ui.IEditorPart)23 ArrayList (java.util.ArrayList)22 Collectors (java.util.stream.Collectors)22 BusinessObjectContext (org.osate.ge.BusinessObjectContext)21 Collection (java.util.Collection)19 Collections (java.util.Collections)18 Dimension (org.osate.ge.graphics.Dimension)18 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)18 Optional (java.util.Optional)16 AgeConnection (org.osate.ge.graphics.internal.AgeConnection)16 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)16 ElkPort (org.eclipse.elk.graph.ElkPort)14 Node (javafx.scene.Node)13