Merge branch 'develop' into nameEditorE4
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / TaxonEditorInput.java
index d127c3f317347b866f89fcb6f23b84ce44643c29..a42076cf1d1555619ba281e252e0c3b9388980f5 100644 (file)
@@ -28,7 +28,7 @@ import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -37,6 +37,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
@@ -52,6 +53,8 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorInput, IConversationEnabled, IPersistableElement {
 
  */
 public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorInput, IConversationEnabled, IPersistableElement {
 
+    private static final String INCORRECT_STATE = Messages.TaxonEditorInput_INCORRECT_STATE;
+
     private final ConversationHolder conversation;
 
     private TaxonNode taxonNode;
     private final ConversationHolder conversation;
 
     private TaxonNode taxonNode;
@@ -100,7 +103,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
         TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, getTaxonNodePropertyPaths());
 
         if(taxonNode == null){
         TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, getTaxonNodePropertyPaths());
 
         if(taxonNode == null){
-            MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase.");
+            MessagingUtils.warningDialog(Messages.TaxonEditorInput_NOT_IMPLEMENTED, TaxonEditorInput.class, Messages.TaxonEditorInput_NOT_IMPLEMENTED_MESSAGE);
         }
         init(taxonNode);
 
         }
         init(taxonNode);
 
@@ -114,7 +117,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
 
                 if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){
                     // TODO get accepted taxon
 
                 if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){
                     // TODO get accepted taxon
-                    MessagingUtils.info("trying to open Mispplied Name ");
+                    MessagingUtils.info(Messages.TaxonEditorInput_OPEN_MISSAPPLIED_NAME);
 
                     Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
                     Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
 
                     Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
                     Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
@@ -131,7 +134,11 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
             }else if(taxonBase instanceof Synonym){
                 Synonym synonym = (Synonym) taxonBase;
 
             }else if(taxonBase instanceof Synonym){
                 Synonym synonym = (Synonym) taxonBase;
 
-                Set<Taxon> taxa = synonym.getAcceptedTaxa();
+                Set<Taxon> taxa = new HashSet<>();
+                Taxon taxon = synonym.getAcceptedTaxon();
+                if (taxon != null){
+                       taxa.add(taxon);
+                }
                 setInputForMultipleTaxa(conversation, taxa);
             }
         }
                 setInputForMultipleTaxa(conversation, taxa);
             }
         }
@@ -147,7 +154,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     private void initForParentTaxonNode(UUID parentNodeUuid){
 
 
     private void initForParentTaxonNode(UUID parentNodeUuid){
 
 
-        TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
+        TaxonName name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
         ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid);
 
         Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference());
         ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid);
 
         Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference());
@@ -173,9 +180,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
             }
         } else if (taxonNodes.size() == 0) {
             // this is an undesired state
             }
         } else if (taxonNodes.size() == 0) {
             // this is an undesired state
-            MessagingUtils.warningDialog("Incorrect state",TaxonEditorInput.class,"The accepted "
-                    + "taxon is not part of any classification. Editing with the "
-                    + "name editor is currently not implemented. Try to edit the taxon with the bulk editor.");
+            MessagingUtils.warningDialog(INCORRECT_STATE,TaxonEditorInput.class,Messages.TaxonEditorInput_TAXON_NOT_IN_CLASSIFICATION);
         }
     }
 
         }
     }
 
@@ -192,8 +197,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
             setInputForMultipleNodes(conversation, taxonNodes);
         }else if(taxa.size() == 0){
             // this is an undesired state
             setInputForMultipleNodes(conversation, taxonNodes);
         }else if(taxa.size() == 0){
             // this is an undesired state
-            MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" +
-                    " no accepted taxa are present. This should not have happened.");
+            MessagingUtils.warningDialog(INCORRECT_STATE, TaxonEditorInput.class, Messages.TaxonEditorInput_NO_ACCEPTED_TAXON_PRESENT);
         }
     }
 
         }
     }
 
@@ -269,9 +273,9 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
         if(getTaxon() == null){
             return null;
         }
         if(getTaxon() == null){
             return null;
         }
-        TaxonNameBase<?, ?> name = getTaxon().getName();
+        TaxonName name = getTaxon().getName();
         if (name == null || name.getTitleCache() == null) {
         if (name == null || name.getTitleCache() == null) {
-            return "New taxon";
+            return Messages.TaxonEditorInput_NEW_TAXON;
         } else {
             return name.getTitleCache();
         }
         } else {
             return name.getTitleCache();
         }
