fix #5616 Add check for orphaned taxa to CdmViewer context menu
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 13 Sep 2016 11:07:42 +0000 (13:07 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 13 Sep 2016 11:11:17 +0000 (13:11 +0200)
 - removed default handler for this

eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/NameEditorMenuPropertyTester.java
eu.etaxonomy.taxeditor.navigation/plugin.xml

index c8bd4f7..6570a9c 100644 (file)
       </viewCommandMapping>
       <viewCommandMapping
             commandId="eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity"
-            selection="eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache"
-            viewerName="%viewCommandMapping.viewerName.BULK_EDITOR">
-      </viewCommandMapping>
-      <viewCommandMapping
-            commandId="eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity"
             selection="eu.etaxonomy.cdm.model.common.IdentifiableEntity"
             viewerName="%viewCommandMapping.viewerName.BULK_EDITOR">
       </viewCommandMapping>
index 3ef7f17..e32835f 100644 (file)
             name="%command.name.41">
       </command>
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorForTaxonHandler"
             id="eu.etaxonomy.taxeditor.editor.openTaxonEditorForTaxon"
             name="%command.name.42">
          <commandParameter
             </test>
          </with>
       </definition>
+      <definition
+            id="isOrphanedTaxon">
+         <with
+               variable="selection">
+            <test
+                  forcePluginActivation="true"
+                  property="eu.etaxonomy.taxeditor.editor.name.propertyTester.isOrphaned">
+            </test>
+         </with>
+      </definition>
    </extension>
    <extension
          point="org.eclipse.core.expressions.propertyTesters">
             class="eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester"
             id="eu.etaxonomy.taxeditor.editor.name.propertyTester"
             namespace="eu.etaxonomy.taxeditor.editor.name.propertyTester"
-            properties="isAcceptedTaxon,isSynonym,isMisapplication,isTaxonBase,hasEmptyNames,isAcceptedAndHasNoHomotypicSynonyms,isNotHomotypicSynonymOfAcceptedTaxon,isSynonymInHomotypicalGroupWithMoreSynonyms"
+            properties="isAcceptedTaxon,isSynonym,isMisapplication,isTaxonBase,hasEmptyNames,isAcceptedAndHasNoHomotypicSynonyms,isNotHomotypicSynonymOfAcceptedTaxon,isSynonymInHomotypicalGroupWithMoreSynonyms,isOrphaned"
             type="org.eclipse.jface.viewers.IStructuredSelection">
       </propertyTester>
       <propertyTester
index f8a49eb..5eb1e17 100644 (file)
@@ -12,12 +12,15 @@ package eu.etaxonomy.taxeditor.editor.name.handler;
 
 import org.eclipse.jface.viewers.IStructuredSelection;
 
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.Page;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * <p>NameEditorMenuPropertyTester class.</p>
@@ -37,6 +40,7 @@ public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.P
        private static final String ACCEPTED_AND_NO_HOMOTYPIC_SYNONYMS = "isAcceptedAndHasNoHomotypicSynonyms";
        private static final String NOT_HOMOTYPIC_SYNONYM_OF_ACCEPTED = "isNotHomotypicSynonymOfAcceptedTaxon";
        private static final String SYNONYM_WITH_HOMOTYPIC_SYNONYMS = "isSynonymInHomotypicalGroupWithMoreSynonyms";
+       private static final String IS_ORPHANED = "isOrphaned";
 
        /**
         * <p>Constructor for NameEditorMenuPropertyTester.</p>
@@ -57,6 +61,11 @@ public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.P
                        IStructuredSelection selection = (IStructuredSelection) receiver;
 
                        Object selectedElement = selection.getFirstElement();
+                       if(selectedElement instanceof UuidAndTitleCache){
+                           UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache<?>)selectedElement;
+                           CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
+                           selectedElement = cdmBase;
+                       }
 
                        if(ACCEPTED.equals(property)){
                                return isAccepted(selectedElement);
@@ -85,6 +94,9 @@ public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.P
                        else if (SYNONYM_WITH_HOMOTYPIC_SYNONYMS.equals(property)){
                                return isSynonymInHomotypicalGroupWithMoreSynonyms(selectedElement);
                        }
+                       else if (IS_ORPHANED.equals(property)){
+                           return isOrphaned(selectedElement);
+                       }
 
                }
 
@@ -99,7 +111,7 @@ public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.P
                }
                return false;
        }
-       
+
        private boolean isSynonymInHomotypicalGroupWithMoreSynonyms(Object selectedElement) {
                if (isSynonym(selectedElement)){
                        Synonym synonym = (Synonym) selectedElement;
@@ -156,4 +168,8 @@ public class NameEditorMenuPropertyTester extends org.eclipse.core.expressions.P
        private boolean isAccepted(Object selectedElement) {
                return (selectedElement instanceof Taxon  && ! ((Taxon) selectedElement).isMisapplication()) ? true : false;
        }
+
+       private boolean isOrphaned(Object selectedElement) {
+           return selectedElement instanceof Taxon  && ((Taxon) selectedElement).isOrphaned();
+       }
 }
index 4960a05..65c7e18 100644 (file)
             </with>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorForTaxonHandler"
+            commandId="eu.etaxonomy.taxeditor.editor.openTaxonEditorForTaxon">
+         <activeWhen>
+            <and>
+               <not>
+                  <reference
+                        definitionId="isOrphanedTaxon">
+                  </reference>
+               </not>
+            </and>
+         </activeWhen>
+      </handler>
    </extension>