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
.ITaxonTreeNode
;
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
.element
.CdmFormFactory
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.selection
.TaxonNodeSelectionElement
;
32 * TaxonNodeDetailElement class.
36 * @created Sep 27, 2010
39 public class TaxonNodeDetailElement
extends AbstractCdmDetailElement
<ITaxonTreeNode
> {
41 private EntitySelectionElement
<Classification
> selection_classification
;
43 private Classification classification
;
45 private TaxonNodeSelectionElement selection_parentTaxonNode
;
47 private ITaxonTreeNode parentTreeNode
;
49 private EntitySelectionElement
<Taxon
> selection_reuseExistingTaxon
;
53 private TextWithLabelElement text_newTaxonName
;
55 private CheckboxElement checkbox_openInEditor
;
57 private boolean openInEditor
;
59 private boolean complete
;
61 private EntitySelectionElement
<TaxonNameBase
> selection_reuseExistingName
;
65 * Constructor for TaxonNodeDetailElement.
69 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
72 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
75 public TaxonNodeDetailElement(CdmFormFactory formFactory
,
76 ICdmFormElement formElement
) {
77 super(formFactory
, formElement
);
84 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
85 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
86 * eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
90 protected void createControls(ICdmFormElement formElement
,
91 ITaxonTreeNode entity
, int style
) {
92 selection_classification
= formFactory
93 .createSelectionElement(Classification
.class,
94 getConversationHolder(), formElement
, "Classification",
95 null, EntitySelectionElement
.DELETABLE
, style
);
96 selection_parentTaxonNode
= formFactory
97 .createTaxonNodeSelectionElement(getConversationHolder(), formElement
, "Parent", null,
98 EntitySelectionElement
.DELETABLE
, style
);
99 selection_reuseExistingTaxon
= formFactory
100 .createSelectionElement(Taxon
.class,
101 getConversationHolder(), formElement
,
102 "Reuse existing taxon", null,
103 EntitySelectionElement
.DELETABLE
, style
);
105 selection_reuseExistingName
= formFactory
106 .createSelectionElement(TaxonNameBase
.class,
107 getConversationHolder(), formElement
,
108 "Reuse existing name", null,
109 EntitySelectionElement
.DELETABLE
, style
);
111 text_newTaxonName
= formFactory
.createTextWithLabelElement(formElement
,
112 "New Taxon", "", style
);
113 text_newTaxonName
.setFocus();
115 checkbox_openInEditor
= formFactory
.createCheckbox(formElement
,
116 "Open in Editor", true, style
);
117 setOpenInEditor(true);
118 setParentTreeNode(entity
);
125 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
130 public void handleEvent(Object eventSource
) {
131 if (eventSource
== selection_classification
) {
132 setClassification(selection_classification
.getEntity());
133 } else if (eventSource
== selection_parentTaxonNode
) {
134 setParentTreeNode(selection_parentTaxonNode
.getEntity());
135 } else if (eventSource
== selection_reuseExistingTaxon
) {
136 boolean enabled
= selection_reuseExistingTaxon
.getEntity() == null;
137 selection_reuseExistingName
.setEnabled(enabled
);
138 text_newTaxonName
.setEnabled(enabled
);
140 setTaxon(selection_reuseExistingTaxon
.getEntity());
141 } else if (eventSource
== selection_reuseExistingName
) {
142 boolean enabled
= selection_reuseExistingName
.getEntity() == null;
143 selection_reuseExistingTaxon
.setEnabled(enabled
);
144 text_newTaxonName
.setEnabled(enabled
);
146 setTaxon(selection_reuseExistingName
.getEntity());
147 } else if (eventSource
== text_newTaxonName
) {
148 boolean enabled
= CdmUtils
.isEmpty(text_newTaxonName
.getText());
149 selection_reuseExistingTaxon
.setEnabled(enabled
);
150 selection_reuseExistingName
.setEnabled(enabled
);
152 setTaxon(text_newTaxonName
.getText());
153 } else if (eventSource
== checkbox_openInEditor
) {
154 setOpenInEditor(checkbox_openInEditor
.getSelection());
160 * Getter for the field <code>classification</code>.
163 * @return the classification
165 public Classification
getClassification() {
166 return classification
;
174 * @return the openInEditor
176 public boolean isOpenInEditor() {
182 * Getter for the field <code>parentTreeNode</code>.
185 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
187 public ITaxonTreeNode
getParentTreeNode() {
188 return parentTreeNode
;
193 * Getter for the field <code>taxon</code>.
198 public Taxon
getTaxon() {
203 * @param classification
204 * the classification to set
206 private void setClassification(Classification classification
) {
207 this.classification
= classification
;
208 setParentTreeNode(classification
);
212 * @param parentTreeNode
213 * the parentTreeNode to set
215 private void setParentTreeNode(ITaxonTreeNode parentTreeNode
) {
216 this.parentTreeNode
= parentTreeNode
;
218 if (parentTreeNode
instanceof Classification
) {
219 classification
= (Classification
) parentTreeNode
;
220 selection_classification
.setEntity(classification
);
221 selection_parentTaxonNode
.setEntity(null);
222 selection_parentTaxonNode
.setClassification(classification
);
223 } else if (parentTreeNode
instanceof TaxonNode
) {
224 classification
= (Classification
) HibernateProxyHelper
225 .deproxy(((TaxonNode
) parentTreeNode
).getClassification());
226 selection_classification
.setEntity(classification
);
227 selection_parentTaxonNode
.setEntity((TaxonNode
) parentTreeNode
);
228 selection_parentTaxonNode
.setClassification(classification
);
229 } else if(parentTreeNode
== null){
230 this.parentTreeNode
= selection_classification
.getEntity();
235 * @param reuseExistingTaxon
236 * the reuseExistingTaxon to set
238 private void setTaxon(Taxon taxon
) {
242 private void setTaxon(String taxonNameString
) {
243 TaxonNameBase taxonName
= ParseHandler
.parseReferencedName(
244 taxonNameString
, null);
248 private void setTaxon(TaxonNameBase taxonName
) {
249 Reference secundum
= null;
250 if (getParentTreeNode() != null) {
251 if (getParentTreeNode() instanceof Classification
) {
252 secundum
= ((Classification
) getParentTreeNode())
254 } else if (getParentTreeNode() instanceof TaxonNode
) {
255 secundum
= ((TaxonNode
) getParentTreeNode()).getTaxon()
259 taxon
= Taxon
.NewInstance(taxonName
, secundum
);
263 * @param openInEditor
264 * the openInEditor to set
266 private void setOpenInEditor(boolean openInEditor
) {
267 this.openInEditor
= openInEditor
;
275 * @return the complete
277 public boolean isComplete() {