You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RCP Handler:enabledWhen能否配置多with元素并实现与逻辑?

RCP Handler enabledWhen 多条件配置方法

直接在同一个<enabledWhen>下放置多个<with>元素不符合Eclipse表达式规范,无法实现"两个条件都为true才启用"的需求。要达成这个逻辑,你需要用<and>元素将多个条件包裹起来,明确指定逻辑与的关系。

修改后的plugin.xml配置如下:

<handler
         class="com.myClass"
         commandId="com.myid">
         <enabledWhen>
           <and>
             <with variable="menu.enablement">
                     <equals
                           value="true">
                     </equals>
              </with>
              <with variable="menu.request.state">
                     <equals
                           value="true">
                     </equals>
              </with>
           </and>
         </enabledWhen>
</handler>

说明

  • <and>是Eclipse表达式框架提供的逻辑组合标签,只有当它包含的所有子表达式(此处为两个<with>条件)都返回true时,整个<enabledWhen>的判定结果才会是true。
  • 你还可以根据需求使用<or>(逻辑或)、<not>(逻辑非)等标签,组合出更复杂的启用条件。

内容的提问来源于stack exchange,提问作者Sangli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 12:27:49