1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.key;
|
12
|
|
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;
|
17
|
|
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;
|
28
|
|
29
|
/**
|
30
|
* @author n.hoffmann
|
31
|
* @created Mar 30, 2011
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class KeyEditor extends FormEditor implements IConversationEnabled,
|
35
|
IDirtyMarkableSelectionProvider, IPartContentHasDetails {
|
36
|
|
37
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.key";
|
38
|
|
39
|
private ConversationHolder conversation;
|
40
|
|
41
|
private boolean dirty;
|
42
|
|
43
|
private KeyEditorDataChangeBehaviour dataChangeBehavior;
|
44
|
|
45
|
/*
|
46
|
* (non-Javadoc)
|
47
|
*
|
48
|
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
|
49
|
* IProgressMonitor)
|
50
|
*/
|
51
|
@Override
|
52
|
public void doSave(IProgressMonitor monitor) {
|
53
|
try {
|
54
|
monitor.beginTask("Saving Editor", 1);
|
55
|
getConversationHolder().bind();
|
56
|
getConversationHolder().commit(true);
|
57
|
setDirty(false);
|
58
|
monitor.worked(1);
|
59
|
} finally {
|
60
|
monitor.done();
|
61
|
}
|
62
|
}
|
63
|
|
64
|
/*
|
65
|
* (non-Javadoc)
|
66
|
*
|
67
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
68
|
*/
|
69
|
@Override
|
70
|
public void doSaveAs() {
|
71
|
// not allowed
|
72
|
}
|
73
|
|
74
|
/*
|
75
|
* (non-Javadoc)
|
76
|
*
|
77
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
78
|
*/
|
79
|
@Override
|
80
|
public boolean isSaveAsAllowed() {
|
81
|
return false;
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public void setFocus() {
|
86
|
getConversationHolder().bind();
|
87
|
super.setFocus();
|
88
|
}
|
89
|
/*
|
90
|
* (non-Javadoc)
|
91
|
*
|
92
|
* @see
|
93
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
94
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
95
|
*/
|
96
|
@Override
|
97
|
public void update(CdmDataChangeMap map) {
|
98
|
if(dataChangeBehavior == null){
|
99
|
dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
|
100
|
}
|
101
|
DataChangeBridge.handleDataChange(map, dataChangeBehavior);
|
102
|
}
|
103
|
|
104
|
/*
|
105
|
* (non-Javadoc)
|
106
|
*
|
107
|
* @see
|
108
|
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
|
109
|
* ()
|
110
|
*/
|
111
|
@Override
|
112
|
public ConversationHolder getConversationHolder() {
|
113
|
return conversation;
|
114
|
}
|
115
|
|
116
|
/*
|
117
|
* (non-Javadoc)
|
118
|
*
|
119
|
* @see
|
120
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
121
|
* java.lang.Object)
|
122
|
*/
|
123
|
@Override
|
124
|
public void changed(Object element) {
|
125
|
editorDirtyStateChanged();
|
126
|
IEditorPart activeEditor = getActiveEditor();
|
127
|
if (activeEditor instanceof IDirtyMarkableSelectionProvider) {
|
128
|
((IDirtyMarkableSelectionProvider) activeEditor).changed(element);
|
129
|
}
|
130
|
}
|
131
|
|
132
|
/*
|
133
|
* (non-Javadoc)
|
134
|
*
|
135
|
* @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
|
136
|
*/
|
137
|
@Override
|
138
|
public void editorDirtyStateChanged() {
|
139
|
dirty = true;
|
140
|
super.editorDirtyStateChanged();
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
protected void handlePropertyChange(int propertyId) {
|
145
|
if (propertyId == PROP_DIRTY) {
|
146
|
setDirty(true);
|
147
|
}
|
148
|
super.handlePropertyChange(propertyId);
|
149
|
}
|
150
|
|
151
|
private void setDirty(boolean dirty) {
|
152
|
this.dirty = dirty;
|
153
|
firePropertyChange(PROP_DIRTY);
|
154
|
}
|
155
|
|
156
|
/*
|
157
|
* (non-Javadoc)
|
158
|
*
|
159
|
* @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
|
160
|
*/
|
161
|
@Override
|
162
|
public boolean isDirty() {
|
163
|
return dirty;
|
164
|
}
|
165
|
|
166
|
/*
|
167
|
* (non-Javadoc)
|
168
|
*
|
169
|
* @see org.eclipse.ui.forms.editor.FormEditor#dispose()
|
170
|
*/
|
171
|
@Override
|
172
|
public void dispose() {
|
173
|
conversation.unregisterForDataStoreChanges(this);
|
174
|
conversation.close();
|
175
|
super.dispose();
|
176
|
}
|
177
|
|
178
|
/*
|
179
|
* (non-Javadoc)
|
180
|
*
|
181
|
* @see org.eclipse.ui.forms.editor.FormEditor#addPages()
|
182
|
*/
|
183
|
@Override
|
184
|
protected void addPages() {
|
185
|
AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
|
186
|
conversation = input.getConversationHolder();
|
187
|
conversation.registerForDataStoreChanges(this);
|
188
|
|
189
|
try {
|
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
|
EditorUtil.error(getClass(), e);
|
196
|
}
|
197
|
|
198
|
|
199
|
|
200
|
setPartName();
|
201
|
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
*
|
206
|
*/
|
207
|
public void setPartName() {
|
208
|
AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
|
209
|
PolytomousKey key = (PolytomousKey) input.getKey();
|
210
|
setPartName(key.getTitleCache());
|
211
|
}
|
212
|
}
|