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().commit(true);
87 getConversationHolder().bind();
94 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
95 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
98 public void update(CdmDataChangeMap map
) {
99 if(dataChangeBehavior
== null){
100 dataChangeBehavior
= new KeyEditorDataChangeBehaviour(this);
102 DataChangeBridge
.handleDataChange(map
, dataChangeBehavior
);
109 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
113 public ConversationHolder
getConversationHolder() {
121 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
125 public void changed(Object element
) {
126 editorDirtyStateChanged();
127 IEditorPart activeEditor
= getActiveEditor();
128 if (activeEditor
instanceof IDirtyMarkable
) {
129 ((IDirtyMarkable
) activeEditor
).changed(element
);
134 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
137 public void forceDirty() {
144 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
147 public void editorDirtyStateChanged() {
149 super.editorDirtyStateChanged();
153 protected void handlePropertyChange(int propertyId
) {
154 if (propertyId
== PROP_DIRTY
) {
157 super.handlePropertyChange(propertyId
);
160 private void setDirty(boolean dirty
) {
162 firePropertyChange(PROP_DIRTY
);
168 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
171 public boolean isDirty() {
178 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
181 public void dispose() {
182 conversation
.unregisterForDataStoreChanges(this);
183 conversation
.close();
190 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
193 protected void addPages() {
194 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
195 conversation
= input
.getConversationHolder();
196 conversation
.registerForDataStoreChanges(this);
199 addPage(0, new PolytomousKeyListEditor(this), input
);
200 setPageText(0, "List");
201 addPage(1, new PolytomousKeyGraphEditor(this), input
);
202 setPageText(1, "Graph");
203 } catch (PartInitException e
) {
204 MessagingUtils
.error(getClass(), e
);
216 public void setPartName() {
217 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
218 PolytomousKey key
= (PolytomousKey
) input
.getKey();
219 setPartName(key
.getTitleCache());