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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With