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
;
35 * <p>TaxonNodeDetailElement class.</p>
38 * @created Sep 27, 2010
41 public class TaxonNodeDetailElement
extends AbstractCdmDetailElement
<ITreeNode
> {
43 private ClassificationSelectionElement selection_classification
;
45 private Classification classification
;
47 private TaxonNodeSelectionElement selection_parentTaxonNode
;
49 private ITreeNode parentTreeNode
;
51 private TaxonSelectionElement selection_reuseExistingTaxon
;
55 private TextWithLabelElement text_newTaxonName
;
57 private CheckboxElement checkbox_openInEditor
;
59 private boolean openInEditor
;
61 private boolean complete
;
63 private NameSelectionElement selection_reuseExistingName
;
66 * <p>Constructor for TaxonNodeDetailElement.</p>
68 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
69 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
71 public TaxonNodeDetailElement(CdmFormFactory formFactory
,
72 ICdmFormElement formElement
) {
73 super(formFactory
, formElement
);
77 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
81 protected void createControls(ICdmFormElement formElement
,
82 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
);
87 selection_reuseExistingName
= (NameSelectionElement
) formFactory
.createSelectionElement(SelectionType
.NAME
, getConversationHolder(), formElement
, "Reuse existgin name", null, style
);
89 text_newTaxonName
= formFactory
.createTextWithLabelElement(formElement
, "New Taxon", "", style
);
91 checkbox_openInEditor
= formFactory
.createCheckbox(formElement
, "Open in Editor", true, style
);
92 setOpenInEditor(true);
93 setParentTreeNode(entity
);
98 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
102 public void handleEvent(Object eventSource
) {
103 if(eventSource
== selection_classification
){
104 setClassification(selection_classification
.getEntity());
106 else if(eventSource
== selection_parentTaxonNode
){
107 setParentTreeNode(selection_parentTaxonNode
.getEntity());
109 else if(eventSource
== selection_reuseExistingTaxon
){
110 boolean enabled
= selection_reuseExistingTaxon
.getEntity() == null;
111 selection_reuseExistingName
.setEnabled(enabled
);
112 text_newTaxonName
.setEnabled(enabled
);
114 setTaxon((Taxon
) selection_reuseExistingTaxon
.getEntity());
116 else if(eventSource
== selection_reuseExistingName
){
117 boolean enabled
= selection_reuseExistingName
.getEntity() == null;
118 selection_reuseExistingTaxon
.setEnabled(enabled
);
119 text_newTaxonName
.setEnabled(enabled
);
121 setTaxon(selection_reuseExistingName
.getEntity());
123 else if(eventSource
== text_newTaxonName
){
124 boolean enabled
= CdmUtils
.isEmpty(text_newTaxonName
.getText());
125 selection_reuseExistingTaxon
.setEnabled(enabled
);
126 selection_reuseExistingName
.setEnabled(enabled
);
128 setTaxon(text_newTaxonName
.getText());
130 else if(eventSource
== checkbox_openInEditor
){
131 setOpenInEditor(checkbox_openInEditor
.getSelection());
134 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
139 * <p>Getter for the field <code>classification</code>.</p>
141 * @return the classification
143 public Classification
getClassification() {
144 return classification
;
148 * <p>isOpenInEditor</p>
150 * @return the openInEditor
152 public boolean isOpenInEditor() {
157 * <p>Getter for the field <code>parentTreeNode</code>.</p>
159 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
161 public ITreeNode
getParentTreeNode() {
162 return parentTreeNode
;
166 * <p>Getter for the field <code>taxon</code>.</p>
170 public Taxon
getTaxon() {
175 * @param classification the classification to set
177 private void setClassification(Classification classification
) {
178 this.classification
= classification
;
179 setParentTreeNode(classification
);
183 * @param parentTreeNode the parentTreeNode to set
185 private void setParentTreeNode(ITreeNode parentTreeNode
) {
186 this.parentTreeNode
= parentTreeNode
;
188 if(parentTreeNode
instanceof Classification
){
189 classification
= (Classification
) parentTreeNode
;
190 selection_classification
.setEntity(classification
);
191 selection_parentTaxonNode
.setEntity(null);
193 else if(parentTreeNode
instanceof TaxonNode
){
194 classification
= (Classification
) HibernateProxyHelper
.deproxy(((TaxonNode
) parentTreeNode
).getClassification());
195 selection_classification
.setEntity(classification
);
196 selection_parentTaxonNode
.setEntity((TaxonNode
) parentTreeNode
);
201 * @param reuseExistingTaxon the reuseExistingTaxon to set
203 private void setTaxon(Taxon taxon
) {
207 private void setTaxon(String taxonNameString
){
208 TaxonNameBase taxonName
= ParseHandler
.parseReferencedName(taxonNameString
, null);
212 private void setTaxon(TaxonNameBase taxonName
){
213 Reference secundum
= null;
214 if(getParentTreeNode() != null){
215 if(getParentTreeNode() instanceof Classification
){
216 secundum
= ((Classification
) getParentTreeNode()).getReference();
218 else if(getParentTreeNode() instanceof TaxonNode
){
219 secundum
= ((TaxonNode
) getParentTreeNode()).getTaxon().getSec();
222 taxon
= Taxon
.NewInstance(taxonName
, secundum
);
226 * @param openInEditor the openInEditor to set
228 private void setOpenInEditor(boolean openInEditor
) {
229 this.openInEditor
= openInEditor
;
235 * @return the complete
237 public boolean isComplete() {