@Override public IResource getLaunchableResource(IEditorPart editorpart) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editorpart); if (xtextEditor != null) { return xtextEditor.getResource(); } return null; }
protected XtextEditor openEditor(IFile file) throws Exception { IEditorPart openEditor = openEditor(file, getEditorId()); XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { return xtextEditor; } else if (openEditor instanceof ErrorEditorPart) { Field field = openEditor.getClass().getDeclaredField("error"); field.setAccessible(true); throw new IllegalStateException("Couldn't open the editor.",((Status)field.get(openEditor)).getException()); } else { fail("Opened Editor with id:" + getEditorId() + ", is not an XtextEditor"); } return null; }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = findEObjectByURI(uri, resource); if (object != null) { ITextRegion location = (crossReference != null) ? locationProvider .getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } } }); } }
protected XtextEditor openEditor(IFile file) throws Exception { IEditorPart openEditor = openEditor(file, getEditorId()); XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { ISourceViewer sourceViewer = xtextEditor.getInternalSourceViewer(); ((ProjectionViewer)sourceViewer).doOperation(ProjectionViewer.EXPAND_ALL); return xtextEditor; } else if (openEditor instanceof ErrorEditorPart) { Field field = openEditor.getClass().getDeclaredField("error"); field.setAccessible(true); throw new IllegalStateException("Couldn't open the editor.",((Status)field.get(openEditor)).getException()); } else { fail("Opened Editor with id:" + getEditorId() + ", is not an XtextEditor"); } return null; }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { if (uri.fragment() != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = resource.getEObject(uri.fragment()); ITextRegion location = (crossReference != null) ? locationProvider.getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } }); } } }
public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) { Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator(); if (storages != null && storages.hasNext()) { try { IStorage storage = storages.next().getFirst(); // TODO we should create a JarEntryEditorInput if storage is a NonJavaResource from jdt to match the editor input used when double clicking on the same resource in a jar. IEditorInput editorInput = (storage instanceof IFile) ? new FileEditorInput((IFile) storage) : new XtextReadonlyEditorInput(storage); IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID); 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; }
@Override public void launch(IEditorPart editor, String mode) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editor); final ISelection selection = xtextEditor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { final ITextSelection sel = (ITextSelection) selection; final EObject obj = xtextEditor.getDocument().readOnly(resource -> { final IParseResult parseRes = resource.getParseResult(); if (parseRes == null) { return null; } final ICompositeNode rootNode = parseRes.getRootNode(); final ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, sel.getOffset()); return NodeModelUtils.findActualSemanticObjectFor(node); }); if (obj != null) { final EObject elt = EcoreUtil2.getContainerOfType(obj, getValidEObjectType()); if (elt != null) { searchAndLaunch(mode, elt); return; } } } else if (selection != null) { launch(selection, mode); return; } // Default launching searchAndLaunch(mode, xtextEditor.getResource()); }