3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.key
;
13 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
14 import org
.eclipse
.ui
.IEditorInput
;
15 import org
.eclipse
.ui
.IEditorPart
;
16 import org
.eclipse
.ui
.IEditorSite
;
17 import org
.eclipse
.ui
.PartInitException
;
18 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
22 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
23 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
24 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyGraphEditor
;
26 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
27 import eu
.etaxonomy
.taxeditor
.model
.DataChangeBridge
;
28 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
29 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 * @created Mar 30, 2011
37 public class KeyEditor
extends FormEditor
implements IConversationEnabled
,
38 IDirtyMarkable
, IPartContentHasDetails
{
40 public static final String ID
= "eu.etaxonomy.taxeditor.editor.key";
42 private ConversationHolder conversation
;
44 private boolean dirty
;
46 private KeyEditorDataChangeBehaviour dataChangeBehavior
;
48 private PolytomousKeyEditorInput polytomousKeyEditorInput
;
53 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
54 * org.eclipse.ui.IEditorInput)
57 public void init(IEditorSite site
, IEditorInput input
)
58 throws PartInitException
{
59 polytomousKeyEditorInput
= (PolytomousKeyEditorInput
)input
;
60 super.init(site
, input
);
66 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
70 public void doSave(IProgressMonitor monitor
) {
72 monitor
.beginTask("Saving Editor", 1);
73 getConversationHolder().bind();
74 getConversationHolder().commit(true);
75 polytomousKeyEditorInput
.merge();
86 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
89 public void doSaveAs() {
96 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
99 public boolean isSaveAsAllowed() {
104 public void setFocus() {
105 getConversationHolder().bind();
106 polytomousKeyEditorInput
.bind();
113 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
114 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
117 public void update(CdmDataChangeMap map
) {
118 if(dataChangeBehavior
== null){
119 dataChangeBehavior
= new KeyEditorDataChangeBehaviour(this);
121 DataChangeBridge
.handleDataChange(map
, dataChangeBehavior
);
128 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
132 public ConversationHolder
getConversationHolder() {
140 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
144 public void changed(Object element
) {
145 editorDirtyStateChanged();
146 IEditorPart activeEditor
= getActiveEditor();
147 if (activeEditor
instanceof IDirtyMarkable
) {
148 ((IDirtyMarkable
) activeEditor
).changed(element
);
153 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
156 public void forceDirty() {
163 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
166 public void editorDirtyStateChanged() {
168 super.editorDirtyStateChanged();
172 protected void handlePropertyChange(int propertyId
) {
173 if (propertyId
== PROP_DIRTY
) {
176 super.handlePropertyChange(propertyId
);
179 private void setDirty(boolean dirty
) {
181 firePropertyChange(PROP_DIRTY
);
187 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
190 public boolean isDirty() {
197 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
200 public void dispose() {
201 conversation
.unregisterForDataStoreChanges(this);
202 conversation
.close();
203 polytomousKeyEditorInput
.dispose();
210 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
213 protected void addPages() {
214 conversation
= polytomousKeyEditorInput
.getConversationHolder();
215 conversation
.registerForDataStoreChanges(this);
218 addPage(0, new PolytomousKeyListEditor(this), polytomousKeyEditorInput
);
219 setPageText(0, "List");
220 addPage(1, new PolytomousKeyGraphEditor(this), polytomousKeyEditorInput
);
221 setPageText(1, "Graph");
222 } catch (PartInitException e
) {
223 MessagingUtils
.error(getClass(), e
);
235 public void setPartName() {
236 PolytomousKey key
= polytomousKeyEditorInput
.getKey();
237 setPartName(key
.getTitleCache());