3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.classification
;
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
;
36 * TaxonNodeDetailElement class.
40 * @created Sep 27, 2010
43 public class TaxonNodeDetailElement
extends AbstractCdmDetailElement
<ITreeNode
> {
45 private ClassificationSelectionElement selection_classification
;
47 private Classification classification
;
49 private TaxonNodeSelectionElement selection_parentTaxonNode
;
51 private ITreeNode parentTreeNode
;
53 private TaxonSelectionElement selection_reuseExistingTaxon
;
57 private TextWithLabelElement text_newTaxonName
;
59 private CheckboxElement checkbox_openInEditor
;
61 private boolean openInEditor
;
63 private boolean complete
;
65 private NameSelectionElement selection_reuseExistingName
;
69 * Constructor for TaxonNodeDetailElement.
73 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
76 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
79 public TaxonNodeDetailElement(CdmFormFactory formFactory
,
80 ICdmFormElement formElement
) {
81 super(formFactory
, formElement
);
88 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
89 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
90 * eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
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
);
110 selection_reuseExistingName
= (NameSelectionElement
) formFactory
111 .createSelectionElement(SelectionType
.NAME
,
112 getConversationHolder(), formElement
,
113 "Reuse existing name", null,
114 NameSelectionElement
.DEFAULT
, style
);
116 text_newTaxonName
= formFactory
.createTextWithLabelElement(formElement
,
117 "New Taxon", "", style
);
119 checkbox_openInEditor
= formFactory
.createCheckbox(formElement
,
120 "Open in Editor", true, style
);
121 setOpenInEditor(true);
122 setParentTreeNode(entity
);
129 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
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
);
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
);
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
);
156 setTaxon(text_newTaxonName
.getText());
157 } else if (eventSource
== checkbox_openInEditor
) {
158 setOpenInEditor(checkbox_openInEditor
.getSelection());
161 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
167 * Getter for the field <code>classification</code>.
170 * @return the classification
172 public Classification
getClassification() {
173 return classification
;
181 * @return the openInEditor
183 public boolean isOpenInEditor() {
189 * Getter for the field <code>parentTreeNode</code>.
192 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
194 public ITreeNode
getParentTreeNode() {
195 return parentTreeNode
;
200 * Getter for the field <code>taxon</code>.
205 public Taxon
getTaxon() {
210 * @param classification
211 * the classification to set
213 private void setClassification(Classification classification
) {
214 this.classification
= classification
;
215 setParentTreeNode(classification
);
219 * @param parentTreeNode
220 * the parentTreeNode to set
222 private void setParentTreeNode(ITreeNode parentTreeNode
) {
223 this.parentTreeNode
= parentTreeNode
;
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 } else if(parentTreeNode
== null){
237 this.parentTreeNode
= selection_classification
.getEntity();
242 * @param reuseExistingTaxon
243 * the reuseExistingTaxon to set
245 private void setTaxon(Taxon taxon
) {
249 private void setTaxon(String taxonNameString
) {
250 TaxonNameBase taxonName
= ParseHandler
.parseReferencedName(
251 taxonNameString
, null);
255 private void setTaxon(TaxonNameBase taxonName
) {
256 Reference secundum
= null;
257 if (getParentTreeNode() != null) {
258 if (getParentTreeNode() instanceof Classification
) {
259 secundum
= ((Classification
) getParentTreeNode())
261 } else if (getParentTreeNode() instanceof TaxonNode
) {
262 secundum
= ((TaxonNode
) getParentTreeNode()).getTaxon()
266 taxon
= Taxon
.NewInstance(taxonName
, secundum
);
270 * @param openInEditor
271 * the openInEditor to set
273 private void setOpenInEditor(boolean openInEditor
) {
274 this.openInEditor
= openInEditor
;
282 * @return the complete
284 public boolean isComplete() {