fix #4945: add propertytester for polytomouskeynode to enable menu items only if...
authorKatja Luther <k.luther@bgbm.org>
Thu, 24 Nov 2016 12:41:57 +0000 (13:41 +0100)
committerKatja Luther <k.luther@bgbm.org>
Thu, 24 Nov 2016 12:41:57 +0000 (13:41 +0100)
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyPropertyTester.java [new file with mode: 0755]

index ef0345253959952e95158510f4a3ba4caf50f939..f9b5a937b808d222f33e4ec3fd24dd69289187f6 100644 (file)
                name="taxeditor-editor.separator2"
                visible="true">
          </separator>
-         <dynamic
+        <!-- <dynamic
                class="eu.etaxonomy.taxeditor.editor.name.handler.GroupBasionymContributionItem"
                id="taxeditor-editor.dynamic.setBasionym">
             <visibleWhen>
                   </reference>
                </or>
             </visibleWhen>
-         </dynamic>
+         </dynamic>-->
          <command
                commandId="eu.etaxonomy.taxeditor.editor.name.swapSynonymAndAccepted"
                label="%command.label.17"
                label="%command.label.24"
                style="push">
          </command>
-         <dynamic
+       <!--  <dynamic
                class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
                id="eu.etaxonomy.taxeditor.editor.polytomous.list.cdmViewerContextMenu">
-         </dynamic>
+         </dynamic>-->
          <command
                commandId="eu.etaxonomy.taxeditor.key.polytomous.command.refresh"
                label="%command.label.25"
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.DeleteNodeHandler"
-            commandId="eu.etaxonomy.taxeditor.editor.key.polytomous.command.delete">
+            commandId="eu.etaxonomy.taxeditor.key.polytomous.command.delete">
          <activeWhen>
-            <with
+           <with
                   variable="activePartId">
                <equals
                      value="eu.etaxonomy.taxeditor.editor.key">
                </equals>
             </with>
          </activeWhen>
+         <enabledWhen>
+            <with
+                  variable="selection">
+               <test
+                     property="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester.isKeyNode">
+               </test>
+            </with>
+         </enabledWhen>
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.editor.view.concept.handler.DeleteConceptRelationHandler"
        <handler
             class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.InsertNewNodeHandler"
             commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.node">
-         <activeWhen>
-            <reference
-                  definitionId="isRemoting">
-            </reference>
-         </activeWhen>
+          <enabledWhen>
+             <with
+                   variable="selection">
+            <test
+                  property="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester.isKeyNode">
+            </test>
+         
+             </with>
+          </enabledWhen>
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RemotingCreateSiblingPolytomousKeyNodeHandler"
             commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.sibling">
          <activeWhen>
-            <reference
-                  definitionId="isRemoting">
-            </reference>
+            <with
+                  variable="activePartId">
+               <equals
+                     value="eu.etaxonomy.taxeditor.editor.key">
+               </equals>
+            </with>
          </activeWhen>
+         <enabledWhen>
+             <with
+                   variable="selection">
+            <test
+                  property="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester.isKeyNode">
+            </test>
+         
+             </with>
+          </enabledWhen>
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.handler.defaultHandler.OpenReferencingObjectsView"
             </and>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RefreshNodeNumberingHandler"
+            commandId="eu.etaxonomy.taxeditor.key.polytomous.command.refresh">
+         <enabledWhen>
+            <with
+                  variable="selection">
+               <test
+                     property="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester.isKeyNode">
+               </test>
+            </with>
+         </enabledWhen>
+      </handler>
    </extension>
    <extension
          name="%extension.name"
       </category>
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.key.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.CreateChildNodeHandler"
+           
             id="eu.etaxonomy.taxeditor.key.polytomous.command.new.child"
             name="%command.name.28">
       </command>
        <command
             categoryId="eu.etaxonomy.taxeditor.editor.key.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.InsertNewNodeHandler"
+            
             id="eu.etaxonomy.taxeditor.key.polytomous.command.new.node"
             name="%command.name.58">
       </command>
-      <command
-            categoryId="eu.etaxonomy.taxeditor.editor.key.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.CreateSiblingNodeHandler"
+        <command
+             categoryId="eu.etaxonomy.taxeditor.editor.key.category"
             id="eu.etaxonomy.taxeditor.key.polytomous.command.new.sibling"
             name="%command.name.29">
       </command>
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.key.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RefreshNodeNumberingHandler"
+           
             id="eu.etaxonomy.taxeditor.key.polytomous.command.refresh"
             name="%command.name.30">
       </command>
             name="%command.name.31">
       </command>
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.DeleteNodeHandler"
+            categoryId="eu.etaxonomy.taxeditor.editor.key.category"
             id="eu.etaxonomy.taxeditor.key.polytomous.command.delete"
             name="%command.name.50">
       </command>
          <test
                property="eu.etaxonomy.taxeditor.preference.CdmStorePropertyTester.isRemoting">
          </test>
+      </definition>
+       <definition
+            id="isKeyNode">
+          <with
+                variable="selection">
+             <test
+                   property="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester.isKeyNode">
+             </test>
+          </with>
       </definition>
       <definition
             id="isSequence">
             id="eu.etaxonomy.taxeditor.editor.name.propertyTester"
             namespace="eu.etaxonomy.taxeditor.editor.name.propertyTester"
             properties="isAcceptedTaxon,isSynonym,isMisapplication,isTaxonBase,hasEmptyNames,isAcceptedAndHasNoHomotypicSynonyms,isNotHomotypicSynonymOfAcceptedTaxon,isSynonymInHomotypicalGroupWithMoreSynonyms,isOrphaned"
-            type="org.eclipse.jface.viewers.IStructuredSelection">
+            type="java.lang.Object">
       </propertyTester>
       <propertyTester
             class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DescriptionsMenuPropertyTester"
             properties="isLinkedWithTaxonSelection"
             type="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
       </propertyTester>
+      <propertyTester
+            class="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester"
+            id="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester"
+            namespace="eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyPropertyTester"
+            properties="isKeyNode"
+            type="org.eclipse.jface.viewers.IStructuredSelection">
+      </propertyTester>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">   
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyPropertyTester.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyPropertyTester.java
new file mode 100755 (executable)
index 0000000..1964e04
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.key.polytomous;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+
+/**
+ * @author k.luther
+ * @date 23.11.2016
+ *
+ */
+public class PolytomousKeyPropertyTester extends PropertyTester {
+    private static final String KEYNODE = "isKeyNode";
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+        if(receiver instanceof IStructuredSelection){
+
+            IStructuredSelection selection = (IStructuredSelection) receiver;
+
+            Object selectedElement = selection.getFirstElement();
+            if(KEYNODE.equals(property)){
+                return isKeyNode(selectedElement);
+            }
+        }
+        return false;
+    }
+
+    private boolean isKeyNode(Object selectedElement) {
+        return (selectedElement instanceof PolytomousKeyNode) ? true : false;
+    }
+
+
+}