Java Code Examples for org.eclipse.xtext.ui.editor.utils.EditorUtils#createEditorInput()

The following examples show how to use org.eclipse.xtext.ui.editor.utils.EditorUtils#createEditorInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: N4JSResourceLinkHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {
	if (null != selection && !selection.isEmpty()) {
		final Object firstElement = selection.getFirstElement();
		if (firstElement instanceof ResourceNode) {
			SafeURI<?> nodeLocation = ((ResourceNode) firstElement).getLocation();
			if (nodeLocation.isFile()) {
				final URI uri = nodeLocation.toURI();
				final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri));
				final IEditorPart editor = page.findEditor(editorInput);
				if (null != editor) {
					page.bringToTop(editor);
				} else {
					languageSpecificURIEditorOpener.open(uri, true);
				}
				return;
			}
		}
	}
	super.activateEditor(page, selection);
}
 
Example 2
Source File: LanguageSpecificURIEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
	Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
	if (storages != null && storages.hasNext()) {
		try {
			IStorage storage = storages.next().getFirst();
			IEditorInput editorInput = EditorUtils.createEditorInput(storage);
			IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
			final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
			selectAndReveal(editor, uri, crossReference, indexInList, select);
			return EditorUtils.getXtextEditor(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;
}
 
Example 3
Source File: StorageBasedTextEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void open(IWorkbenchPage page) {
	try {
		IEditorInput input = EditorUtils.createEditorInput(storage);
		IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(storage.getName());
		IEditorPart opened = IDE.openEditor(page, input, editorDescriptor.getId());
		if (region != null && opened instanceof ITextEditor) {
			ITextEditor openedTextEditor = (ITextEditor) opened;
			openedTextEditor.selectAndReveal(region.getOffset(), region.getLength());
		}
	} catch (PartInitException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
Example 4
Source File: XbaseEditorInputRedirector.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IEditorInput findOriginalSource(IEditorInput input) {
	IFile resource = ResourceUtil.getFile(input);
	if (resource == null) {
		return input;
	}

	IEditorInput original = findOriginalSourceForOuputFolderCopy(input);
	if (original != input) {
		return original;
	}

	IEclipseTrace trace = traceInformation.getTraceToSource(resource);
	if (trace == null) {
		return input;
	}

	for (ILocationInEclipseResource candidate : trace.getAllAssociatedLocations()) {
		if (languageInfo.equals(candidate.getLanguage())) {
			IStorage storage = candidate.getPlatformResource();
			if (storage != null) {
				return EditorUtils.createEditorInput(storage);
			}
		}
	}

	return input;
}
 
Example 5
Source File: GlobalURIEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected IEditorPart openDefaultEditor(IStorage storage, URI uri) throws PartInitException {
	IEditorInput editorInput = EditorUtils.createEditorInput(storage); 
	IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage();
	return IDE.openEditor(page, editorInput, PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(
			uri.lastSegment()).getId());
}