@@ -338,8 +342,8 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     public boolean equals(Object obj) {
         if (TaxonEditorInput.class.equals(obj.getClass())
                 && getTaxon() != null
     public boolean equals(Object obj) {
         if (TaxonEditorInput.class.equals(obj.getClass())
                 && getTaxon() != null
-                && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){
-            if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){
+                && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())) {
+            if (((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){
                 setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase());
             }
             return true;
                 setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase());
             }
             return true;
@@ -454,9 +458,8 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
      */
     @Override
     public void merge() {
      */
     @Override
     public void merge() {
-        if(CdmStore.getCurrentSessionManager().isRemoting()) {
-            CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
-        }
+       CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
     }
 
     @Override
     }
 
     @Override
@@ -467,44 +470,44 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     private List<String> getTaxonNodePropertyPaths() {
         List<String> taxonNodePropertyPaths = new ArrayList<String>();
         for(String propertyPath : getTaxonBasePropertyPaths()) {
     private List<String> getTaxonNodePropertyPaths() {
         List<String> taxonNodePropertyPaths = new ArrayList<String>();
         for(String propertyPath : getTaxonBasePropertyPaths()) {
-            taxonNodePropertyPaths.add("taxon." + propertyPath);
+            taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
         }
         return taxonNodePropertyPaths;
     }
 
     private List<String> getTaxonBasePropertyPaths() {
         List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
         }
         return taxonNodePropertyPaths;
     }
 
     private List<String> getTaxonBasePropertyPaths() {
         List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
-                "sec",
-                "createdBy",
-                "updatedBy",
-                "annotations",
-                "markers",
-                "credits",
-                "extensions",
-                "rights",
-                "sources",
-                "descriptions",
-                "relationsToThisTaxon",
-                "relationsFromThisTaxon",
-                "taxonNodes",
-                "descriptions.descriptionElements.feature",
-                "descriptions.descriptionElements.area",
-                "descriptions.descriptionElements.status",
-                "descriptions.markers",
-                "name.descriptions",
-                "name.typeDesignations",
-                "name.status",
-                "name.nomenclaturalReference.inReference",
-                "name.taxonBases.taxonNodes",
-                "name.relationsFromThisName",
-                "name.relationsToThisName",
-                "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status",
-                "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName",
-                "synonymRelations.synonym.name.status.type",
-                "synonymRelations.synonym.name.relationsToThisName.fromName",
-                "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship",
-                "synonymRelations.synonym.name.nomenclaturalReference.authorship",
-                "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations"
+                "sec", //$NON-NLS-1$
+                "createdBy", //$NON-NLS-1$
+                "updatedBy", //$NON-NLS-1$
+                "annotations", //$NON-NLS-1$
+                "markers", //$NON-NLS-1$
+                "credits", //$NON-NLS-1$
+                "extensions", //$NON-NLS-1$
+                "rights", //$NON-NLS-1$
+                "sources", //$NON-NLS-1$
+                "descriptions", //$NON-NLS-1$
+                "relationsToThisTaxon", //$NON-NLS-1$
+                "relationsFromThisTaxon", //$NON-NLS-1$
+                "taxonNodes", //$NON-NLS-1$
+                "descriptions.descriptionElements.feature", //$NON-NLS-1$
+                "descriptions.descriptionElements.area", //$NON-NLS-1$
+                "descriptions.descriptionElements.status", //$NON-NLS-1$
+                "descriptions.markers", //$NON-NLS-1$
+                "name.descriptions", //$NON-NLS-1$
+                "name.typeDesignations", //$NON-NLS-1$
+                "name.status", //$NON-NLS-1$
+                "name.nomenclaturalReference.inReference", //$NON-NLS-1$
+                "name.taxonBases.taxonNodes", //$NON-NLS-1$
+                "name.relationsFromThisName", //$NON-NLS-1$
+                "name.relationsToThisName", //$NON-NLS-1$
+                "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status", //$NON-NLS-1$
+                "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName", //$NON-NLS-1$
+                "synonymRelations.synonym.name.status.type", //$NON-NLS-1$
+                "synonymRelations.synonym.name.relationsToThisName.fromName", //$NON-NLS-1$
+                "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship", //$NON-NLS-1$
+                "synonymRelations.synonym.name.nomenclaturalReference.authorship", //$NON-NLS-1$
+                "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations" //$NON-NLS-1$
         });
 
         return taxonBasePropertyPaths;
         });
 
         return taxonBasePropertyPaths;