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
.NOTHING
, style
);
105 selection_reuseExistingName
= formFactory
106 .createSelectionElement(TaxonNameBase
.class,
107 getConversationHolder(), formElement
,
108 "Reuse existing name", null,
109 EntitySelectionElement
.ALL
, style
);
111 text_newTaxonName
= formFactory
.createTextWithLabelElement(formElement
,
112 "New Taxon", "", style
);
114 checkbox_openInEditor
= formFactory
.createCheckbox(formElement
,
115 "Open in Editor", true, style
);
116 setOpenInEditor(true);
117 setParentTreeNode(entity
);
124 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
129 public void handleEvent(Object eventSource
) {
130 if (eventSource
== selection_classification
) {
131 setClassification(selection_classification
.getEntity());
132 } else if (eventSource
== selection_parentTaxonNode
) {
133 setParentTreeNode(selection_parentTaxonNode
.getEntity());
134 } else if (eventSource
== selection_reuseExistingTaxon
) {
135 boolean enabled
= selection_reuseExistingTaxon
.getEntity() == null;
136 selection_reuseExistingName
.setEnabled(enabled
);
137 text_newTaxonName
.setEnabled(enabled
);
139 setTaxon(selection_reuseExistingTaxon
.getEntity());
140 } else if (eventSource
== selection_reuseExistingName
) {
141 boolean enabled
= selection_reuseExistingName
.getEntity() == null;
142 selection_reuseExistingTaxon
.setEnabled(enabled
);
143 text_newTaxonName
.setEnabled(enabled
);
145 setTaxon(selection_reuseExistingName
.getEntity());
146 } else if (eventSource
== text_newTaxonName
) {
147 boolean enabled
= CdmUtils
.isEmpty(text_newTaxonName
.getText());
148 selection_reuseExistingTaxon
.setEnabled(enabled
);
149 selection_reuseExistingName
.setEnabled(enabled
);
151 setTaxon(text_newTaxonName
.getText());
152 } else if (eventSource
== checkbox_openInEditor
) {
153 setOpenInEditor(checkbox_openInEditor
.getSelection());
159 * Getter for the field <code>classification</code>.
162 * @return the classification
164 public Classification
getClassification() {
165 return classification
;
173 * @return the openInEditor
175 public boolean isOpenInEditor() {
181 * Getter for the field <code>parentTreeNode</code>.
184 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
186 public ITaxonTreeNode
getParentTreeNode() {
187 return parentTreeNode
;
192 * Getter for the field <code>taxon</code>.
197 public Taxon
getTaxon() {
202 * @param classification
203 * the classification to set
205 private void setClassification(Classification classification
) {
206 this.classification
= classification
;
207 setParentTreeNode(classification
);
211 * @param parentTreeNode
212 * the parentTreeNode to set
214 private void setParentTreeNode(ITaxonTreeNode parentTreeNode
) {
215 this.parentTreeNode
= parentTreeNode
;
217 if (parentTreeNode
instanceof Classification
) {
218 classification
= (Classification
) parentTreeNode
;
219 selection_classification
.setEntity(classification
);
220 selection_parentTaxonNode
.setEntity(null);
221 selection_parentTaxonNode
.setClassification(classification
);
222 } else if (parentTreeNode
instanceof TaxonNode
) {
223 classification
= (Classification
) HibernateProxyHelper
224 .deproxy(((TaxonNode
) parentTreeNode
).getClassification());
225 selection_classification
.setEntity(classification
);
226 selection_parentTaxonNode
.setEntity((TaxonNode
) parentTreeNode
);
227 selection_parentTaxonNode
.setClassification(classification
);
228 } else if(parentTreeNode
== null){
229 this.parentTreeNode
= selection_classification
.getEntity();
234 * @param reuseExistingTaxon
235 * the reuseExistingTaxon to set
237 private void setTaxon(Taxon taxon
) {
241 private void setTaxon(String taxonNameString
) {
242 TaxonNameBase taxonName
= ParseHandler
.parseReferencedName(
243 taxonNameString
, null);
247 private void setTaxon(TaxonNameBase taxonName
) {
248 Reference secundum
= null;
249 if (getParentTreeNode() != null) {
250 if (getParentTreeNode() instanceof Classification
) {
251 secundum
= ((Classification
) getParentTreeNode())
253 } else if (getParentTreeNode() instanceof TaxonNode
) {
254 secundum
= ((TaxonNode
) getParentTreeNode()).getTaxon()
258 taxon
= Taxon
.NewInstance(taxonName
, secundum
);
262 * @param openInEditor
263 * the openInEditor to set
265 private void setOpenInEditor(boolean openInEditor
) {
266 this.openInEditor
= openInEditor
;
274 * @return the complete
276 public boolean isComplete() {