2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
;
12 import java
.util
.HashSet
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.IEditorReference
;
21 import org
.eclipse
.ui
.IPageLayout
;
22 import org
.eclipse
.ui
.IViewPart
;
23 import org
.eclipse
.ui
.PartInitException
;
25 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
32 public class EditorUtil
extends AbstractUtility
{
34 private static boolean isSaving
= false;
36 private static IViewPart view
;
38 public static boolean closeAll() {
39 for (IEditorPart editor
: getOpenEditors()) {
40 if (!getActivePage().closeEditor(editor
, true)) {
48 * Close the given editor.
50 * @param editor The <tt>MultipageTaxonEditor</tt> to close.
51 * @return <tt>true</tt> on success
53 public static boolean close(MultiPageTaxonEditor editor
) {
54 return getActivePage().closeEditor(editor
, true);
58 * Opens a new editor window with the given input
63 * @throws PartInitException
65 private static IEditorPart
open(IEditorInput input
, String editorId
)
66 throws PartInitException
{
67 return getActivePage().openEditor(input
, editorId
);
72 * Taxon Editors may be opened by supplying a taxon uuid only.
73 * Session gets initialised here and is passed to the editor
75 * @param taxonNodeUuid
77 * @throws PartInitException
79 public static IEditorPart
open(UUID taxonNodeUuid
) throws PartInitException
{
80 IEditorInput input
= TaxonEditorInput
.NewInstance(taxonNodeUuid
);
81 return open(input
, MultiPageTaxonEditor
.ID
);
85 * An uninitialized taxon is one that hasn't been saved yet. As such, it should appear in neither
86 * the list of recent names nor in the taxonomic tree when opened.
88 * @param parentTaxon The UUID of the parental taxon or <code>null</code> if this is
89 * supposed to be a root taxon.
90 * @return The EditorPart.
91 * @throws PartInitException
93 public static IEditorPart
openEmpty(UUID parentNodeUuid
) throws PartInitException
{
94 TaxonEditorInput input
= TaxonEditorInput
.NewEmptyInstance(parentNodeUuid
);
95 return open(input
, MultiPageTaxonEditor
.ID
);
98 public static void setSaving(boolean isSaving
) {
99 EditorUtil
.isSaving
= isSaving
;
102 public static boolean isSaving() {
107 * Returns a set of all currently open
108 * <code>MultiPageTaxonEditor</code>s.
112 public static Set
<IEditorPart
> getOpenEditors() {
113 Set
<IEditorPart
> taxonEditors
= new HashSet
<IEditorPart
>();
115 if(getActivePage() != null){
116 for (IEditorReference reference
: getActivePage().getEditorReferences()) {
117 IEditorPart editor
= reference
.getEditor(false);
118 if (editor
instanceof MultiPageTaxonEditor
) {
119 taxonEditors
.add(editor
);
128 * Returns the currently active taxon editor
130 * @return the taxon editor that has focus
132 public static MultiPageTaxonEditor
getActiveEditor(){
133 IEditorPart editorPart
= getActivePage().getActiveEditor();
134 if(editorPart
instanceof MultiPageTaxonEditor
){
135 MultiPageTaxonEditor editor
= (MultiPageTaxonEditor
) editorPart
;
136 editor
.getConversationHolder().bind();
142 public static AbstractTaxonEditor
getActiveEditorPage(Page page
){
143 MultiPageTaxonEditor editor
= getActiveEditor();
145 return editor
.getPage(page
);
148 public static IUndoContext
getUndoContext(MultiPageTaxonEditor editor
){
149 return editor
.getUndoContext();
152 public static IUndoContext
getUndoContext() {
153 return IOperationHistory
.GLOBAL_UNDO_CONTEXT
;
156 public static void showPropertySheet() {
157 if (getActivePage() == null) {
161 view
= getActivePage().showView(IPageLayout
.ID_PROP_SHEET
);
162 } catch (PartInitException e
) {
163 // TODO Auto-generated catch block
168 public static void checkHidePropertySheet() {
169 if (getOpenEditors().size() == 0) {
170 if (view
!= null && getActivePage() != null) {
171 getActivePage().hideView(view
);