fix #4945: add propertytester for polytomouskeynode to enable menu items only if...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / PolytomousKeyPropertyTester.java
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;
+    }
+
+
+}