Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse RCP PropertyTester never gets called via menu visibleWhen

I'd like to implement a custom propertytester for my custom navigator view pop-up menu. Unfortunately it never actually gets called. Here are the plugin.xml parts and the class.

The defined property tester:

<extension
     point="org.eclipse.core.expressions.propertyTesters">
  <propertyTester
        class="com.mytest.MyPropertyTester"
        id="com.mytest.myPropertyTester"
        namespace="com.mytest.myPropertyTester"
        properties="testProperty"
        type="com.mytest.MyPropertyTester">
  </propertyTester>

The definition part:

<extension
     point="org.eclipse.core.expressions.definitions">
  <definition
        id="org.eclipse.example.testExtension">
     <adapt
           type="org.eclipse.core.resources.IResource">
        <test
              property="com.mytest.myPropertyTester.testProperty">
        </test>
     </adapt>
  </definition>

The visibleWhen part:

<command
           commandId="com.mytest.testcommand"
           label="Test Command"
           style="push">
         <visibleWhen
              checkEnabled="false">
           <with
                 variable="activeMenuSelection">
              <iterate
                    ifEmpty="false"
                    operator="or">
                 <or>
                    <reference
                          definitionId="org.eclipse.example.testExtension">
                    </reference>
                 </or>
              </iterate>
           </with>
        </visibleWhen>
     </command>

And the corresponding class:

package com.mytest;

import org.eclipse.core.expressions.PropertyTester;

public class MyPropertyTester extends PropertyTester {

public MyPropertyTester() {
    System.out.println("PROPERTY TESTER CONSTRUCTOR");
}

@Override
public boolean test(Object receiver, String property, Object[] args,
        Object expectedValue) {
    System.out.println("PROPERTY TESTER CALLED");
    return true;
}

}

Without the "test" used in the org.eclipse.core.expressions.definitions part everything works fine.

It seems that not even the constructor of the MyPropertyTester class gets called. I haven’t really found any working example regarding this.

Any help would be appreciated.

like image 641
breakline Avatar asked Jan 23 '14 14:01

breakline


2 Answers

I know this question was answered already, but I faced the same problem due to a different reason; so just thought I will put it out here.

In my case, the org.eclipse.core.expressions plugin was not activated at the point my <test> expression was evaluated, so it was simply skipping the evaluation.

So I had to force the plugin activation using forcePluginActivation=true, like:

<test 
      property="org.eclipse.wst.xml.core.isSelectedElementARunnableSeleniumTestSuite"
      value="true" 
      forcePluginActivation="true">
</test>

Quoting the documentation,

  • forcePluginActivation - a flag indicating whether the plug-in contributing the property tester should be loaded if necessary. As such, this flag should be used judiciously, in order to avoid unnecessary plug-in activations. Most clients should avoid setting this flag to true. This flag is only honored if the evaluation context used to evaluate this expression allows plug-in activation. Otherwise the flag is ignored and no plug-in loading takes place.
like image 109
mystarrocks Avatar answered Nov 14 '22 23:11

mystarrocks


I think this is your type value (type="com.mytest.MyPropertyTester") in your propertyTester definition.

The object to be tested must be an instance of the type (or adapt to) before the tester will be called (the help is very vague about this!).

Use type="org.eclipse.core.runtime.IAdaptable" which will match most objects or type="org.eclipse.core.resources.IResource" to just match resources.

like image 43
greg-449 Avatar answered Nov 14 '22 22:11

greg-449