Java 类org.eclipse.ui.IReusableEditor 实例源码

项目:eclipse-utility    文件:OpenComparablesHandler.java   
private void openInCompare(ITypedElement ancestor, ITypedElement left,
        ITypedElement right) {
    IWorkbenchPage workBenchPage = getTargetPage();
    CompareEditorInput input = new SaveablesCompareEditorInput(ancestor,
            left, right, workBenchPage);
    IEditorPart editor = CompareRevisionAction.findReusableCompareEditor(
            input, workBenchPage);
    if (editor != null) {
        IEditorInput otherInput = editor.getEditorInput();
        if (otherInput.equals(input)) {
            // simply provide focus to editor
            workBenchPage.activate(editor);
        } else {
            // if editor is currently not open on that input either re-use
            // existing
            CompareUI.reuseCompareEditor(input, (IReusableEditor) editor);
            workBenchPage.activate(editor);
        }
    } else {
        CompareUI.openCompareEditor(input);
    }
}
项目:Permo    文件:CompareUtil.java   
/**
 * Displays the given input in an existing compare editor, if there is already one. Otherwise, a new compare editor is
 * opened.
 * 
 * @param input
 *          the {@link GitFileDiffEditorInput} to be shown in the compare editor
 */
public static void openExistingCompareEditor(final GitFileDiffEditorInput input) {
  final IEditorPart existingEditor = findExistingCompareEditor();
  if (existingEditor != null) {
    CompareUI.reuseCompareEditor(input, (IReusableEditor) existingEditor);
    WorkbenchUtil.activePage().activate(existingEditor);
  }
  else {
    openNewCompareEditor(input);
  }
}
项目:Permo    文件:CompareUtil.java   
private static IEditorPart findExistingCompareEditor() {
  final IEditorReference[] editorRefs = WorkbenchUtil.activePage().getEditorReferences();
  for (final IEditorReference editorRef : editorRefs) {
    final IEditorPart part = editorRef.getEditor(false);
    if (part != null && part.getEditorInput() instanceof GitFileDiffEditorInput && part instanceof IReusableEditor) {
      return part;
    }
  }
  return null;
}
项目:hssd    文件:HSSDEditor.java   
private EntryEditor openEntryEditor(TreeNode en) throws PartInitException {
    final EditorInput input = new EditorInput(this, en);
    final IWorkbenchPage activePage = Helper.getActiveWBPage();
    IEditorPart editor = activePage.findEditor(input);
    if(editor != null && editor instanceof IReusableEditor) {
        editor.setFocus();
        return (EntryEditor)editor;
    }
    else {
        editor = activePage.openEditor(input, EntryEditor.ID);
        final IEditorPart entryEditor = editor;
        editor.addPropertyListener(new IPropertyListener() {

               @Override
               public void propertyChanged(Object source, int propId) {
                   if(propId == EntryEditor.PROP_DIRTY) {
                       if(entryEditor.isDirty()) {
                           markDirty();
                       }
                       firePropertyChange(PROP_DIRTY);
                   }
               }
           });

        if(editor instanceof EntryEditor) {
            ((EntryEditor)editor).initExpand();
        }

        return (EntryEditor)editor;
    }
}
项目:OpenSPIFe    文件:MultiPagePlanEditor.java   
/**
 * For each editor page, set the new input.
 * Auxiliary to setInput()
 * @param input the new editor input; may be null
 */
protected void setPageInputs(IEditorInput input) {
    for (int i = 0; i < getPageCount(); i++) {
        IEditorPart editorPart = getEditor(i);
        if (editorPart instanceof IReusableEditor) {
            ((IReusableEditor) editorPart).setInput(input);
        } else {
            // should be an illegal state since we want all of our editors to be reusable
            throw new IllegalStateException("All editors in the multi page plan editor must implement IReusableEditor");
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSearchEditorOpener.java   
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;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSearchEditorOpener.java   
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;
    }
}
项目:goclipse    文件:EditorUtils.java   
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;
}
项目:typescript.java    文件:EditorOpener.java   
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;
}
项目:Pydev    文件:EditorOpener.java   
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;
}