1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.key;
|
11
|
|
12
|
import org.eclipse.core.runtime.IProgressMonitor;
|
13
|
import org.eclipse.ui.IEditorInput;
|
14
|
import org.eclipse.ui.IEditorPart;
|
15
|
import org.eclipse.ui.IEditorSite;
|
16
|
import org.eclipse.ui.PartInitException;
|
17
|
import org.eclipse.ui.forms.editor.FormEditor;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
20
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
21
|
import eu.etaxonomy.cdm.api.application.ICdmChangeListener;
|
22
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
23
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
26
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
27
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
|
28
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyGraphEditor;
|
29
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
|
30
|
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
|
31
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
32
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
33
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
34
|
|
35
|
/**
|
36
|
* @author n.hoffmann
|
37
|
* @created Mar 30, 2011
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class KeyEditor extends FormEditor implements IConversationEnabled,
|
41
|
IDirtyMarkable, IPartContentHasDetails, ICdmChangeListener {
|
42
|
|
43
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.key";
|
44
|
|
45
|
private ConversationHolder conversation;
|
46
|
|
47
|
private boolean dirty;
|
48
|
|
49
|
private KeyEditorDataChangeBehaviour dataChangeBehavior;
|
50
|
|
51
|
private PolytomousKeyEditorInput polytomousKeyEditorInput;
|
52
|
|
53
|
/*
|
54
|
* (non-Javadoc)
|
55
|
*
|
56
|
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
|
57
|
* org.eclipse.ui.IEditorInput)
|
58
|
*/
|
59
|
@Override
|
60
|
public void init(IEditorSite site, IEditorInput input)
|
61
|
throws PartInitException {
|
62
|
polytomousKeyEditorInput = (PolytomousKeyEditorInput)input;
|
63
|
CdmApplicationState.getCurrentDataChangeService().register(this);
|
64
|
super.init(site, input);
|
65
|
}
|
66
|
|
67
|
/*
|
68
|
* (non-Javadoc)
|
69
|
*
|
70
|
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
|
71
|
* IProgressMonitor)
|
72
|
*/
|
73
|
@Override
|
74
|
public void doSave(IProgressMonitor monitor) {
|
75
|
try {
|
76
|
monitor.beginTask("Saving Editor", 1);
|
77
|
getConversationHolder().bind();
|
78
|
getConversationHolder().commit(true);
|
79
|
polytomousKeyEditorInput.merge();
|
80
|
setDirty(false);
|
81
|
monitor.worked(1);
|
82
|
} finally {
|
83
|
monitor.done();
|
84
|
}
|
85
|
}
|
86
|
|
87
|
/*
|
88
|
* (non-Javadoc)
|
89
|
*
|
90
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
91
|
*/
|
92
|
@Override
|
93
|
public void doSaveAs() {
|
94
|
// not allowed
|
95
|
}
|
96
|
|
97
|
/*
|
98
|
* (non-Javadoc)
|
99
|
*
|
100
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
101
|
*/
|
102
|
@Override
|
103
|
public boolean isSaveAsAllowed() {
|
104
|
return false;
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public void setFocus() {
|
109
|
getConversationHolder().commit(true);
|
110
|
getConversationHolder().bind();
|
111
|
polytomousKeyEditorInput.bind();
|
112
|
super.setFocus();
|
113
|
}
|
114
|
/*
|
115
|
* (non-Javadoc)
|
116
|
*
|
117
|
* @see
|
118
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
119
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
120
|
*/
|
121
|
@Override
|
122
|
public void update(CdmDataChangeMap map) {
|
123
|
if(dataChangeBehavior == null){
|
124
|
dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
|
125
|
}
|
126
|
DataChangeBridge.handleDataChange(map, dataChangeBehavior);
|
127
|
}
|
128
|
|
129
|
/*
|
130
|
* (non-Javadoc)
|
131
|
*
|
132
|
* @see
|
133
|
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
|
134
|
* ()
|
135
|
*/
|
136
|
@Override
|
137
|
public ConversationHolder getConversationHolder() {
|
138
|
return conversation;
|
139
|
}
|
140
|
|
141
|
/*
|
142
|
* (non-Javadoc)
|
143
|
*
|
144
|
* @see
|
145
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
146
|
* java.lang.Object)
|
147
|
*/
|
148
|
@Override
|
149
|
public void changed(Object element) {
|
150
|
editorDirtyStateChanged();
|
151
|
IEditorPart activeEditor = getActiveEditor();
|
152
|
if (activeEditor instanceof IDirtyMarkable) {
|
153
|
((IDirtyMarkable) activeEditor).changed(element);
|
154
|
}
|
155
|
}
|
156
|
|
157
|
/* (non-Javadoc)
|
158
|
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
|
159
|
*/
|
160
|
@Override
|
161
|
public void forceDirty() {
|
162
|
changed(null);
|
163
|
}
|
164
|
|
165
|
/*
|
166
|
* (non-Javadoc)
|
167
|
*
|
168
|
* @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
|
169
|
*/
|
170
|
@Override
|
171
|
public void editorDirtyStateChanged() {
|
172
|
dirty = true;
|
173
|
super.editorDirtyStateChanged();
|
174
|
}
|
175
|
|
176
|
@Override
|
177
|
protected void handlePropertyChange(int propertyId) {
|
178
|
if (propertyId == PROP_DIRTY) {
|
179
|
setDirty(true);
|
180
|
}
|
181
|
super.handlePropertyChange(propertyId);
|
182
|
}
|
183
|
|
184
|
private void setDirty(boolean dirty) {
|
185
|
this.dirty = dirty;
|
186
|
firePropertyChange(PROP_DIRTY);
|
187
|
}
|
188
|
|
189
|
/*
|
190
|
* (non-Javadoc)
|
191
|
*
|
192
|
* @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
|
193
|
*/
|
194
|
@Override
|
195
|
public boolean isDirty() {
|
196
|
return dirty;
|
197
|
}
|
198
|
|
199
|
/*
|
200
|
* (non-Javadoc)
|
201
|
*
|
202
|
* @see org.eclipse.ui.forms.editor.FormEditor#dispose()
|
203
|
*/
|
204
|
@Override
|
205
|
public void dispose() {
|
206
|
conversation.unregisterForDataStoreChanges(this);
|
207
|
conversation.close();
|
208
|
polytomousKeyEditorInput.dispose();
|
209
|
CdmApplicationState.getCurrentDataChangeService().unregister(this);
|
210
|
super.dispose();
|
211
|
}
|
212
|
|
213
|
/*
|
214
|
* (non-Javadoc)
|
215
|
*
|
216
|
* @see org.eclipse.ui.forms.editor.FormEditor#addPages()
|
217
|
*/
|
218
|
@Override
|
219
|
protected void addPages() {
|
220
|
conversation = polytomousKeyEditorInput.getConversationHolder();
|
221
|
conversation.registerForDataStoreChanges(this);
|
222
|
|
223
|
try {
|
224
|
addPage(0, new PolytomousKeyListEditor(this), polytomousKeyEditorInput);
|
225
|
setPageText(0, "List");
|
226
|
addPage(1, new PolytomousKeyGraphEditor(this), polytomousKeyEditorInput);
|
227
|
setPageText(1, "Graph");
|
228
|
} catch (PartInitException e) {
|
229
|
MessagingUtils.error(getClass(), e);
|
230
|
}
|
231
|
|
232
|
|
233
|
|
234
|
setPartName();
|
235
|
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
*
|
240
|
*/
|
241
|
public void setPartName() {
|
242
|
PolytomousKey key = polytomousKeyEditorInput.getKey();
|
243
|
setPartName(key.getTitleCache());
|
244
|
}
|
245
|
|
246
|
/* (non-Javadoc)
|
247
|
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
|
248
|
*/
|
249
|
@Override
|
250
|
public void onChange(CdmChangeEvent event) {
|
251
|
editorDirtyStateChanged();
|
252
|
IEditorPart activeEditor = getActiveEditor();
|
253
|
if (activeEditor instanceof IDirtyMarkable) {
|
254
|
for(CdmBase cdmBase : event.getChangedObjects()) {
|
255
|
((IDirtyMarkable) activeEditor).changed(cdmBase);
|
256
|
}
|
257
|
}
|
258
|
}
|
259
|
}
|