【发布时间】:2013-04-24 02:26:15
【问题描述】:
我正在制作一个使用我自己的向导页面(扩展 MBSCustomPage)的 Eclipse (3.6.2) CDT (7.0.2) 插件。此向导页面显示了一个表格,其中包含一些可以通过单击它们来选中或取消选中的 TableItems(像往常一样)。 问题是当 TableItem 复选框被选中(或未选中)时,我总是收到两个事件!。在收到的第一个事件中,我有一个 (SelectedEvent)e.detail == SWT.CHECK,即使首先检查了 TableItem,在第二个事件中,(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):)
谢谢!
【问题讨论】:
标签: java events eclipse-plugin eclipse-cdt