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);
}
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);
}
}
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;
}
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());
}
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;
}
Aggregations