Create taxon/parse name when wizard is closed and not with every key
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Apr 2016 14:05:31 +0000 (16:05 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Apr 2016 14:05:31 +0000 (16:05 +0200)
stroke #5605

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeWizardPage.java

index 0586c53..e8dfc55 100644 (file)
@@ -48,12 +48,12 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizard<ITaxonTreeNode>{
 
     @Override
     protected void saveEntity() {
-        if(taxonNodePage.getTaxon() == null || StringUtils.isEmpty(taxonNodePage.getTaxon().getName().getFullTitleCache())){
+        Taxon taxon = taxonNodePage.createTaxon();
+        if(taxon == null || StringUtils.isEmpty(taxon.getName().getFullTitleCache())){
             openEmptyEditor = true;
         }else{
             getConversationHolder().bind();
             ITaxonTreeNode parent = getParentTreeNode();
-            Taxon taxon = taxonNodePage.getTaxon();
             Reference sec = taxon.getSec();
             taxon.setSec(null);
             try{
index 5ac40f5..6d347db 100644 (file)
@@ -11,6 +11,7 @@
 package eu.etaxonomy.taxeditor.ui.section.classification;
 
 import org.apache.commons.lang.StringUtils;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
@@ -22,7 +23,6 @@ import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.parser.ParseHandler;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -55,8 +55,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
 
        private Taxon taxon;
 
-       private Reference secReference;
-
        private TextWithLabelElement textNewTaxonName;
 
        private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
@@ -170,8 +168,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        setClassification(selection_classification.getEntity());
                } else if (eventSource == selection_parentTaxonNode) {
                        setParentTreeNode(selection_parentTaxonNode.getEntity());
-               } else if (eventSource == selection_SecRef) {
-                       setSecReference(selection_SecRef.getEntity());
                } else if (eventSource == selection_reuseExistingTaxon) {
                                boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
                                selection_reuseExistingName.setEnabled(enabled);
@@ -203,7 +199,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        selection_reuseExistingTaxon.setEnabled(enabled);
                        selection_reuseExistingName.setEnabled(enabled);
 
-                       setTaxon(textNewTaxonName.getText());
                        complete = !textNewTaxonName.getText().isEmpty();
                } else if (eventSource == checkbox_openInEditor) {
                        setOpenInEditor(checkbox_openInEditor.getSelection());
@@ -229,10 +224,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                return parentTreeNode;
        }
 
-       public Taxon getTaxon() {
-               return taxon;
-       }
-
        private void setClassification(Classification classification) {
                this.classification = classification;
                setParentTreeNode(classification);
@@ -268,11 +259,6 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
         selection_SecRef.setEntity(((TaxonNode)treeNode).getTaxon().getSec());
        }
 
-       private void setSecReference(Reference secRef){
-               this.secReference = secRef;
-               setTaxon(textNewTaxonName.getText());
-       }
-
        private void setTaxon(Taxon taxon) {
                this.taxon = taxon;
                if (isCreateNew()){
@@ -281,24 +267,12 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                selection_SecRef.setEntity(taxon.getSec());
        }
 
-       private void setTaxon(String taxonNameString) {
-               TaxonNameBase taxonName = ParseHandler.parseReferencedName(
-                               taxonNameString, null);
-               setTaxon(taxonName);
-       }
-
        private void setTaxon(TaxonNameBase taxonName) {
                Reference secundum = null;
                if (getParentTreeNode() != null) {
                        if (this.selection_SecRef.getEntity() != null){
                                secundum = this.selection_SecRef.getEntity();
-                       } /*else if (getParentTreeNode() instanceof Classification) {
-                               secundum = ((Classification) getParentTreeNode())
-                                               .getReference();
-                       } else if (getParentTreeNode() instanceof TaxonNode) {
-                               secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
-                                               .getSec();
-                       }*/
+                       }
                }
                if (taxonName != null){
                    taxon = Taxon.NewInstance(taxonName, secundum);
@@ -314,10 +288,18 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                this.openInEditor = openInEditor;
        }
 
-       public TextWithLabelElement getTextNewTaxonName() {
-        return textNewTaxonName;
+       public String getTaxonName() {
+        return textNewTaxonName.getText();
     }
 
+       public Reference getReference(){
+           return selection_SecRef.getSelection();
+       }
+
+       public Control getMainControl(){
+           return textNewTaxonName.getMainControl();
+       }
+
        public boolean isComplete() {
            boolean allComplete = true;
            if (!isCreateNew()){
index 62d9578..f6e7a30 100644 (file)
@@ -16,9 +16,12 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
+import eu.etaxonomy.taxeditor.parser.ParseHandler;
 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -75,7 +78,7 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
                detailElement.setEntity(entity);
                formFactory.addPropertyChangeListener(this);
                if (isCreateNew){
-                   detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
+                   detailElement.getMainControl().addListener(SWT.KeyDown, this);
                }
                return detailElement;
        }
@@ -112,7 +115,7 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
                        setMessage("No classification set.", WARNING);
                }
                else if(isCreateNew ){
-                   if(detailElement.getTextNewTaxonName().getText().isEmpty()){
+                   if(detailElement.getTaxonName().isEmpty()){
                        setMessage("No taxon name set.", ERROR);
                    } else{
                        setMessage(null);
@@ -144,8 +147,11 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
                                .getParentTreeNode();
        }
 
-       public Taxon getTaxon() {
-               return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
+       public Taxon createTaxon() {
+               String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
+               Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
+               NonViralName parseReferencedName = ParseHandler.parseReferencedName(taxonName, null);
+               return Taxon.NewInstance(parseReferencedName, reference);
        }
 
        /*
@@ -163,7 +169,7 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
     @Override
     public void handleEvent(Event event) {
         TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
-        if(event.widget == detailElement.getTextNewTaxonName().getMainControl()
+        if(event.widget == detailElement.getMainControl()
                 && event.keyCode == SWT.CR && isPageComplete()){
             wizardPageListener.close();
         }