我的一位才华横溢的同事刚刚找到了 eclipse >= 3.3 的答案:
以下是如何在 plugin.xml 中定义命令:
<command
commandId="com.acme.bo.command.done"
id="com.acme.bo.menu.done"
label="Command to do">
<visibleWhen>
<with variable="activeMenuSelection">
<iterate>
<adapt type="com.acme.bo.model.Pojo"></adapt>
<test
args="valueThatYouWantToPassTest"
property="com.acme.namespace.testedProperty"
value="something">
</test>
</iterate>
</with>
</visibleWhen>
</command>
然后,您必须再次在 plugin.xml 中定义 propertyTester:
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.acme.namespace.tester.YourPropertyTester"
id="com.acme.namespace.tester.testedPropertyTester"
namespace="com.acme.namespace"
properties="testedProperty"
type="com.acme.bo.model.Pojo">
</propertyTester>
</extension>
这是进行测试的YourPropertyTester类:
package com.acme.namespace.tester;
import org.eclipse.core.expressions.PropertyTester;
import com.acme.bo.model.Pojo;
public class YourPropertyTester extends PropertyTester {
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver == null || !(receiver instanceof Pojo))
return false;
Pojo pojo = (Pojo) receiver;
if (args != null) {
for (Object object : args) {
if (pojo.getYourProperty().contains((String)object))
return true;
}
}
return false;
}
}