Merge branch 'release/5.26.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / newWizard / NewTaxonNodeWizard.java
index ae40775d8c33661f629587ab89541e9d1b8ea574..9526758c7a0822b25aae12ecfb86aa5934545fd7 100644 (file)
@@ -1,6 +1,11 @@
 /**
- *
- */
+* 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.newWizard;
 
 import java.util.Map;
@@ -16,9 +21,11 @@ import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.dto.CreateTaxonDTO;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.reference.NamedSource;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@ -27,7 +34,7 @@ import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
 
 /**
- * <p>NewTaxonNodeWizard class.</p>
+ * NewTaxonNodeWizard class.
  *
  * @author n.hoffmann
  * @created Sep 15, 2009
@@ -41,11 +48,6 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
     private boolean isOpenInEditor = false;
     private boolean success = true;
 
-    /**
-     * <p>Constructor for AbstractNewEntityWizard.</p>
-     *
-     * @param <T> a T object.
-     */
     @Inject
     public NewTaxonNodeWizard(){
         setWindowTitle(Messages.TaxonNodeWizardPage_new);
@@ -67,25 +69,23 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
             try{
                UpdateResult result;
                TaxonNode parent = getParentEntity();
-               Map<Language, LanguageString> nodes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
-               UUID refUuid = parent.getReference() != null? parent.getReference().getUuid(): null;
-
-               TaxonNodeStatus status = null;
-               if( ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isUnplaced()){
-                   status = TaxonNodeStatus.UNPLACED;
-               }else if( ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isPlacementDoubtful()){
-                   status = TaxonNodeStatus.DOUBTFUL;
-               }else if (((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isExcluded()){
-                   status = TaxonNodeStatus.EXCLUDED;
+
+               Map<Language, LanguageString> notes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
+               NamedSource source = parent.getSource().checkEmpty()? null: parent.getSource();
+
+               TaxonNodeStatus status = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getTaxonNodeStatus();
+               if (status == null){
+                   notes = null;
                }
-               result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, refUuid, parent.getMicroReference(),
-                        status, nodes);
+
+               result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(),
+                       taxon, source, parent.getMicroReference(), status, notes);
 
 
                if (result.isOk()){
                    this.setEntity((TaxonNode)result.getCdmEntity());
-                   CdmApplicationState.getCurrentDataChangeService()
-                                .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
+                    CdmApplicationState.getCurrentDataChangeService()
+                             .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
 
                     }else{
                         setSuccess(false);
@@ -104,33 +104,6 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
         }
     }
 
-//    @Override
-//    protected TaxonNode createNewEntity() {
-//        if(getSelection() != null){
-//            Object selectedObject = getSelection().getFirstElement();
-//            if(selectedObject instanceof TaxonNodeDto){
-//                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
-//             TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
-//             Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
-//             Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
-//             TaxonNode child = node.addChildTaxon(newTaxon, null, null);
-//
-//                return child;
-//
-//            }
-//        }
-//
-//        return null;
-//    }
-
-
-    /**
-     * <p>
-     * openInEditor
-     * </p>
-     *
-     * @return a boolean.
-     */
     public boolean openInEditor() {
         return isOpenInEditor ;
     }
@@ -139,20 +112,10 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
         this.isOpenInEditor = isOpenInEditor;
     }
 
-    /**
-     * <p>openEmpty</p>
-     *
-     * @return a boolean.
-     */
     public boolean openEmpty(){
         return openInEditor() && openEmptyEditor;
     }
 
-    /**
-     * <p>getTaxonNode</p>
-     *
-     * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
-     */
     public TaxonNode getTaxonNode(){
         if(generatedTaxonNodeUuid != null){
             return CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
@@ -173,12 +136,10 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
         this.wizardPageListener = wizardPageListener;
     }
 
-
     public boolean isSuccess() {
         return success;
     }
 
-
     public void setSuccess(boolean success) {
         this.success = success;
     }
@@ -193,6 +154,4 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<Taxon
             }
         }
     }
-
-
-}
+}
\ No newline at end of file