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