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.l10n.Messages;
|
29
|
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
|
30
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
31
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
32
|
|
33
|
/**
|
34
|
* @author n.hoffmann
|
35
|
* @created Mar 30, 2011
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class KeyEditor extends FormEditor implements IConversationEnabled,
|
39
|
IDirtyMarkable, IPartContentHasDetails, ICdmChangeListener {
|
40
|
|
41
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.key"; //$NON-NLS-1$
|
42
|
|
43
|
private ConversationHolder conversation;
|
44
|
|
45
|
private boolean dirty;
|
46
|
|
47
|
private KeyEditorDataChangeBehaviour dataChangeBehavior;
|
48
|
|
49
|
private PolytomousKeyEditorInput polytomousKeyEditorInput;
|
50
|
|
51
|
/*
|
52
|
* (non-Javadoc)
|
53
|
*
|
54
|
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
|
55
|
* org.eclipse.ui.IEditorInput)
|
56
|
*/
|
57
|
@Override
|
58
|
public void init(IEditorSite site, IEditorInput input)
|
59
|
throws PartInitException {
|
60
|
polytomousKeyEditorInput = (PolytomousKeyEditorInput)input;
|
61
|
CdmApplicationState.getCurrentDataChangeService().register(this);
|
62
|
super.init(site, input);
|
63
|
}
|
64
|
|
65
|
/*
|
66
|
* (non-Javadoc)
|
67
|
*
|
68
|
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
|
69
|
* IProgressMonitor)
|
70
|
*/
|
71
|
@Override
|
72
|
public void doSave(IProgressMonitor monitor) {
|
73
|
try {
|
74
|
monitor.beginTask(Messages.KeyEditor_SAVING, 1);
|
75
|
getConversationHolder().bind();
|
76
|
getConversationHolder().commit(true);
|
77
|
polytomousKeyEditorInput.merge();
|
78
|
setDirty(false);
|
79
|
monitor.worked(1);
|
80
|
} finally {
|
81
|
monitor.done();
|
82
|
}
|
83
|
}
|
84
|
|
85
|
/*
|
86
|
* (non-Javadoc)
|
87
|
*
|
88
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
89
|
*/
|
90
|
@Override
|
91
|
public void doSaveAs() {
|
92
|
// not allowed
|
93
|
}
|
94
|
|
95
|
/*
|
96
|
* (non-Javadoc)
|
97
|
*
|
98
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
99
|
*/
|
100
|
@Override
|
101
|
public boolean isSaveAsAllowed() {
|
102
|
return false;
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public void setFocus() {
|
107
|
getConversationHolder().commit(true);
|
108
|
getConversationHolder().bind();
|
109
|
polytomousKeyEditorInput.bind();
|
110
|
super.setFocus();
|
111
|
}
|
112
|
/*
|
113
|
* (non-Javadoc)
|
114
|
*
|
115
|
* @see
|
116
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
117
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
118
|
*/
|
119
|
@Override
|
120
|
public void update(CdmDataChangeMap map) {
|
121
|
if(dataChangeBehavior == null){
|
122
|
dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
|
123
|
}
|
124
|
DataChangeBridge.handleDataChange(map, dataChangeBehavior);
|
125
|
}
|
126
|
|
127
|
/*
|
128
|
* (non-Javadoc)
|
129
|
*
|
130
|
* @see
|
131
|
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
|
132
|
* ()
|
133
|
*/
|
134
|
@Override
|
135
|
public ConversationHolder getConversationHolder() {
|
136
|
return conversation;
|
137
|
}
|
138
|
|
139
|
/*
|
140
|
* (non-Javadoc)
|
141
|
*
|
142
|
* @see
|
143
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
144
|
* java.lang.Object)
|
145
|
*/
|
146
|
@Override
|
147
|
public void changed(Object element) {
|
148
|
if (element != null){
|
149
|
editorDirtyStateChanged();
|
150
|
}
|
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, Messages.KeyEditor_LIST);
|
226
|
// addPage(1, new PolytomousKeyGraphEditor(this), polytomousKeyEditorInput);
|
227
|
// setPageText(1, Messages.KeyEditor_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
|
}
|