How to programatically access the Eclipse variable pool?

拟墨画扇 提交于 2021-01-29 03:12:24

问题


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.

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).


回答1:


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);

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.



来源:https://stackoverflow.com/questions/41585695/how-to-programatically-access-the-eclipse-variable-pool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!