RCP选型服务
我有两个视图:一个带有 TreeViewer
,另一个带有 SWT 小部件。我希望小部件视图中的活动能够导致 TreeViewer
视图发生变化。在阅读有关该主题的各种资源时,他们都谈论允许 JFace 查看器发出选择并接收通知,但他们没有谈论能够从文本小部件触发这些选择。
假设此代码所在的视图是一个 ISelectionProvider
,我可以做这样的事情吗?
Text someText = new Text( parent, SWT.BORDER ) ;
someText.addKeyListener( new KeyListener() {
@Override
public void keyPressed( KeyEvent e ) {}
@Override
public void keyReleased( KeyEvent e ) {
...
...
CellInfo cellInfo = new CellInfo( /*text collected while typing*/);
currentSelection = new StructuredSelection( cellInfo ) ;
setSelection( currentSelection ) ;
...
...
public void setSelection( ISelection selection ) {
Object[] list = getListeners() ;//listeners.getListeners();
for (int i = 0; i < list.length; i++) {
((ISelectionChangedListener) list[i])
.selectionChanged(new SelectionChangedEvent(this, selection));
}
}
这似乎在选择方面有效,但在我想要使用选择的另一方面,没有任何反应。在该查看器中,我实现了 ISelectionListener
接口,并在 createPartControl()
方法的开头执行以下操作:
getSite().getPage().addSelectionListener(this);
但是 selectionChanged()
方法从不被叫。
我的猜测是,我在生产者方面做错了,因为消费者方面似乎非常简单。有什么指点吗?
谢谢!
乔恩
I have two views: one with a TreeViewer
and another that has SWT widgets. I want activities in the view with the widgets to cause changes in the view with the TreeViewer
. In reading the various resources on the subject, they all talk about allowing JFace viewers to issue selections and receive notifications but they don't talk about being able to trigger these selections from a Text widget, for example.
Can I do something like this, assuming the view in which this code is, is an ISelectionProvider
?
Text someText = new Text( parent, SWT.BORDER ) ;
someText.addKeyListener( new KeyListener() {
@Override
public void keyPressed( KeyEvent e ) {}
@Override
public void keyReleased( KeyEvent e ) {
...
...
CellInfo cellInfo = new CellInfo( /*text collected while typing*/);
currentSelection = new StructuredSelection( cellInfo ) ;
setSelection( currentSelection ) ;
...
...
public void setSelection( ISelection selection ) {
Object[] list = getListeners() ;//listeners.getListeners();
for (int i = 0; i < list.length; i++) {
((ISelectionChangedListener) list[i])
.selectionChanged(new SelectionChangedEvent(this, selection));
}
}
This seems to work on the selection side, but the on the other side where I want to consume the selection, nothing happens. In that viewer I implement the ISelectionListener
interface and do the following in the beginning of the createPartControl()
method:
getSite().getPage().addSelectionListener(this);
But the selectionChanged()
method never gets called.
My guess is that I am doing something wrong on the producer side since the consumer side seems pretty straightforward. Any pointers?
Thanks!
Jon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否向工作台告知了您选择的提供商?在生产者方面,在 createPartControl() 中您需要:
Have you told the Workbench about your selection provider? On the producer side, in your createPartControl() you need:
由于整个 SWT 中应用的设计决策,通常不会发送事件对程序更改的响应(而不是用户操作)。然而,您可以做类似的事情:
但是要注意这种方法会导致一个搬起石头砸自己脚的好机会(根据我自己的经验)。
Due to a design decision that is applied throughout SWT, events are usually not sent in response to programmatic changes (as opposed to user actions). However, you could do something like:
But be aware that this method causes a good occasion to shoot yourself in the foot (from my own experience).