Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 59729

Summary: Run-> context menu only enabled for a single selection
Product: [Eclipse Project] Platform Reporter: Jared Burns <jared_burns>
Component: DebugAssignee: 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 CLA 2004-04-22 19:38:26 EDT
The Run-> context menu item (object contribution on IResource) is specified to only work on a 
single selection. We should support multi-select.

There are three issues here:
1. The action contribution needs to allow multi-select.
2. Make sure the XML expression language supports multiple arguments.
3. Make sure our PropertyTesters handle the multi-select case.
Comment 1 Darin Wright CLA 2004-04-23 09:31:29 EDT
*** Bug 51506 has been marked as a duplicate of this bug. ***
Comment 2 Jared Burns CLA 2004-04-23 17:10:17 EDT
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>
Comment 3 Jared Burns CLA 2004-04-23 17:15:16 EDT
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.
Comment 4 Darin Swanson CLA 2004-04-27 01:24:53 EDT
Verified.
Shouldn't we take out the "work in progress" in the plugin.xml?