Basically, I want to enable my LaunchShortcuts only when project has specific nature and contains specific file. Project's nature is not a problem. However, I can't find out how to check if project contains specific file. By far I have the following code in the plugin.xml
:
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.projectNature"
value="my.project.nature" />
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
Is it possible to check if a project contains a specific file ?
UPDATED:
@greg-449 gave me a great hint in the 1 comment below about using custom org.eclipse.core.expressions.propertyTesters. So, now my code looks like this:
.
.
.
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
id="my.tester"
type="org.eclipse.core.resources.IResource"
namespace="my.namespace"
properties="myProperty"
class="my.MyTester">
</propertyTester>
</extension>
.
.
.
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<and>
<test property="org.eclipse.core.resources.projectNature"
value="my.project.nature" />
<test property="my.namespace.myProperty"
value="true"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
Here is the code of MyTester:
public class MyTester extends PropertyTester {
private static final String PROPERTY_NAME = "myProperty";
@Override
public boolean test(Object receiver, String property, Object[] arg2, Object expectedValue) {
if (property.equals(PROPERTY_NAME) && receiver instanceof IProject) {
return FileUtil.containsSpecificFile((IProject) receiver);
}
return false;
}
}
But this approach doesn't seem to work. While debugging MyTester.test() is never called. Any ideas?