根据ViewPart中的选择启用/禁用工具栏命令,而不是透视 [英] Enabling/Disabling Toolbar-Command based on selection in ViewPart, not Perspective

查看:445
本文介绍了根据ViewPart中的选择启用/禁用工具栏命令,而不是透视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由多个 ViewPart 组成的透视图。其中一个 ViewPart s具有使用 menuContribution locationURI =工具栏分配的命令: ......



使用Toolbar-Command的 ViewPart 只包含一个Child(一个 TreeView ),并且 this.getSite()。setSelectionProvider(child)在它的 createPartControl(Composite) - 方法。

问题是,当我点击我的Perspective命令中的其他 ViewPart 之一时被禁用,但是选择在 TreeView -Component中是抵制的。
我猜,$ code>启用
- 条件无效,因为选择 -Variable现在指向东西在另一个ViewPart中抵抗。



这分散注意力,因为应该激活工具栏按钮,当 TreeView 被选中。



我如何告诉我的Core Expression,它只应该检查 ViewPart 工具栏阻止了全局选择?



解决方案

我有一个类似的问题,我最后做的是实现我自己的属性测试仪。这可能是最简单的方法,因为预定义的选择变量将始终指向全局选择。



您将需要按照以下步骤进行。


  1. 添加 org.eclipse.core.expressions 插件到您的依赖。


  2. 定义 org.eclipse.core.expressions.propertyTesters 扩展点。这将看起来像以下(文档链接):

     < extension 
    point = org.eclipse.core.expressions.propertyTesters>
    < propertyTester
    class =your.package.TreeItemSelectionPropertyTester
    id =your.package.treeItemSelectionPropertyTester
    namespace =your.namespace
    properties = itemSelected
    type =java.lang.Object>
    < / propertyTester>
    < / extension>


  3. 实现您的PropertyTester代码。如上述文档所述,类应该是公开的,并应该扩展 org.eclipse.core.expressions.PropertyTester class。



    public class CodeSelectionPropertyTester extends PropertyTester {
    @Override
    public boolean test(Object receiver,String property,
    Object [] args,Object expectedValue) {
    if(property.equals(itemSelected)){
    //编写自己的代码测试
    //是否有有效的选择...
    }

    // ...
    }
    }


  4. 在enabledWhen子句中使用实现的属性测试器。

     < enabledWhen> 
    < test
    property =your.namespace.itemSelected>
    < / test>
    < / enabledWhen>



I have a perspective consisting of multiple ViewParts. One of these ViewParts has a command assigned using a menuContribution with locationURI="toolbar:...".

The ViewPart with the Toolbar-Command only contains one Child (a TreeView) and does this.getSite().setSelectionProvider(child) in it's createPartControl(Composite)-Method.

The problem is, that when i click one of the other ViewParts in my Perspective the Command gets disabled, but the selection does resist in the TreeView-Component. I guess the enabledWhen-Condition is not valid anymore, because the selection-Variable now points to stuff that resists in another ViewPart.

This distracts, because the Toolbar-Button should be activated, when a valid row in the TreeView is selected.

How do i tell my Core Expression, that it only should check the selection of the ViewPart the Toolbar resists in and not the global-selection?

解决方案

I had a similar problem, and what I ended up doing was implementing my own property tester. This is probably the easiest way, because the predefined selection variable will always point to the global selection.

Roughly, you will need to follow the steps below.

  1. add org.eclipse.core.expressions plug-in to your dependency.

  2. define an extension for org.eclipse.core.expressions.propertyTesters extension point. This would look something like the following (documentation link):

    <extension
         point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
            class="your.package.TreeItemSelectionPropertyTester"
            id="your.package.treeItemSelectionPropertyTester"
            namespace="your.namespace"
            properties="itemSelected"
            type="java.lang.Object">
      </propertyTester>
    </extension>
    

  3. Implement your PropertyTester code. As the above documentation says, the class should be public and should extend org.eclipse.core.expressions.PropertyTester class.

    public class CodeSelectionPropertyTester extends PropertyTester {
        @Override
        public boolean test(Object receiver, String property,
                Object[] args, Object expectedValue) {
            if (property.equals("itemSelected")) {
                // write your own code to test
                // whether there is a valid selection...
            }
    
            // ...
        }
    }
    

  4. Use the implemented property tester in your enabledWhen clause.

     <enabledWhen>
        <test
              property="your.namespace.itemSelected">
        </test>
     </enabledWhen>
    

这篇关于根据ViewPart中的选择启用/禁用工具栏命令,而不是透视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