[英]How to programatically access the Eclipse variable pool?
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. 我已经通过
org.eclipse.ui.handlers
扩展点注册了一个处理程序,并添加了enabledWhen
条件,该条件检查Eclipse变量池中的变量selection
。 This works perfectly fine, but now I want to replicate this behavior to my SWT buttons which are displayed in a view. 这工作得很好,但是现在我想将此行为复制到视图中显示的SWT按钮上。
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)
. 我的问题如下:我如何访问Eclipse变量池,以使
selection
变量侦听选择事件并随后调用button.setEnabled(true/false)
。
You use the selection service ISelectionService
to listen for selection changes. 您可以使用选择服务
ISelectionService
来侦听选择更改。 In a view or editor you can get this using: 在视图或编辑器中,可以使用:
ISelectionService selectionService = getSite().getService(ISelectionService.class);
You can then use the 然后,您可以使用
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. 聆听特定部分的选择更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.