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
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyGraphEditor
;
24 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
25 import eu
.etaxonomy
.taxeditor
.model
.DataChangeBridge
;
26 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkableSelectionProvider
;
27 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
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().commit(true);
66 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
69 public void doSaveAs() {
76 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
79 public boolean isSaveAsAllowed() {
87 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
88 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
91 public void update(CdmDataChangeMap map
) {
92 if(dataChangeBehavior
== null){
93 dataChangeBehavior
= new KeyEditorDataChangeBehaviour(this);
95 DataChangeBridge
.handleDataChange(map
, dataChangeBehavior
);
102 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
106 public ConversationHolder
getConversationHolder() {
114 * eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
118 public void changed(Object element
) {
119 editorDirtyStateChanged();
120 IEditorPart activeEditor
= getActiveEditor();
121 if (activeEditor
instanceof IDirtyMarkableSelectionProvider
) {
122 ((IDirtyMarkableSelectionProvider
) activeEditor
).changed(element
);
129 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
132 public void editorDirtyStateChanged() {
134 super.editorDirtyStateChanged();
138 protected void handlePropertyChange(int propertyId
) {
139 if (propertyId
== PROP_DIRTY
) {
142 super.handlePropertyChange(propertyId
);
145 private void setDirty(boolean dirty
) {
147 firePropertyChange(PROP_DIRTY
);
153 * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
156 public boolean isDirty() {
163 * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
166 public void dispose() {
167 conversation
.unregisterForDataStoreChanges(this);
168 conversation
.close();
175 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
178 protected void addPages() {
179 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
180 conversation
= input
.getConversationHolder();
181 conversation
.registerForDataStoreChanges(this);
184 addPage(0, new PolytomousKeyListEditor(this), input
);
185 setPageText(0, "List");
186 addPage(1, new PolytomousKeyGraphEditor(this), input
);
187 setPageText(1, "Graph");
188 } catch (PartInitException e
) {
189 EditorUtil
.error(getClass(), e
);
201 public void setPartName() {
202 AbstractIdentificationEditorInput input
= (AbstractIdentificationEditorInput
) getEditorInput();
203 PolytomousKey key
= (PolytomousKey
) input
.getKey();
204 setPartName(key
.getTitleCache());