- pre-fill parent taxon name in new taxon wizard (#4860)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / classification / TaxonNodeDetailElement.java
index 298080f403064eff43be41fcfc103b692dbf98d8..79ec3ffe4e85e450526ec7c79485d4ebb3945a19 100644 (file)
 
 package eu.etaxonomy.taxeditor.ui.section.classification;
 
+import org.eclipse.swt.widgets.Text;
+
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Classification;
@@ -111,6 +115,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
                                "New Taxon", "", style);
                text_newTaxonName.setFocus();
+               preFillParentTaxonName();
 
                checkbox_openInEditor = formFactory.createCheckbox(formElement,
                                "Open in Editor", true, style);
@@ -118,7 +123,33 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                setParentTreeNode(entity);
        }
 
-       /*
+       private void preFillParentTaxonName() {
+        if(getEntity() instanceof TaxonNode){
+            TaxonNode node = (TaxonNode)getEntity();
+            if(node.getTaxon()!=null){
+                Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
+                if(taxon.getName()!=null && taxon.getName().isInstanceOf(NonViralName.class)){
+                    NonViralName<?> name = HibernateProxyHelper.deproxy(node.getTaxon().getName(), NonViralName.class);
+                    if(!name.getRank().isHigher(Rank.GENUS())){
+                        String taxonName = "";
+                        if(name.isGenus() || name.isInfraGeneric()){
+                            taxonName = name.getGenusOrUninomial();
+                        }
+                        else if(name.isSpecies() || name.isInfraSpecific()){
+                            taxonName = name.getGenusOrUninomial() +" "+ name.getSpecificEpithet();
+                        }
+                        text_newTaxonName.setText(taxonName+" ");
+                        if(text_newTaxonName.getMainControl() instanceof Text){
+                            Text text = (Text)text_newTaxonName.getMainControl();
+                            text.setSelection(text_newTaxonName.getText().length());
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /*
         * (non-Javadoc)
         *
         * @see