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;
}
Aggregations