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