Refactoring selection elements so they can be configured
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / classification / TaxonNodeDetailElement.java
index cd673aa0cb8208764013ec7b39cbe81507959174..8f44bc55cd19a08f03b930fbd3865d2d5bde60d9 100644 (file)
@@ -1,12 +1,12 @@
 // $Id$
 /**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy 
+ * http://www.e-taxonomy.eu
+ 
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 
 package eu.etaxonomy.taxeditor.ui.section.classification;
 
@@ -32,8 +32,10 @@ import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
 
 /**
- * <p>TaxonNodeDetailElement class.</p>
- *
+ * <p>
+ * TaxonNodeDetailElement class.
+ * </p>
+ * 
  * @author n.hoffmann
  * @created Sep 27, 2010
  * @version 1.0
@@ -41,103 +43,130 @@ import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
 public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode> {
 
        private ClassificationSelectionElement selection_classification;
-       
+
        private Classification classification;
-       
+
        private TaxonNodeSelectionElement selection_parentTaxonNode;
-       
+
        private ITreeNode parentTreeNode;
-       
+
        private TaxonSelectionElement selection_reuseExistingTaxon;
-       
+
        private Taxon taxon;
-       
+
        private TextWithLabelElement text_newTaxonName;
-       
+
        private CheckboxElement checkbox_openInEditor;
-       
+
        private boolean openInEditor;
-       
+
        private boolean complete;
 
        private NameSelectionElement selection_reuseExistingName;
-       
+
        /**
-        * <p>Constructor for TaxonNodeDetailElement.</p>
-        *
-        * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
-        * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
+        * <p>
+        * Constructor for TaxonNodeDetailElement.
+        * </p>
+        * 
+        * @param formFactory
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
+        *            object.
+        * @param formElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
+        *            object.
         */
        public TaxonNodeDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement) {
                super(formFactory, formElement);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
+        * (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
+        * eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
         */
        /** {@inheritDoc} */
        @Override
        protected void createControls(ICdmFormElement formElement,
                        ITreeNode entity, int style) {
-               selection_classification = (ClassificationSelectionElement) formFactory.createSelectionElement(SelectionType.CLASSIFICATION, getConversationHolder(), formElement, "Classification", null, style);
-               selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory.createSelectionElement(SelectionType.TAXON_NODE, getConversationHolder(), formElement, "Parent", null, style);
-               selection_reuseExistingTaxon = (TaxonSelectionElement) formFactory.createSelectionElement(SelectionType.TAXON, getConversationHolder(), formElement, "Reuse existing Taxon", null, style);
-               
-               selection_reuseExistingName = (NameSelectionElement) formFactory.createSelectionElement(SelectionType.NAME, getConversationHolder(), formElement, "Reuse existgin name", null, style);
-               
-               text_newTaxonName = formFactory.createTextWithLabelElement(formElement, "New Taxon", "", style);
-
-               checkbox_openInEditor = formFactory.createCheckbox(formElement, "Open in Editor", true, style);
+               selection_classification = (ClassificationSelectionElement) formFactory
+                               .createSelectionElement(SelectionType.CLASSIFICATION,
+                                               getConversationHolder(), formElement, "Classification",
+                                               null, ClassificationSelectionElement.DEFAULT, style);
+               selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory
+                               .createSelectionElement(SelectionType.TAXON_NODE,
+                                               getConversationHolder(), formElement, "Parent", null,
+                                               TaxonNodeSelectionElement.DEFAULT, style);
+               selection_reuseExistingTaxon = (TaxonSelectionElement) formFactory
+                               .createSelectionElement(SelectionType.TAXON,
+                                               getConversationHolder(), formElement,
+                                               "Reuse existing Taxon", null,
+                                               TaxonSelectionElement.DEFAULT, style);
+
+               selection_reuseExistingName = (NameSelectionElement) formFactory
+                               .createSelectionElement(SelectionType.NAME,
+                                               getConversationHolder(), formElement,
+                                               "Reuse existgin name", null,
+                                               NameSelectionElement.DEFAULT, style);
+
+               text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
+                               "New Taxon", "", style);
+
+               checkbox_openInEditor = formFactory.createCheckbox(formElement,
+                               "Open in Editor", true, style);
                setOpenInEditor(true);
                setParentTreeNode(entity);
        }
 
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
+        * .lang.Object)
         */
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
-               if(eventSource == selection_classification){
+               if (eventSource == selection_classification) {
                        setClassification(selection_classification.getEntity());
-               }
-               else if(eventSource == selection_parentTaxonNode){
+               } else if (eventSource == selection_parentTaxonNode) {
                        setParentTreeNode(selection_parentTaxonNode.getEntity());
-               }
-               else if(eventSource == selection_reuseExistingTaxon){
+               } else if (eventSource == selection_reuseExistingTaxon) {
                        boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
                        selection_reuseExistingName.setEnabled(enabled);
                        text_newTaxonName.setEnabled(enabled);
-                       
-                       setTaxon((Taxon) selection_reuseExistingTaxon.getEntity());
-               }
-               else if(eventSource == selection_reuseExistingName){
+
+                       setTaxon(selection_reuseExistingTaxon.getEntity());
+               } else if (eventSource == selection_reuseExistingName) {
                        boolean enabled = selection_reuseExistingName.getEntity() == null;
                        selection_reuseExistingTaxon.setEnabled(enabled);
                        text_newTaxonName.setEnabled(enabled);
-                       
+
                        setTaxon(selection_reuseExistingName.getEntity());
-               }
-               else if(eventSource == text_newTaxonName){
+               } else if (eventSource == text_newTaxonName) {
                        boolean enabled = CdmUtils.isEmpty(text_newTaxonName.getText());
                        selection_reuseExistingTaxon.setEnabled(enabled);
                        selection_reuseExistingName.setEnabled(enabled);
-                                               
+
                        setTaxon(text_newTaxonName.getText());
-               }
-               else if(eventSource == checkbox_openInEditor){
+               } else if (eventSource == checkbox_openInEditor) {
                        setOpenInEditor(checkbox_openInEditor.getSelection());
                }
-               
+
                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
-               
+
        }
 
        /**
-        * <p>Getter for the field <code>classification</code>.</p>
-        *
+        * <p>
+        * Getter for the field <code>classification</code>.
+        * </p>
+        * 
         * @return the classification
         */
        public Classification getClassification() {
@@ -145,8 +174,10 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode>
        }
 
        /**
-        * <p>isOpenInEditor</p>
-        *
+        * <p>
+        * isOpenInEditor
+        * </p>
+        * 
         * @return the openInEditor
         */
        public boolean isOpenInEditor() {
@@ -154,17 +185,21 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode>
        }
 
        /**
-        * <p>Getter for the field <code>parentTreeNode</code>.</p>
-        *
+        * <p>
+        * Getter for the field <code>parentTreeNode</code>.
+        * </p>
+        * 
         * @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
         */
        public ITreeNode getParentTreeNode() {
                return parentTreeNode;
        }
