Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317968 - Add generic implementation of IURIEditorOpener
Summary: Add generic implementation of IURIEditorOpener
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-25 09:15 EDT by Moritz Eysholdt CLA
Modified: 2017-10-31 11:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Moritz Eysholdt CLA 2010-06-25 09:15:28 EDT
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());
	}

}
Comment 1 Sven Efftinge CLA 2012-11-14 04:13:36 EST
See org.eclipse.xtext.ui.ecore.EcoreEditorOpener as an example.
Comment 2 Eclipse Webmaster CLA 2017-10-31 11:05:35 EDT
Requested via bug 522520.

-M.
Comment 3 Eclipse Webmaster CLA 2017-10-31 11:16:52 EDT
Requested via bug 522520.

-M.