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.ui.section.classification;
|
12
|
|
13
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
14
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
15
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
16
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
18
|
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
21
|
import eu.etaxonomy.taxeditor.parser.ParseHandler;
|
22
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
|
23
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
|
24
|
import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
|
25
|
import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.selection.ClassificationSelectionElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
|
33
|
|
34
|
/**
|
35
|
* <p>
|
36
|
* TaxonNodeDetailElement class.
|
37
|
* </p>
|
38
|
*
|
39
|
* @author n.hoffmann
|
40
|
* @created Sep 27, 2010
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode> {
|
44
|
|
45
|
private ClassificationSelectionElement selection_classification;
|
46
|
|
47
|
private Classification classification;
|
48
|
|
49
|
private TaxonNodeSelectionElement selection_parentTaxonNode;
|
50
|
|
51
|
private ITreeNode parentTreeNode;
|
52
|
|
53
|
private TaxonSelectionElement selection_reuseExistingTaxon;
|
54
|
|
55
|
private Taxon taxon;
|
56
|
|
57
|
private TextWithLabelElement text_newTaxonName;
|
58
|
|
59
|
private CheckboxElement checkbox_openInEditor;
|
60
|
|
61
|
private boolean openInEditor;
|
62
|
|
63
|
private boolean complete;
|
64
|
|
65
|
private NameSelectionElement selection_reuseExistingName;
|
66
|
|
67
|
/**
|
68
|
* <p>
|
69
|
* Constructor for TaxonNodeDetailElement.
|
70
|
* </p>
|
71
|
*
|
72
|
* @param formFactory
|
73
|
* a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
|
74
|
* object.
|
75
|
* @param formElement
|
76
|
* a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
|
77
|
* object.
|
78
|
*/
|
79
|
public TaxonNodeDetailElement(CdmFormFactory formFactory,
|
80
|
ICdmFormElement formElement) {
|
81
|
super(formFactory, formElement);
|
82
|
}
|
83
|
|
84
|
/*
|
85
|
* (non-Javadoc)
|
86
|
*
|
87
|
* @see
|
88
|
* eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
|
89
|
* (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
|
90
|
* eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
|
91
|
*/
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
protected void createControls(ICdmFormElement formElement,
|
95
|
ITreeNode entity, int style) {
|
96
|
selection_classification = (ClassificationSelectionElement) formFactory
|
97
|
.createSelectionElement(SelectionType.CLASSIFICATION,
|
98
|
getConversationHolder(), formElement, "Classification",
|
99
|
null, ClassificationSelectionElement.DEFAULT, style);
|
100
|
selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory
|
101
|
.createSelectionElement(SelectionType.TAXON_NODE,
|
102
|
getConversationHolder(), formElement, "Parent", null,
|
103
|
TaxonNodeSelectionElement.DEFAULT, style);
|
104
|
selection_reuseExistingTaxon = (TaxonSelectionElement) formFactory
|
105
|
.createSelectionElement(SelectionType.TAXON,
|
106
|
getConversationHolder(), formElement,
|
107
|
"Reuse existing Taxon", null,
|
108
|
TaxonSelectionElement.DELETABLE, style);
|
109
|
|
110
|
selection_reuseExistingName = (NameSelectionElement) formFactory
|
111
|
.createSelectionElement(SelectionType.NAME,
|
112
|
getConversationHolder(), formElement,
|
113
|
"Reuse existing name", null,
|
114
|
NameSelectionElement.DEFAULT, style);
|
115
|
|
116
|
text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
|
117
|
"New Taxon", "", style);
|
118
|
|
119
|
checkbox_openInEditor = formFactory.createCheckbox(formElement,
|
120
|
"Open in Editor", true, style);
|
121
|
setOpenInEditor(true);
|
122
|
setParentTreeNode(entity);
|
123
|
}
|
124
|
|
125
|
/*
|
126
|
* (non-Javadoc)
|
127
|
*
|
128
|
* @see
|
129
|
* eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
|
130
|
* .lang.Object)
|
131
|
*/
|
132
|
/** {@inheritDoc} */
|
133
|
@Override
|
134
|
public void handleEvent(Object eventSource) {
|
135
|
if (eventSource == selection_classification) {
|
136
|
setClassification(selection_classification.getEntity());
|
137
|
} else if (eventSource == selection_parentTaxonNode) {
|
138
|
setParentTreeNode(selection_parentTaxonNode.getEntity());
|
139
|
} else if (eventSource == selection_reuseExistingTaxon) {
|
140
|
boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
|
141
|
selection_reuseExistingName.setEnabled(enabled);
|
142
|
text_newTaxonName.setEnabled(enabled);
|
143
|
|
144
|
setTaxon(selection_reuseExistingTaxon.getEntity());
|
145
|
} else if (eventSource == selection_reuseExistingName) {
|
146
|
boolean enabled = selection_reuseExistingName.getEntity() == null;
|
147
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
148
|
text_newTaxonName.setEnabled(enabled);
|
149
|
|
150
|
setTaxon(selection_reuseExistingName.getEntity());
|
151
|
} else if (eventSource == text_newTaxonName) {
|
152
|
boolean enabled = CdmUtils.isEmpty(text_newTaxonName.getText());
|
153
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
154
|
selection_reuseExistingName.setEnabled(enabled);
|
155
|
|
156
|
setTaxon(text_newTaxonName.getText());
|
157
|
} else if (eventSource == checkbox_openInEditor) {
|
158
|
setOpenInEditor(checkbox_openInEditor.getSelection());
|
159
|
}
|
160
|
|
161
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
162
|
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* <p>
|
167
|
* Getter for the field <code>classification</code>.
|
168
|
* </p>
|
169
|
*
|
170
|
* @return the classification
|
171
|
*/
|
172
|
public Classification getClassification() {
|
173
|
return classification;
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* <p>
|
178
|
* isOpenInEditor
|
179
|
* </p>
|
180
|
*
|
181
|
* @return the openInEditor
|
182
|
*/
|
183
|
public boolean isOpenInEditor() {
|
184
|
return openInEditor;
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* <p>
|
189
|
* Getter for the field <code>parentTreeNode</code>.
|
190
|
* </p>
|
191
|
*
|
192
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
|
193
|
*/
|
194
|
public ITreeNode getParentTreeNode() {
|
195
|
return parentTreeNode;
|
196
|
}
|
197
|
|
198
|
/**
|
199
|
* <p>
|
200
|
* Getter for the field <code>taxon</code>.
|
201
|
* </p>
|
202
|
*
|
203
|
* @return the taxon
|
204
|
*/
|
205
|
public Taxon getTaxon() {
|
206
|
return taxon;
|
207
|
}
|
208
|
|
209
|
/**
|
210
|
* @param classification
|
211
|
* the classification to set
|
212
|
*/
|
213
|
private void setClassification(Classification classification) {
|
214
|
this.classification = classification;
|
215
|
setParentTreeNode(classification);
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* @param parentTreeNode
|
220
|
* the parentTreeNode to set
|
221
|
*/
|
222
|
private void setParentTreeNode(ITreeNode parentTreeNode) {
|
223
|
this.parentTreeNode = parentTreeNode;
|
224
|
|
225
|
if (parentTreeNode instanceof Classification) {
|
226
|
classification = (Classification) parentTreeNode;
|
227
|
selection_classification.setEntity(classification);
|
228
|
selection_parentTaxonNode.setEntity(null);
|
229
|
selection_parentTaxonNode.setClassification(classification);
|
230
|
} else if (parentTreeNode instanceof TaxonNode) {
|
231
|
classification = (Classification) HibernateProxyHelper
|
232
|
.deproxy(((TaxonNode) parentTreeNode).getClassification());
|
233
|
selection_classification.setEntity(classification);
|
234
|
selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
|
235
|
selection_parentTaxonNode.setClassification(classification);
|
236
|
}
|
237
|
}
|
238
|
|
239
|
/**
|
240
|
* @param reuseExistingTaxon
|
241
|
* the reuseExistingTaxon to set
|
242
|
*/
|
243
|
private void setTaxon(Taxon taxon) {
|
244
|
this.taxon = taxon;
|
245
|
}
|
246
|
|
247
|
private void setTaxon(String taxonNameString) {
|
248
|
TaxonNameBase taxonName = ParseHandler.parseReferencedName(
|
249
|
taxonNameString, null);
|
250
|
setTaxon(taxonName);
|
251
|
}
|
252
|
|
253
|
private void setTaxon(TaxonNameBase taxonName) {
|
254
|
Reference secundum = null;
|
255
|
if (getParentTreeNode() != null) {
|
256
|
if (getParentTreeNode() instanceof Classification) {
|
257
|
secundum = ((Classification) getParentTreeNode())
|
258
|
.getReference();
|
259
|
} else if (getParentTreeNode() instanceof TaxonNode) {
|
260
|
secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
|
261
|
.getSec();
|
262
|
}
|
263
|
}
|
264
|
taxon = Taxon.NewInstance(taxonName, secundum);
|
265
|
}
|
266
|
|
267
|
/**
|
268
|
* @param openInEditor
|
269
|
* the openInEditor to set
|
270
|
*/
|
271
|
private void setOpenInEditor(boolean openInEditor) {
|
272
|
this.openInEditor = openInEditor;
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* <p>
|
277
|
* isComplete
|
278
|
* </p>
|
279
|
*
|
280
|
* @return the complete
|
281
|
*/
|
282
|
public boolean isComplete() {
|
283
|
return complete;
|
284
|
}
|
285
|
|
286
|
}
|