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
.IEditorPart
;
15 import org
.eclipse
.ui
.PartInitException
;
16 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
21 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
22 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyGraphEditor
;
23 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
24 import eu
.etaxonomy
.taxeditor
.model
.DataChangeBridge
;
25 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
26 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 * @created Mar 30, 2011
34 public class KeyEditor
extends FormEditor
implements IConversationEnabled
,
35 IDirtyMarkable
, IPartContentHasDetails
{
37 public static final String ID
= "eu.etaxonomy.taxeditor.editor.key";
39 private ConversationHolder conversation
;
41 private boolean dirty
;
43 private KeyEditorDataChangeBehaviour dataChangeBehavior
;
48 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
52 public void doSave(IProgressMonitor monitor
) {
54 monitor
.beginTask("Saving Editor", 1);
55 getConversationHolder().bind();
56 getConversationHolder().commit(true);
67 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
70 public void doSaveAs() {
77 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
80 public boolean isSaveAsAllowed() {
85 public void setFocus() {
86 getConversationHolder().bind();
93 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
94 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
97 public void update(CdmDataChangeMap map
) {
98 if(dataChangeBehavior
== null){
99 dataChangeBehavior
= new KeyEditorDataChangeBehaviour(this);
101 DataChangeBridge
.handleDataChange(map
, dataChangeBehavior
);
108 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
112 public ConversationHolder
getConversationHolder() {
120 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
124 public void changed(Object element
) {
125 editorDirtyStateChanged();
126 IEditorPart activeEditor
= getActiveEditor();
127 if (activeEditor
instanceof IDirtyMarkable
) {
128 ((IDirtyMarkable
) activeEditor
).changed(element
);
133 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
136 public void forceDirty() {
143 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
146 public void editorDirtyStateChanged() {
148 super.editorDirtyStateChanged();
152 protected void handlePropertyChange(int propertyId
) {
153 if (propertyId
== PROP_DIRTY
) {
156 super.handlePropertyChange(propertyId
);
159 private void setDirty(boolean dirty
) {
161 firePropertyChange(PROP_DIRTY
);
167 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
170 public boolean isDirty() {
177 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
180 public void dispose() {
181 conversation
.unregisterForDataStoreChanges(this);
182 conversation
.close();
189 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
192 protected void addPages() {
193 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
194 conversation
= input
.getConversationHolder();
195 conversation
.registerForDataStoreChanges(this);
198 addPage(0, new PolytomousKeyListEditor(this), input
);
199 setPageText(0, "List");
200 addPage(1, new PolytomousKeyGraphEditor(this), input
);
201 setPageText(1, "Graph");
202 } catch (PartInitException e
) {
203 MessagingUtils
.error(getClass(), e
);
215 public void setPartName() {
216 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
217 PolytomousKey key
= (PolytomousKey
) input
.getKey();
218 setPartName(key
.getTitleCache());