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