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.section.classification;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
14
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
16
|
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
|
20
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType;
|
21
|
import eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent;
|
22
|
import eu.etaxonomy.taxeditor.forms.CheckboxElement;
|
23
|
import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
|
24
|
import eu.etaxonomy.taxeditor.forms.TextWithLabelElement;
|
25
|
import eu.etaxonomy.taxeditor.forms.selection.ClassificationSelectionElement;
|
26
|
import eu.etaxonomy.taxeditor.forms.selection.TaxonBaseSelectionElement;
|
27
|
import eu.etaxonomy.taxeditor.forms.selection.TaxonNodeSelectionElement;
|
28
|
import eu.etaxonomy.taxeditor.parser.ParseHandler;
|
29
|
import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
|
30
|
|
31
|
/**
|
32
|
* <p>TaxonNodeDetailElement class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created Sep 27, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode> {
|
39
|
|
40
|
private ClassificationSelectionElement selection_classification;
|
41
|
|
42
|
private Classification classification;
|
43
|
|
44
|
private TaxonNodeSelectionElement selection_parentTaxonNode;
|
45
|
|
46
|
private ITreeNode parentTreeNode;
|
47
|
|
48
|
private TaxonBaseSelectionElement selection_reuseExistingTaxon;
|
49
|
|
50
|
private Taxon taxon;
|
51
|
|
52
|
private TextWithLabelElement text_newTaxonName;
|
53
|
|
54
|
private CheckboxElement checkbox_openInEditor;
|
55
|
|
56
|
private boolean openInEditor;
|
57
|
|
58
|
private boolean complete;
|
59
|
|
60
|
/**
|
61
|
* <p>Constructor for TaxonNodeDetailElement.</p>
|
62
|
*
|
63
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
|
64
|
* @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
|
65
|
*/
|
66
|
public TaxonNodeDetailElement(CdmFormFactory formFactory,
|
67
|
ICdmFormElement formElement) {
|
68
|
super(formFactory, formElement);
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
|
73
|
*/
|
74
|
/** {@inheritDoc} */
|
75
|
@Override
|
76
|
protected void createControls(ICdmFormElement formElement,
|
77
|
ITreeNode entity, int style) {
|
78
|
selection_classification = (ClassificationSelectionElement) formFactory.createSelectionElement(SelectionType.CLASSIFICATION, getConversationHolder(), formElement, "Classification", null, style);
|
79
|
selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory.createSelectionElement(SelectionType.TAXON_NODE, getConversationHolder(), formElement, "Parent", null, style);
|
80
|
selection_reuseExistingTaxon = (TaxonBaseSelectionElement) formFactory.createSelectionElement(SelectionType.TAXON_BASE, getConversationHolder(), formElement, "Reuse existing Taxon", null, style);
|
81
|
|
82
|
text_newTaxonName = formFactory.createTextWithLabelElement(formElement, "New Taxon", "", style);
|
83
|
|
84
|
checkbox_openInEditor = formFactory.createCheckbox(formElement, "Open in Editor", true, style);
|
85
|
setOpenInEditor(true);
|
86
|
setParentTreeNode(entity);
|
87
|
}
|
88
|
|
89
|
|
90
|
/* (non-Javadoc)
|
91
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
|
92
|
*/
|
93
|
/** {@inheritDoc} */
|
94
|
@Override
|
95
|
public void handleEvent(Object eventSource) {
|
96
|
if(eventSource == selection_classification){
|
97
|
setClassification(selection_classification.getEntity());
|
98
|
}
|
99
|
else if(eventSource == selection_parentTaxonNode){
|
100
|
setParentTreeNode(selection_parentTaxonNode.getEntity());
|
101
|
}
|
102
|
else if(eventSource == selection_reuseExistingTaxon){
|
103
|
setTaxon((Taxon) selection_reuseExistingTaxon.getEntity());
|
104
|
}
|
105
|
else if(eventSource == text_newTaxonName){
|
106
|
setTaxon(text_newTaxonName.getText());
|
107
|
}
|
108
|
else if(eventSource == checkbox_openInEditor){
|
109
|
setOpenInEditor(checkbox_openInEditor.getSelection());
|
110
|
}
|
111
|
|
112
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
113
|
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* <p>Getter for the field <code>classification</code>.</p>
|
118
|
*
|
119
|
* @return the classification
|
120
|
*/
|
121
|
public Classification getClassification() {
|
122
|
return classification;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* <p>isOpenInEditor</p>
|
127
|
*
|
128
|
* @return the openInEditor
|
129
|
*/
|
130
|
public boolean isOpenInEditor() {
|
131
|
return openInEditor;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* <p>Getter for the field <code>parentTreeNode</code>.</p>
|
136
|
*
|
137
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
|
138
|
*/
|
139
|
public ITreeNode getParentTreeNode() {
|
140
|
return parentTreeNode;
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* <p>Getter for the field <code>taxon</code>.</p>
|
145
|
*
|
146
|
* @return the taxon
|
147
|
*/
|
148
|
public Taxon getTaxon() {
|
149
|
return taxon;
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* @param classification the classification to set
|
154
|
*/
|
155
|
private void setClassification(Classification classification) {
|
156
|
this.classification = classification;
|
157
|
setParentTreeNode(classification);
|
158
|
}
|
159
|
|
160
|
/**
|
161
|
* @param parentTreeNode the parentTreeNode to set
|
162
|
*/
|
163
|
private void setParentTreeNode(ITreeNode parentTreeNode) {
|
164
|
this.parentTreeNode = parentTreeNode;
|
165
|
|
166
|
if(parentTreeNode instanceof Classification){
|
167
|
selection_parentTaxonNode.setEntity(null);
|
168
|
}
|
169
|
else if(parentTreeNode instanceof TaxonNode){
|
170
|
classification = ((TaxonNode) parentTreeNode).getClassification();
|
171
|
selection_classification.setEntity(classification);
|
172
|
selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
|
173
|
}
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* @param reuseExistingTaxon the reuseExistingTaxon to set
|
178
|
*/
|
179
|
private void setTaxon(Taxon taxon) {
|
180
|
this.taxon = taxon;
|
181
|
}
|
182
|
|
183
|
private void setTaxon(String taxonNameString){
|
184
|
TaxonNameBase taxonName = ParseHandler.quickParse(taxonNameString);
|
185
|
Reference secundum = null;
|
186
|
if(getParentTreeNode() != null){
|
187
|
if(getParentElement() instanceof Classification){
|
188
|
secundum = ((Classification) getParentTreeNode()).getReference();
|
189
|
}
|
190
|
else if(getParentTreeNode() instanceof TaxonNode){
|
191
|
secundum = ((TaxonNode) getParentTreeNode()).getTaxon().getSec();
|
192
|
}
|
193
|
}
|
194
|
taxon = Taxon.NewInstance(taxonName, secundum);
|
195
|
}
|
196
|
|
197
|
/**
|
198
|
* @param openInEditor the openInEditor to set
|
199
|
*/
|
200
|
private void setOpenInEditor(boolean openInEditor) {
|
201
|
this.openInEditor = openInEditor;
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* <p>isComplete</p>
|
206
|
*
|
207
|
* @return the complete
|
208
|
*/
|
209
|
public boolean isComplete() {
|
210
|
return complete;
|
211
|
}
|
212
|
|
213
|
}
|