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.persistence.hibernate.CdmDataChangeMap;
|
21
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
22
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyGraphEditor;
|
23
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
|
24
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
|
25
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
26
|
|
27
|
/**
|
28
|
* @author n.hoffmann
|
29
|
* @created Mar 30, 2011
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class KeyEditor extends FormEditor implements IConversationEnabled,
|
33
|
IDirtyMarkableSelectionProvider, IPartContentHasDetails {
|
34
|
|
35
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.key";
|
36
|
|
37
|
private ConversationHolder conversation;
|
38
|
|
39
|
private AbstractIdentificationEditorInput input;
|
40
|
|
41
|
private boolean dirty;
|
42
|
|
43
|
/*
|
44
|
* (non-Javadoc)
|
45
|
*
|
46
|
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
|
47
|
* IProgressMonitor)
|
48
|
*/
|
49
|
@Override
|
50
|
public void doSave(IProgressMonitor monitor) {
|
51
|
try {
|
52
|
monitor.beginTask("Saving Editor", 1);
|
53
|
getConversationHolder().commit(true);
|
54
|
setDirty(false);
|
55
|
monitor.worked(1);
|
56
|
} finally {
|
57
|
monitor.done();
|
58
|
}
|
59
|
}
|
60
|
|
61
|
/*
|
62
|
* (non-Javadoc)
|
63
|
*
|
64
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
65
|
*/
|
66
|
@Override
|
67
|
public void doSaveAs() {
|
68
|
// not allowed
|
69
|
}
|
70
|
|
71
|
/*
|
72
|
* (non-Javadoc)
|
73
|
*
|
74
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
75
|
*/
|
76
|
@Override
|
77
|
public boolean isSaveAsAllowed() {
|
78
|
return false;
|
79
|
}
|
80
|
|
81
|
/*
|
82
|
* (non-Javadoc)
|
83
|
*
|
84
|
* @see
|
85
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
86
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
87
|
*/
|
88
|
@Override
|
89
|
public void update(CdmDataChangeMap arg0) {
|
90
|
// TODO Auto-generated method stub
|
91
|
}
|
92
|
|
93
|
/*
|
94
|
* (non-Javadoc)
|
95
|
*
|
96
|
* @see
|
97
|
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
|
98
|
* ()
|
99
|
*/
|
100
|
@Override
|
101
|
public ConversationHolder getConversationHolder() {
|
102
|
return conversation;
|
103
|
}
|
104
|
|
105
|
/*
|
106
|
* (non-Javadoc)
|
107
|
*
|
108
|
* @see
|
109
|
* eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(
|
110
|
* java.lang.Object)
|
111
|
*/
|
112
|
@Override
|
113
|
public void changed(Object element) {
|
114
|
editorDirtyStateChanged();
|
115
|
IEditorPart activeEditor = getActiveEditor();
|
116
|
if (activeEditor instanceof PolytomousKeyListEditor) {
|
117
|
((PolytomousKeyListEditor) activeEditor).changed(element);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/*
|
122
|
* (non-Javadoc)
|
123
|
*
|
124
|
* @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
|
125
|
*/
|
126
|
@Override
|
127
|
public void editorDirtyStateChanged() {
|
128
|
dirty = true;
|
129
|
super.editorDirtyStateChanged();
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
protected void handlePropertyChange(int propertyId) {
|
134
|
if (propertyId == PROP_DIRTY) {
|
135
|
setDirty(true);
|
136
|
}
|
137
|
super.handlePropertyChange(propertyId);
|
138
|
}
|
139
|
|
140
|
private void setDirty(boolean dirty) {
|
141
|
this.dirty = dirty;
|
142
|
firePropertyChange(PROP_DIRTY);
|
143
|
}
|
144
|
|
145
|
/*
|
146
|
* (non-Javadoc)
|
147
|
*
|
148
|
* @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
|
149
|
*/
|
150
|
@Override
|
151
|
public boolean isDirty() {
|
152
|
return dirty;
|
153
|
}
|
154
|
|
155
|
/*
|
156
|
* (non-Javadoc)
|
157
|
*
|
158
|
* @see org.eclipse.ui.forms.editor.FormEditor#dispose()
|
159
|
*/
|
160
|
@Override
|
161
|
public void dispose() {
|
162
|
conversation.unregisterForDataStoreChanges(this);
|
163
|
conversation.close();
|
164
|
super.dispose();
|
165
|
}
|
166
|
|
167
|
/*
|
168
|
* (non-Javadoc)
|
169
|
*
|
170
|
* @see org.eclipse.ui.forms.editor.FormEditor#addPages()
|
171
|
*/
|
172
|
@Override
|
173
|
protected void addPages() {
|
174
|
input = (AbstractIdentificationEditorInput) getEditorInput();
|
175
|
conversation = input.getConversationHolder();
|
176
|
conversation.registerForDataStoreChanges(this);
|
177
|
|
178
|
try {
|
179
|
addPage(0, new PolytomousKeyListEditor(), input);
|
180
|
setPageText(0, "List");
|
181
|
addPage(1, new PolytomousKeyGraphEditor(), input);
|
182
|
setPageText(1, "Graph");
|
183
|
} catch (PartInitException e) {
|
184
|
EditorUtil.error(getClass(), e);
|
185
|
}
|
186
|
|
187
|
}
|
188
|
}
|