| Summary: | Add generic implementation of IURIEditorOpener | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Moritz Eysholdt <moritz.eysholdt> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | sebastian.zarnekow |
| Version: | 1.0.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
See org.eclipse.xtext.ui.ecore.EcoreEditorOpener as an example. Requested via bug 522520. -M. Requested via bug 522520. -M. |
For people that implement a language for Xtext's index that is not based on a Xtext grammar, IResourceUIServiceProvider requires them to supply a URIOpener. It would be good to have a generic default implementation for non-Xtext editors. For example, the one below. GlobalURIEditorOpener is not suitable since there are cases where it delegates to the global URI opener and thereby creates a stack overflow. /* * partly copied from org.eclipse.xtext.ui.editor.GlobalURIEditorOpener */ public class DefaultURIEditorOperner implements IURIEditorOpener { private static final Logger logger = Logger.getLogger(DefaultURIEditorOperner.class); public IEditorPart open(URI uri, boolean select) { return openDefaultEditor(uri, null, -1, select); } public IEditorPart open(URI referenceOwnerURI, EReference reference, int indexInList, boolean select) { return openDefaultEditor(referenceOwnerURI, reference, indexInList, select); } protected IEditorPart openDefaultEditor(URI uri, EReference crossReference, int indexInList, boolean select) { Iterator<IStorage> storages = Access.getIStorage2UriMapper().get().getStorages(uri.trimFragment()).iterator(); if (storages != null && storages.hasNext()) { try { IStorage storage = storages.next(); IEditorPart editor = null; if (storage instanceof IFile) { editor = openDefaultEditor((IFile) storage); } else { editor = openDefaultEditor(storage, uri); } return editor; } catch (WrappedException e) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); } catch (PartInitException partInitException) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); } } return null; } protected IEditorPart openDefaultEditor(IFile file) throws PartInitException { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return IDE.openEditor(page, file); } protected IEditorPart openDefaultEditor(IStorage storage, URI uri) throws PartInitException { XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(storage); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return IDE.openEditor(page, editorInput, PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(uri.lastSegment()).getId()); } }