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
.application
.CdmApplicationState
;
21 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
;
22 import eu
.etaxonomy
.cdm
.api
.application
.ICdmChangeListener
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
28 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyEditorInput
;
29 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyGraphEditor
;
30 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
31 import eu
.etaxonomy
.taxeditor
.model
.DataChangeBridge
;
32 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
33 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
38 * @created Mar 30, 2011
41 public class KeyEditor
extends FormEditor
implements IConversationEnabled
,
42 IDirtyMarkable
, IPartContentHasDetails
, ICdmChangeListener
{
44 public static final String ID
= "eu.etaxonomy.taxeditor.editor.key";
46 private ConversationHolder conversation
;
48 private boolean dirty
;
50 private KeyEditorDataChangeBehaviour dataChangeBehavior
;
52 private PolytomousKeyEditorInput polytomousKeyEditorInput
;
57 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
58 * org.eclipse.ui.IEditorInput)
61 public void init(IEditorSite site
, IEditorInput input
)
62 throws PartInitException
{
63 polytomousKeyEditorInput
= (PolytomousKeyEditorInput
)input
;
64 CdmApplicationState
.getCurrentDataChangeService().register(this);
65 super.init(site
, input
);
71 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
75 public void doSave(IProgressMonitor monitor
) {
77 monitor
.beginTask("Saving Editor", 1);
78 getConversationHolder().bind();
79 getConversationHolder().commit(true);
80 polytomousKeyEditorInput
.merge();
91 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
94 public void doSaveAs() {
101 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
104 public boolean isSaveAsAllowed() {
109 public void setFocus() {
110 getConversationHolder().commit(true);
111 getConversationHolder().bind();
112 polytomousKeyEditorInput
.bind();
119 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
120 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
123 public void update(CdmDataChangeMap map
) {
124 if(dataChangeBehavior
== null){
125 dataChangeBehavior
= new KeyEditorDataChangeBehaviour(this);
127 DataChangeBridge
.handleDataChange(map
, dataChangeBehavior
);
134 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
138 public ConversationHolder
getConversationHolder() {
146 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
150 public void changed(Object element
) {
151 editorDirtyStateChanged();
152 IEditorPart activeEditor
= getActiveEditor();
153 if (activeEditor
instanceof IDirtyMarkable
) {
154 ((IDirtyMarkable
) activeEditor
).changed(element
);
159 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
162 public void forceDirty() {
169 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
172 public void editorDirtyStateChanged() {
174 super.editorDirtyStateChanged();
178 protected void handlePropertyChange(int propertyId
) {
179 if (propertyId
== PROP_DIRTY
) {
182 super.handlePropertyChange(propertyId
);
185 private void setDirty(boolean dirty
) {
187 firePropertyChange(PROP_DIRTY
);
193 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
196 public boolean isDirty() {
203 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
206 public void dispose() {
207 conversation
.unregisterForDataStoreChanges(this);
208 conversation
.close();
209 polytomousKeyEditorInput
.dispose();
210 CdmApplicationState
.getCurrentDataChangeService().unregister(this);
217 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
220 protected void addPages() {
221 conversation
= polytomousKeyEditorInput
.getConversationHolder();
222 conversation
.registerForDataStoreChanges(this);
225 addPage(0, new PolytomousKeyListEditor(this), polytomousKeyEditorInput
);
226 setPageText(0, "List");
227 addPage(1, new PolytomousKeyGraphEditor(this), polytomousKeyEditorInput
);
228 setPageText(1, "Graph");
229 } catch (PartInitException e
) {
230 MessagingUtils
.error(getClass(), e
);
242 public void setPartName() {
243 PolytomousKey key
= polytomousKeyEditorInput
.getKey();
244 setPartName(key
.getTitleCache());
248 * @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
251 public void onChange(CdmChangeEvent event
) {
252 //editorDirtyStateChanged();
253 IEditorPart activeEditor
= getActiveEditor();
254 if (activeEditor
instanceof IDirtyMarkable
) {
255 for(CdmBase cdmBase
: event
.getChangedObjects()) {
256 ((IDirtyMarkable
) activeEditor
).changed(cdmBase
);