Enablement Expression and Property Tester

Source: http://www.eclipse.org/webtools/wst/components/server/runOnServer.html

Enablement Expression Performance

Enablement expressions allow you to create arbitrarily complex expressions using ands, ors, nots, and Java code. For performance reasons, it’s always better to use the expression support instead of using Java code, which is slower or may be in plugins that aren’t loaded yet. However, simple Java tests can provide much better flexibility and do not need to cause large delays.

The best practice is to use enablement expressions as much as possible to filter down the number and types of objects that are applicable. As a final check, a property tester can then be used. However, it is still important to use expressions first, even if you know you’ll be using a property tester for the last check – this will keep the performance up for all the objects that are filtered out.

Adding a Property Tester

To add a property tester to an enablement expression, try using the following example. In your plugin.xml, add the propertyTesters extension point:

<extension point="org.eclipse.core.expressions.propertyTesters">

Inside your plugin, add and implement the property tester code:

package org.eclipse.myplugin.internal;
import org.eclipse.core.expressions.PropertyTester;

public class MyPropertyTester extends PropertyTester {
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
// cast receiver and/or expectedValue
// if (xx) // check some dynamic property
return true;
// else
//return false;

You can now use a property expression within the enablement:

<test property="org.eclipse.myplugin.someProperty" value="true"/>

This entry was posted in Eclipse, Tricks. Bookmark the permalink.

Comments are closed.