代码之家  ›  专栏  ›  技术社区  ›  John Doe

如何以编程方式访问Eclipse变量池?

  •  1
  • John Doe  · 技术社区  · 8 年前

    我已通过注册了处理程序 org.eclipse.ui.handlers 扩展点并添加了 enabledWhen 检查变量的条件 selection 在Eclipse变量池中。这工作得非常好,但现在我想将此行为复制到视图中显示的SWT按钮。

    我的问题如下:如何访问Eclipse变量池以获取 选择 变量侦听选择事件,然后调用 button.setEnabled(true/false) .

    1 回复  |  直到 8 年前
        1
  •  2
  •   greg-449    8 年前

    您使用选择服务 ISelectionService 以侦听选择更改。在视图或编辑器中,您可以使用以下方法获取此信息:

    ISelectionService selectionService = getSite().getService(ISelectionService.class);
    

    然后,您可以使用

    public void addSelectionListener(ISelectionListener listener);
    

    方法来侦听所有选择更改,或者您可以使用

    public void addSelectionListener(String partId, ISelectionListener listener);
    

    收听特定部分中的选择更改。