| Summary: | Run-> context menu only enabled for a single selection | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Jared Burns <jared_burns> |
| Component: | Debug | Assignee: | Darin Swanson <Darin_Swanson> |
| Status: | VERIFIED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P2 | CC: | darin.eclipse, ebelisar |
| Version: | 3.0 | ||
| Target Milestone: | 3.0 M9 | ||
| Hardware: | PC | ||
| OS: | All | ||
| Whiteboard: | |||
|
Description
Jared Burns
*** Bug 51506 has been marked as a duplicate of this bug. *** It turns out that the only thing we needed to do to make this work was tweak our objection
contribution to allow for multi-selection. Once that's done, clients are free to specify their own
property testers that deal with multiselection.
The only slightly unfortunate thing is that clients need to know to contribute their property tester to
java.util.ArrayList, the concrete type that our action passes into the "evaluation context" for the
property tester. But once they contribute this, they can do whatever they want with their tester.
The following example shows how to do this to specify that exactly one *.java and one *.class file
must be selected. I left a bunch of sysouts in it to make the flow easier to see:
public boolean test(Object receiver, String method, Object[] args, Object expectedValue) {
if (receiver instanceof List) {
if (!"classAndJava".equals(method)) {
System.out.println("Wrong method: " + method);
return false;
}
List list= (List) receiver;
boolean javaFound= false;
boolean classFound= false;
Iterator iter= list.iterator();
while (iter.hasNext()) {
Object selection = iter.next();
if (!(selection instanceof IResource)) {
System.out.println("Selection contains non-resource: " + selection.getClass());
return false;
}
IResource resource= (IResource) selection;
if (nameMatches(resource, "*.java")) {
if (javaFound == true) {
System.out.println("Two *.java selected");
return false;
}
javaFound= true;
} else if (nameMatches(resource, "*.class")) {
if (classFound == true) {
System.out.println("Two *.class selected");
return false;
}
classFound= true;
} else {
System.out.println("Name doesn't match *.java or *.class");
return false;
}
}
return javaFound && classFound;
}
}
This is what the property tester contribution looks like:
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
namespace="org.eclipse.jdt.debug.ui"
properties="classAndJava"
type="java.util.ArrayList"
class="org.eclipse.jdt.internal.debug.ui.launcher.ResourceExtender"
id="org.eclipse.jdt.debug.ClassAndJavaTester">
</propertyTester>
</extension>
And here's what my enablement expression looks like:
<enablement>
<with variable="selection">
<count value="+"/>
<test property="org.eclipse.jdt.debug.ui.classAndJava"/>
</with>
</enablement>
Took a while to figure this out, but at least I understand how it works now. :) One-character change to org.eclipse.debug.ui/plugin.xml. Please verify, DarinS. Verified. Shouldn't we take out the "work in progress" in the plugin.xml? |