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().commit(true);
|
56
|
setDirty(false);
|
57
|
monitor.worked(1);
|
58
|
} finally {
|
59
|
monitor.done();
|
60
|
}
|
61
|
}
|
62
|
|
63
|
/*
|
64
|
* (non-Javadoc)
|
65
|
*
|
66
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
67
|
*/
|
68
|
@Override
|
69
|
public void doSaveAs() {
|
70
|
// not allowed
|
71
|
}
|
72
|
|
73
|
/*
|
74
|
* (non-Javadoc)
|
75
|
*
|
76
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
77
|
*/
|
78
|
@Override
|
79
|
public boolean isSaveAsAllowed() {
|
80
|
return false;
|
81
|
}
|
82
|
|
83
|
/*
|
84
|
* (non-Javadoc)
|
85
|
*
|
86
|
* @see
|
87
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
88
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
89
|
*/
|
90
|
@Override
|
91
|
public void update(CdmDataChangeMap map) {
|
92
|
if(dataChangeBehavior == null){
|
93
|
dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
|
94
|
}
|
95
|
DataChangeBridge.handleDataChange(map, dataChangeBehavior);
|
96
|
}
|
97
|
|
98
|
/*
|
99
|
* (non-Javadoc)
|
100
|
*
|
101
|
* @see
|
102
|
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
|
103
|
* ()
|
104
|
*/
|
105
|
@Override
|
106
|
public ConversationHolder getConversationHolder() {
|
107
|
return conversation;
|
108
|
}
|
109
|
|
110
|
/*
|
111
|
* (non-Javadoc)
|
112
|
*
|
113
|
* @see
|
114
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
115
|
* java.lang.Object)
|
116
|
*/
|
117
|
@Override
|
118
|
public void changed(Object element) {
|
119
|
editorDirtyStateChanged();
|
120
|
IEditorPart activeEditor = getActiveEditor();
|
121
|
if (activeEditor instanceof IDirtyMarkableSelectionProvider) {
|
122
|
((IDirtyMarkableSelectionProvider) activeEditor).changed(element);
|
123
|
}
|
124
|
}
|
125
|
|
126
|
/*
|
127
|
* (non-Javadoc)
|
128
|
*
|
129
|
* @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
|
130
|
*/
|
131
|
@Override
|
132
|
public void editorDirtyStateChanged() {
|
133
|
dirty = true;
|
134
|
super.editorDirtyStateChanged();
|
135
|
}
|
136
|
|
137
|
@Override
|
138
|
protected void handlePropertyChange(int propertyId) {
|
139
|
if (propertyId == PROP_DIRTY) {
|
140
|
setDirty(true);
|
141
|
}
|
142
|
super.handlePropertyChange(propertyId);
|
143
|
}
|
144
|
|
145
|
private void setDirty(boolean dirty) {
|
146
|
this.dirty = dirty;
|
147
|
firePropertyChange(PROP_DIRTY);
|
148
|
}
|
149
|
|
150
|
/*
|
151
|
* (non-Javadoc)
|
152
|
*
|
153
|
* @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
|
154
|
*/
|
155
|
@Override
|
156
|
public boolean isDirty() {
|
157
|
return dirty;
|
158
|
}
|
159
|
|
160
|
/*
|
161
|
* (non-Javadoc)
|
162
|
*
|
163
|
* @see org.eclipse.ui.forms.editor.FormEditor#dispose()
|
164
|
*/
|
165
|
@Override
|
166
|
public void dispose() {
|
167
|
conversation.unregisterForDataStoreChanges(this);
|
168
|
conversation.close();
|
169
|
super.dispose();
|
170
|
}
|
171
|
|
172
|
/*
|
173
|
* (non-Javadoc)
|
174
|
*
|
175
|
* @see org.eclipse.ui.forms.editor.FormEditor#addPages()
|
176
|
*/
|
177
|
@Override
|
178
|
protected void addPages() {
|
179
|
AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
|
180
|
conversation = input.getConversationHolder();
|
181
|
conversation.registerForDataStoreChanges(this);
|
182
|
|
183
|
try {
|
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);
|
190
|
}
|
191
|
|
192
|
|
193
|
|
194
|
setPartName();
|
195
|
|
196
|
}
|
197
|
|
198
|
/**
|
199
|
*
|
200
|
*/
|
201
|
public void setPartName() {
|
202
|
AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
|
203
|
PolytomousKey key = (PolytomousKey) input.getKey();
|
204
|
setPartName(key.getTitleCache());
|
205
|
}
|
206
|
}
|