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
.IDirtyMarkableSelectionProvider
;
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 IDirtyMarkableSelectionProvider
, 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 IDirtyMarkableSelectionProvider
) {
128 ((IDirtyMarkableSelectionProvider
) activeEditor
).changed(element
);
135 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
138 public void editorDirtyStateChanged() {
140 super.editorDirtyStateChanged();
144 protected void handlePropertyChange(int propertyId
) {
145 if (propertyId
== PROP_DIRTY
) {
148 super.handlePropertyChange(propertyId
);
151 private void setDirty(boolean dirty
) {
153 firePropertyChange(PROP_DIRTY
);
159 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
162 public boolean isDirty() {
169 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
172 public void dispose() {
173 conversation
.unregisterForDataStoreChanges(this);
174 conversation
.close();
181 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
184 protected void addPages() {
185 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
186 conversation
= input
.getConversationHolder();
187 conversation
.registerForDataStoreChanges(this);
190 addPage(0, new PolytomousKeyListEditor(this), input
);
191 setPageText(0, "List");
192 addPage(1, new PolytomousKeyGraphEditor(this), input
);
193 setPageText(1, "Graph");
194 } catch (PartInitException e
) {
195 MessagingUtils
.error(getClass(), e
);
207 public void setPartName() {
208 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
209 PolytomousKey key
= (PolytomousKey
) input
.getKey();
210 setPartName(key
.getTitleCache());