SWT - TreeViewer - 单个 Select 与多个 Select

SWT - TreeViewer - Single Select vs Multi-Select

请注意使用了 Eclipse RCP。

我已经使用 CTRL+鼠标单击为现有的树查看器启用了 Multi-select。现在我需要为右键单击提供两个菜单:

 One menu item on Single Selection.
 A different menu item for Multiple Selection.

当前通过 plugin.xml 的扩展定义可用于单选,其中检查 selected 对象是否是 instanceof 某个值。

如何识别多个select?扩展定义中multi-select需要检查什么。

   <definition
        id="com.sample.rightclickmenu.singleselect.id.expression">
     <with
           variable="org.eclipse.ui.selection">
        <iterate
              ifEmpty="false"
              operator="and">
           <or>
              <instanceof
                    value="com.sample.ExampleNGroup"> -> Where N=1,2,.. 
              </instanceof>
           </or>
        </iterate>
     </with>
  </definition>

当我在不同N之间多select时,扩展定义应该是什么。

   <definition
        id="com.sample.rightclickmenu.multiselect.id.expression">
     <with
           variable="org.eclipse.ui.selection">
        <iterate
              ifEmpty="false"
              operator="and">
           <or>
              <instanceof
                    value=??>  -> what needs to be the value here.
              </instanceof>
           </or>
        </iterate>
     </with>
  </definition>

希望我已经正确解释了问题。

您可以使用 count 元素来测试选择大小

选择的单项:

 <with variable="org.eclipse.ui.selection">
    <count value="1" />
    <iterate ifEmpty="false">
          ....
    </iterate>
 </with>

选择了两项或更多项

 <with variable="org.eclipse.ui.selection">
    <count value="(2-" />
    <iterate ifEmpty="false">
          ....
    </iterate>
 </with>