当选择 TableItem 时,带有 SWT.CHECK 的 Eclipse Table 小部件会触发两个事件
我正在制作一个 Eclipse (3.6.2) CDT (7.0.2) 插件,它使用我自己的向导页面(扩展 MBSCustomPage)。此向导页面显示一个表,其中填充了一些表项,可以通过单击它们来选中或取消选中这些表项(像往常一样)。 问题是,当选中(或取消选中)TableItem 复选框时,我总是收到两个事件!。在收到的第一个事件中,即使首先检查了 TableItem,我也有 (SelectedEvent)e.detail == SWT.CHECK,而在第二个事件中,(SelectedEvent)e.detail == 0!。所以我无法知道 TableItem 是否真的被检查过。 这是我的代码(某种程度上):
final Table table = new Table( composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK );
table.setHeaderVisible(true);
table.setLinesVisible(false);
(...)
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
CheckThatOnlyOneItemCanBeCheckedAtTime(e.item);
//If someone check on me, save the item data value in a "container"
if( e.detail == SWT.CHECK ) {
MBSCustomPageManager.addPageProperty(PAGE_ID, "SDK_Path", ((ISdk)((TableItem)e.item).getData()).getPath() );
} else { //Otherwise, unset the saved value
MBSCustomPageManager.addPageProperty(PAGE_ID, "SDK_Path", "" );
}
}
});
当我单击 TableItem 的复选框时,为什么 widgetSelected() 被调用两次? 我测试了即使 widgetSelected() 方法中没有代码,事件也会被触发。 我没有找到任何东西谷歌搜索或在 Eclipse Bugzilla 数据库中查找...对我来说真的很奇怪,但我不是一个经验丰富的 Eclipse 插件编码器(甚至不是 Java):)
谢谢!
I'm making an Eclipse (3.6.2) CDT (7.0.2) Plugin which uses my own wizard page (extending MBSCustomPage). This wizard page shows a Table filled with some TableItems that can be checked or unchecked by clicking on them (as usual). The problem is that I'm always receiving two events when a TableItem checkbox is cheked (or unchecked)!. In the first event received, I have a (SelectedEvent)e.detail == SWT.CHECK, even if the TableItem was checked first, and in the second event, the (SelectedEvent)e.detail == 0!. So I have no way to know if the TableItem is really checked or not.
This is my code (somewhat):
final Table table = new Table( composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK );
table.setHeaderVisible(true);
table.setLinesVisible(false);
(...)
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
CheckThatOnlyOneItemCanBeCheckedAtTime(e.item);
//If someone check on me, save the item data value in a "container"
if( e.detail == SWT.CHECK ) {
MBSCustomPageManager.addPageProperty(PAGE_ID, "SDK_Path", ((ISdk)((TableItem)e.item).getData()).getPath() );
} else { //Otherwise, unset the saved value
MBSCustomPageManager.addPageProperty(PAGE_ID, "SDK_Path", "" );
}
}
});
Why is widgetSelected() being called two times when I click on the checkbox of a TableItem?
I tested that the events are fired even if there is no code inside the widgetSelected() method.
I didn't find anything Googling around or looking in Eclipse Bugzilla database... really strange to me, but I'm not an experienced Eclipse plugin coder (not even Java) :)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)