Search in sources :

Example 1 with DiagramGroup

use of org.osate.ge.internal.ui.navigator.DiagramGroup in project osate2 by osate.

the class SelectionUtil method findDiagramContextForSelectedObject.

private static Element findDiagramContextForSelectedObject(final Object selectedObject) {
    if (selectedObject instanceof IFile) {
        final String ext = ((IFile) selectedObject).getFileExtension();
        if (FileNameConstants.SOURCE_FILE_EXT.equalsIgnoreCase(ext) || FileNameConstants.INSTANCE_FILE_EXT.equalsIgnoreCase(ext)) {
            URI uri = OsateResourceUtil.toResourceURI((IFile) selectedObject);
            final EList<EObject> contents = new ResourceSetImpl().getResource(uri, true).getContents();
            if (contents != null && !contents.isEmpty()) {
                final EObject root = contents.get(0);
                if (root instanceof AadlPackage) {
                    return (AadlPackage) root;
                } else if (root instanceof ComponentInstance) {
                    return (ComponentInstance) root;
                }
            }
        }
    } else if (selectedObject instanceof DiagramGroup) {
        final DiagramGroup dg = (DiagramGroup) selectedObject;
        if (dg.isContextReferenceValid()) {
            final ReferenceService referenceService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ReferenceService.class);
            if (referenceService == null) {
                return null;
            }
            final Object bo = referenceService.getProjectReferenceService(dg.getProject()).resolve(dg.getContextReference());
            if (bo instanceof AadlPackage) {
                return (AadlPackage) bo;
            } else if (bo instanceof Classifier) {
                return (Classifier) bo;
            } else if (bo instanceof SystemInstance) {
                return (SystemInstance) bo;
            }
        }
    } else if (selectedObject instanceof Element) {
        final Classifier classifier = findClassifier((Element) selectedObject);
        if (classifier != null) {
            return classifier;
        }
        final AadlPackage pkg = findPackage((Element) selectedObject);
        if (pkg != null) {
            return pkg;
        }
    } else if (selectedObject instanceof EObjectURIWrapper) {
        final EObjectURIWrapper wrapper = (EObjectURIWrapper) selectedObject;
        final EObject eObject = new ResourceSetImpl().getEObject(wrapper.getUri(), true);
        final Classifier classifier = findClassifier(eObject);
        if (classifier != null) {
            return classifier;
        }
        final AadlPackage pkg = findPackage(eObject);
        if (pkg != null) {
            return pkg;
        }
    }
    return null;
}
Also used : ReferenceService(org.osate.ge.internal.services.ReferenceService) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) AadlPackage(org.osate.aadl2.AadlPackage) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Element(org.osate.aadl2.Element) Classifier(org.osate.aadl2.Classifier) URI(org.eclipse.emf.common.util.URI) DiagramGroup(org.osate.ge.internal.ui.navigator.DiagramGroup) SystemInstance(org.osate.aadl2.instance.SystemInstance) EObject(org.eclipse.emf.ecore.EObject) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 AadlPackage (org.osate.aadl2.AadlPackage)1 Classifier (org.osate.aadl2.Classifier)1 Element (org.osate.aadl2.Element)1 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)1 SystemInstance (org.osate.aadl2.instance.SystemInstance)1 EObjectURIWrapper (org.osate.aadl2.modelsupport.EObjectURIWrapper)1 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)1 ReferenceService (org.osate.ge.internal.services.ReferenceService)1 DiagramGroup (org.osate.ge.internal.ui.navigator.DiagramGroup)1