ref #4611 some l10n for taxeditor and taxeditor.editor plugin
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / TaxonEditorInput.java
index cba7d5eff230d0a550b6b8ee5b508fd1b688a0c1..6ead0696208fb95e260e11181f6e123b8543554e 100644 (file)
@@ -9,9 +9,11 @@
 
 package eu.etaxonomy.taxeditor.editor;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
@@ -48,7 +50,9 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 19.03.2009
  * @version 1.0
  */
-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;
 
@@ -58,8 +62,6 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
 
     private TaxonBase initiallySelectedTaxonBase;
 
-    private final ITaxonNodeService service;
-
     private enum CdmType {
         TAXON_NODE,
         TAXON_BASE,
@@ -67,8 +69,8 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
     }
 
     private TaxonEditorInput(UUID uuid, CdmType type) {
+        super(true);
         this.conversation = CdmStore.createConversation();
-        service = CdmStore.getService(ITaxonNodeService.class);
         switch(type) {
         case PARENT_TAXON_NODE:
             initForParentTaxonNode(uuid);
@@ -97,25 +99,24 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
     private void initForTaxonNode(UUID taxonNodeUuid) {
 
 
-        TaxonNode taxonNode = getCdmEntitySession().remoteLoad(service,taxonNodeUuid, null);
-        taxonNode = getCdmEntitySession().load(taxonNode);
+        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);
 
     }
 
     private void initForTaxonBase(UUID taxonBaseUuid) {
-
-        TaxonBase taxonBase = getCdmEntitySession().remoteLoad(CdmStore.getService(ITaxonService.class),taxonBaseUuid);
+        TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid, getTaxonBasePropertyPaths());
         if (taxonBase != null){
             if(taxonBase.isInstanceOf(Taxon.class)){
                 Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
 
                 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();
@@ -132,7 +133,11 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
             }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);
             }
         }
@@ -150,18 +155,19 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
 
         TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
         ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid);
-        parentNode = getCdmEntitySession().load(parentNode);
 
         Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference());
         TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference());
 
         // add the new taxon to the editors persistence context
-        UUID newTaxonNodeUuid = getCdmEntitySession().remoteSave(CdmStore.getService(ITaxonNodeService.class),newTaxonNode);
+        UUID newTaxonNodeUuid = CdmStore.getService(ITaxonNodeService.class).save(newTaxonNode).getUuid();
 
         initForTaxonNode(newTaxonNodeUuid);
     }
 
 
+
+
     private void setInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){
         if(taxonNodes.size() == 1){
             TaxonNode taxonNode = taxonNodes.iterator().next();
@@ -171,9 +177,9 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
             if(taxonNode != null){
                 init(taxonNode);
             }
-        }else if(taxonNodes.size() == 0){
+        } 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. This should not have happened.");
+            MessagingUtils.warningDialog(INCORRECT_STATE,TaxonEditorInput.class,Messages.TaxonEditorInput_TAXON_NOT_IN_CLASSIFICATION);
         }
     }
 
@@ -190,8 +196,7 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
             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);
         }
     }
 
@@ -218,8 +223,6 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
     }
 
 
-
-
     /**
      * <p>NewEmptyInstance</p>
      *
@@ -271,7 +274,7 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
         }
         TaxonNameBase<?, ?> name = getTaxon().getName();
         if (name == null || name.getTitleCache() == null) {
-            return "New taxon";
+            return Messages.TaxonEditorInput_NEW_TAXON;
         } else {
             return name.getTitleCache();
         }
@@ -338,8 +341,8 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
     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;
@@ -435,25 +438,78 @@ public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorIn
         return initiallySelectedTaxonBase;
     }
 
-    @Override
-    public String toString() {
-        return String.format("%s[%s]", this.getClass().getSimpleName(), getTaxon());
-    }
+//    @Override
+//    public String toString() {
+//        return String.format("%s[%s]", this.getClass().getSimpleName(), getTaxon());
+//    }
+
 
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#getService()
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
      */
     @Override
-    public ITaxonNodeService getService() {
-        return service;
+    public List<TaxonNode> getRootEntities() {
+        return Arrays.asList(taxonNode);
     }
 
-
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#getRootEntities()
+     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
      */
     @Override
-    public  List<TaxonNode> getRootEntities() {
-        return Arrays.asList(taxonNode);
+    public void merge() {
+       CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
+    }
+
+    @Override
+    public Map<Object, List<String>> getPropertyPathsMap() {
+        return null;
     }
+
+    private List<String> getTaxonNodePropertyPaths() {
+        List<String> taxonNodePropertyPaths = new ArrayList<String>();
+        for(String propertyPath : getTaxonBasePropertyPaths()) {
+            taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
+        }
+        return taxonNodePropertyPaths;
+    }
+
+    private List<String> getTaxonBasePropertyPaths() {
+        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
+                "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;
+    }
+
 }