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