merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / TaxonEditorInput.java
index 6a295e64e9a9763f8d9f779ea4d814aab2523b6c..5452a0458934f0005106036673d3807183766aed 100644 (file)
@@ -34,6 +34,7 @@ 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.model.DataChangeBridge;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -47,9 +48,9 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPersistableElement {
 
-       private ConversationHolder conversation;
+       private final ConversationHolder conversation;
 
-       private TaxonNode taxonNode;
+       private final TaxonNode taxonNode;
 
        private TaxonEditorInputDataChangeBehaviour dataChangeBehavior;
 
@@ -90,7 +91,7 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe
        TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, null);
 
                if(taxonNode == null){
-                       EditorUtil.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase.");
+                       MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not of type TaxonNode but [null].");
                        return null;
                }
 
@@ -109,36 +110,37 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe
        TaxonEditorInput input = null;
 
        TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
-       if(taxonBase.isOrphaned()) {
-               EditorUtil.warningDialog("Orphaned Taxon", TaxonEditorInput.class, "This is an orphaned taxon i.e. a taxon that is not connected to a classification and not having any taxonomic relationships. Editing of orphaned taxon is currently not supported.");
-       }
-       else if(taxonBase.isInstanceOf(Taxon.class)){
-               Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
-
-               if (taxon.isMisapplication()){
-                       // TODO get accepted taxon
-                       EditorUtil.info("trying to open Mispplied Name ");
-
-                       Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
-                       Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
-                       for(TaxonRelationship relation : relations){
-                               if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
-                                       acceptedTaxa.add(relation.getToTaxon());
-                               }
-                       }
-                       input =  getInputForMultipleTaxa(conversation, acceptedTaxa);
-
-               }else{
-                       input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes());
-               }
-       }else if(taxonBase instanceof Synonym){
-               Synonym synonym = (Synonym) taxonBase;
-
-               Set<Taxon> taxa = synonym.getAcceptedTaxa();
-               input = getInputForMultipleTaxa(conversation, taxa);
+       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 misapplied Name ");
+
+                               Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
+                               Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
+                               for(TaxonRelationship relation : relations){
+                                       if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+                                               acceptedTaxa.add(relation.getToTaxon());
+                                       }
+                               }
+                               input =  getInputForMultipleTaxa(conversation, acceptedTaxa);
+
+                       }else{
+                               input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes());
+                       }
+               }else if(taxonBase instanceof Synonym){
+                       Synonym synonym = (Synonym) taxonBase;
+
+                       Set<Taxon> taxa = synonym.getAcceptedTaxa();
+                       input = getInputForMultipleTaxa(conversation, taxa);
+               }
+               if (input != null){
+                       input.setInitiallySelectedTaxonBase(taxonBase);
+               }
        }
 
-       input.setInitiallySelectedTaxonBase(taxonBase);
 
        return input;
     }
@@ -154,7 +156,7 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe
                        }
                }else if(taxonNodes.size() == 0){
                        // this is an undesired state
-                       EditorUtil.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, "The accepted taxon is not part of any classification. This should not have happened.");
                }
        return null;
     }
@@ -172,7 +174,7 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe
                        return getInputForMultipleNodes(conversation, taxonNodes);
                }else if(taxa.size() == 0){
                        // this is an undesired state
-                       EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" +
+                       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.");
                }
        return null;