org.eclipse.ui.IReusableEditor Java Examples
The following examples show how to use
org.eclipse.ui.IReusableEditor.
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: JavaSearchEditorOpener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IEditorPart showInEditor(IWorkbenchPage page, IEditorInput input, String editorId) { IEditorPart editor= page.findEditor(input); if (editor != null) { page.bringToTop(editor); return editor; } IEditorReference reusedEditorRef= fReusedEditor; if (reusedEditorRef != null) { boolean isOpen= reusedEditorRef.getEditor(false) != null; boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType= reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor= null; } else { editor= reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); return editor; } } } } // could not reuse try { editor= page.openEditor(input, editorId, false); if (editor instanceof IReusableEditor) { IEditorReference reference= (IEditorReference) page.getReference(editor); fReusedEditor= reference; } else { fReusedEditor= null; } return editor; } catch (PartInitException ex) { MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), SearchMessages.Search_Error_openEditor_title, SearchMessages.Search_Error_openEditor_message); return null; } }
Example #2
Source File: EditorUtils.java From goclipse with Eclipse Public License 1.0 | 5 votes |
public static ITextEditor openTextEditor(ITextEditor currentEditor, String editorId, IEditorInput newInput, OpenNewEditorMode openNewEditor) throws PartInitException, CoreException { IWorkbenchPage page; if(currentEditor == null) { page = WorkbenchUtils.getActivePage(); openNewEditor = OpenNewEditorMode.ALWAYS; } else { page = currentEditor.getEditorSite().getWorkbenchWindow().getActivePage(); } if(openNewEditor == OpenNewEditorMode.NEVER) { if(currentEditor.getEditorInput().equals(newInput)) { return currentEditor; } else if(currentEditor instanceof IReusableEditor) { IReusableEditor reusableEditor = (IReusableEditor) currentEditor; reusableEditor.setInput(newInput); return currentEditor; } else { openNewEditor = OpenNewEditorMode.ALWAYS; } } int matchFlags = openNewEditor == OpenNewEditorMode.ALWAYS ? IWorkbenchPage.MATCH_NONE : IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID; IEditorPart editor = page.openEditor(newInput, editorId, true, matchFlags); ITextEditor targetEditor = tryCast(editor, ITextEditor.class); if(targetEditor == null) { throw EclipseCore.createCoreException("Not a text editor", null); } return targetEditor; }
Example #3
Source File: EditorOpener.java From typescript.java with MIT License | 4 votes |
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException { IEditorInput input= new FileEditorInput(file); IEditorPart editor= page.findEditor(input); if (editor != null) { page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } IEditorReference reusedEditorRef= fReusedEditor; if (reusedEditorRef != null) { boolean isOpen= reusedEditorRef.getEditor(false) != null; boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType= reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor= null; } else { editor= reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } } } } editor= page.openEditor(input, editorId, activate); if (editor instanceof IReusableEditor) { IEditorReference reference= (IEditorReference) page.getReference(editor); fReusedEditor= reference; } else { fReusedEditor= null; } return editor; }
Example #4
Source File: EditorOpener.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException { IEditorInput input = new FileEditorInput(file); IEditorPart editor = page.findEditor(input); if (editor != null) { page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } IEditorReference reusedEditorRef = fReusedEditor; if (reusedEditorRef != null) { boolean isOpen = reusedEditorRef.getEditor(false) != null; boolean canBeReused = isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned(); if (canBeReused) { boolean showsSameInputType = reusedEditorRef.getId().equals(editorId); if (!showsSameInputType) { page.closeEditors(new IEditorReference[] { reusedEditorRef }, false); fReusedEditor = null; } else { editor = reusedEditorRef.getEditor(true); if (editor instanceof IReusableEditor) { ((IReusableEditor) editor).setInput(input); page.bringToTop(editor); if (activate) { page.activate(editor); } return editor; } } } } editor = page.openEditor(input, editorId, activate); if (editor instanceof IReusableEditor) { IEditorReference reference = (IEditorReference) page.getReference(editor); fReusedEditor = reference; } else { fReusedEditor = null; } return editor; }