-       
+
        /**
-        * <p>Getter for the field <code>taxon</code>.</p>
-        *
+        * <p>
+        * Getter for the field <code>taxon</code>.
+        * </p>
+        * 
         * @return the taxon
         */
        public Taxon getTaxon() {
@@ -172,7 +207,8 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode>
        }
 
        /**
-        * @param classification the classification to set
+        * @param classification
+        *            the classification to set
         */
        private void setClassification(Classification classification) {
                this.classification = classification;
@@ -180,58 +216,65 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode>
        }
 
        /**
-        * @param parentTreeNode the parentTreeNode to set
+        * @param parentTreeNode
+        *            the parentTreeNode to set
         */
        private void setParentTreeNode(ITreeNode parentTreeNode) {
                this.parentTreeNode = parentTreeNode;
 
-               if(parentTreeNode instanceof Classification){
+               if (parentTreeNode instanceof Classification) {
                        classification = (Classification) parentTreeNode;
                        selection_classification.setEntity(classification);
                        selection_parentTaxonNode.setEntity(null);
-               }
-               else if(parentTreeNode instanceof TaxonNode){
-                       classification = (Classification) HibernateProxyHelper.deproxy(((TaxonNode) parentTreeNode).getClassification());
+               } else if (parentTreeNode instanceof TaxonNode) {
+                       classification = (Classification) HibernateProxyHelper
+                                       .deproxy(((TaxonNode) parentTreeNode).getClassification());
                        selection_classification.setEntity(classification);
                        selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
-               }               
+               }
        }
 
        /**
-        * @param reuseExistingTaxon the reuseExistingTaxon to set
+        * @param reuseExistingTaxon
+        *            the reuseExistingTaxon to set
         */
        private void setTaxon(Taxon taxon) {
                this.taxon = taxon;
        }
-       
-       private void setTaxon(String taxonNameString){
-               TaxonNameBase taxonName = ParseHandler.parseReferencedName(taxonNameString, null);
+
+       private void setTaxon(String taxonNameString) {
+               TaxonNameBase taxonName = ParseHandler.parseReferencedName(
+                               taxonNameString, null);
                setTaxon(taxonName);
        }
-       
-       private void setTaxon(TaxonNameBase taxonName){
+
+       private void setTaxon(TaxonNameBase taxonName) {
                Reference secundum = null;
-               if(getParentTreeNode() != null){
-                       if(getParentTreeNode() instanceof Classification){
-                               secundum = ((Classification) getParentTreeNode()).getReference();
-                       }
-                       else if(getParentTreeNode() instanceof TaxonNode){
-                               secundum = ((TaxonNode) getParentTreeNode()).getTaxon().getSec();
+               if (getParentTreeNode() != null) {
+                       if (getParentTreeNode() instanceof Classification) {
+                               secundum = ((Classification) getParentTreeNode())
+                                               .getReference();
+                       } else if (getParentTreeNode() instanceof TaxonNode) {
+                               secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
+                                               .getSec();
                        }
                }
                taxon = Taxon.NewInstance(taxonName, secundum);
        }
 
        /**
-        * @param openInEditor the openInEditor to set
+        * @param openInEditor
+        *            the openInEditor to set
         */
        private void setOpenInEditor(boolean openInEditor) {
                this.openInEditor = openInEditor;
        }
 
        /**
-        * <p>isComplete</p>
-        *
+        * <p>
+        * isComplete
+        * </p>
+        * 
         * @return the complete
         */
        public boolean isComplete() {