Search in sources :

Example 1 with IReusableEditor

use of org.eclipse.ui.IReusableEditor in project eclipse.platform.text by eclipse.

the class EditorOpener method showWithReuse.

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;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IReusableEditor(org.eclipse.ui.IReusableEditor) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IReusableEditor (org.eclipse.ui.IReusableEditor)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1