如何以编程方式访问Eclipse变量池? [英] How to programatically access the Eclipse variable pool?

查看:75
本文介绍了如何以编程方式访问Eclipse变量池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 org.eclipse.ui.handlers 扩展点注册了一个处理程序,并添加了一个 enabledWhen 条件,该条件检查变量 selection 在Eclipse变量池中.效果很好,但是现在我想将此行为复制到视图中显示的SWT按钮上.

I have registered a handler through the org.eclipse.ui.handlers extension point and added an enabledWhen condition which checks the variable selection in the Eclipse variable pool. This works perfectly fine, but now I want to replicate this behavior to my SWT buttons which are displayed in a view.

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

My question is as follows: How can I access the Eclipse variable pool in order to get the selection variable to listen on selection events and subsequently call the button.setEnabled(true/false).

推荐答案

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

You use the selection service ISelectionService to listen for selection changes. In a view or editor you can get this using:

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

然后您可以使用

public void addSelectionListener(ISelectionListener listener);

聆听所有选择更改的方法,或者可以使用

method to listen to all selection changes or you can use

public void addSelectionListener(String partId, ISelectionListener listener);

收听特定部分的选择更改.

to listen to selection changes in a particular part.

这篇关于如何以编程方式访问Eclipse变量池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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