adapt propertyTester to navigator changes
authorKatja Luther <k.luther@bgbm.org>
Thu, 6 Jul 2017 09:43:47 +0000 (11:43 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 6 Jul 2017 09:43:47 +0000 (11:43 +0200)
eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodePropertyTester.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java

index dcbb176eff5279258f07233aab6945ae595578ff..6955405c54c7a117b284d0e8024694ab7779ea05 100644 (file)
                   <reference
                         definitionId="isShowExperimentalFeatures">
                   </reference>
-                  <reference
-                        definitionId="isClassification">
-                  </reference>
+                  <test
+                        property="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester.isClassification">
+                  </test>
                </and>
             </visibleWhen>
          </command>
                   <reference
                         definitionId="isShowExperimentalFeatures">
                   </reference>
-                  <reference
-                        definitionId="isClassification">
-                  </reference>
+                  <test
+                        property="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester.isClassification">
+                  </test>
                </and>
             </visibleWhen>
          </command>
                      <reference
                            definitionId="isTaxonNode">
                      </reference>
+                     <not>
+                     <test
+                           property="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester.isClassification">
+                     </test>
+                     </not>
                   </and>
             </visibleWhen>
          </command>
                style="push">
             <visibleWhen
                   checkEnabled="true">
-                  <reference
-                        definitionId="isTaxonNode">
-                  </reference>
+                  <and>
+                         <reference
+                               definitionId="isTaxonNode">
+                         </reference>
+                         <not>
+                            <test
+                                  property="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester.isClassification">
+                            </test>
+                         </not>
+                  </and>
             </visibleWhen>
          </command>
          <command
                   <reference
                         definitionId="isTaxonNode">
                   </reference>
+                  <not>
+                     <test
+                           property="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester.isClassification">
+                     </test>
+                  </not>
+                     
                </and>
             </visibleWhen>
          </command>
             labelProvider="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodeLabelProvider"
             name="%navigatorContent.name.0">
          <triggerPoints>
-            <or>
+            
                <instanceof
                      value="eu.etaxonomy.cdm.model.taxon.TaxonNode">
                </instanceof>
-               <and>
-                  <instanceof
-                     value="eu.etaxonomy.cdm.model.taxon.Classification">
-                  </instanceof>
-                  <test
-                     forcePluginActivation="true"
-                     property="eu.etaxonomy.taxeditor.propertytests.hasTaxa">
-                  </test>
-               </and>
-            </or>
+                
+            
          </triggerPoints>
          <dropAssistant
                class="eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapterAssistant"
          point="org.eclipse.core.expressions.propertyTesters">
       <propertyTester
             class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
-            id="eu.etaxonomy.taxeditor.propertytests.navigatorPropertyTester"
-            namespace="eu.etaxonomy.taxeditor.propertytests"
-            properties="hasSynonyms"
-            type="eu.etaxonomy.cdm.model.taxon.TaxonNode">
+            id="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
+            namespace="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
+            properties="hasSynonyms, isClassification"
+            type="java.lang.Object">
       </propertyTester>
-      <propertyTester
-            class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
-            id="eu.etaxonomy.taxeditor.propertytests.navigatorPropertyTester"
-            namespace="eu.etaxonomy.taxeditor.propertytests"
+      
+     <propertyTester
+             class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
+            id="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
+            namespace="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
             properties="hasTaxa"
             type="eu.etaxonomy.cdm.model.taxon.TaxonomicTree">
       </propertyTester>
       <propertyTester
-            class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
-            id="eu.etaxonomy.taxeditor.propertytests.navigatorPropertyTester"
-            namespace="eu.etaxonomy.taxeditor.propertytests"
+             class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
+            id="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
+            namespace="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
             properties="hasTaxa"
-            type="eu.etaxonomy.cdm.model.taxon.Classification">
+            type="eu.etaxonomy.cdm.model.taxon.TaxonNode">
       </propertyTester>
    <propertyTester
          class="eu.etaxonomy.taxeditor.preference.PreferencePropertyTester"
             </iterate>
          </with>
       </definition>
-      <definition
-            id="isClassification">
-         <with
-               variable="selection">
-            <iterate
-                  ifEmpty="false">
-               <instanceof
-                     value="eu.etaxonomy.cdm.model.taxon.Classification">
-               </instanceof>
-            </iterate>
-         </with>
-      </definition>
+     
       <definition
             id="isChecklistEditorEnabled">
          <with
index d479315cc5140069f24f6f9d5651e6c4d49cde07..91226da9ac245aa650493a89d41643dd711ec90d 100644 (file)
@@ -7,6 +7,9 @@
  */
 package eu.etaxonomy.taxeditor.navigation.navigator;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import org.eclipse.core.expressions.PropertyTester;
 
 import eu.etaxonomy.cdm.model.taxon.Classification;
@@ -16,10 +19,16 @@ public class TaxonNodePropertyTester extends PropertyTester {
        
        private static final Object HAS_SYNONYMS = "hasSynonyms"; //$NON-NLS-1$
        private static final Object HAS_TAXA = "hasTaxa"; //$NON-NLS-1$
+       private static final Object IS_CLASSIFICATION = "isClassification"; //$NON-NLS-1$
        
        /** {@inheritDoc} */
        public boolean test(Object receiver, String property, Object[] args,
                        Object expectedValue) {
+               if (receiver instanceof Collection){
+                       if (((Collection)receiver).iterator().hasNext()){
+                               receiver = ((Collection)receiver).iterator().next();
+                       }
+               }
                if (receiver instanceof TaxonNode && HAS_SYNONYMS.equals(property)) {
                        Taxon taxon = ((TaxonNode) receiver).getTaxon();
                        if(taxon != null){
@@ -27,9 +36,17 @@ public class TaxonNodePropertyTester extends PropertyTester {
                        }
                }
 
-               if (receiver instanceof Classification && HAS_TAXA.equals(property)) {
-                       Classification taxononomicTree = (Classification) receiver;
-                       return taxononomicTree.getChildNodes().size() > 0;
+               if (receiver instanceof TaxonNode && HAS_TAXA.equals(property)) {
+                       TaxonNode node = (TaxonNode) receiver;
+                       if (!node.hasTaxon()){
+                               return node.getChildNodes().size() > 0;
+                       }else{
+                               return false;
+                       }
+               }
+               if (receiver instanceof TaxonNode && IS_CLASSIFICATION.equals(property)) {
+                       TaxonNode node = (TaxonNode) receiver;
+                       return !node.hasTaxon();
                }
                
                return false;
index 825db1af3ae1faf53024e2a710a13ee529211099..e02afdb1cef6c17a6625b8167303d41ededf1407 100644 (file)
@@ -12,6 +12,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
@@ -31,8 +32,8 @@ public class CloneClassificationHandler extends AbstractHandler {
         ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
         if (currentSelection instanceof IStructuredSelection) {
             Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
-            if (selectedElement instanceof Classification) {
-                Classification classification = (Classification) selectedElement;
+            if (selectedElement instanceof TaxonNode && !((TaxonNode)selectedElement).hasTaxon()) {
+                Classification classification = ((TaxonNode)selectedElement).getClassification();
                 TaxonNavigator taxonNavigator = (TaxonNavigator)AbstractUtility.showView(TaxonNavigator.ID);
                 CloneClassificationWizard wizard = new CloneClassificationWizard(classification);
                 WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);