当选择 TableItem 时,带有 SWT.CHECK 的 Eclipse Table 小部件会触发两个事件

发布于 2024-12-09 18:20:07 字数 1273 浏览 1 评论 0原文

我正在制作一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-12-16 18:20:07
table.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event arg0) {
    String string = arg0.detail == SWT.CHECK ? "Checked" : "Selected";
    if (arg0.detail == SWT.CHECK) {
      System.out.println(arg0.item + " " + string+ ":" + 
                         ((Table)arg0.widget).getSelection()[0].getChecked());
     }                         
     else {
       System.out.println(arg0.item + " " + string);
     }
   }
});
table.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event arg0) {
    String string = arg0.detail == SWT.CHECK ? "Checked" : "Selected";
    if (arg0.detail == SWT.CHECK) {
      System.out.println(arg0.item + " " + string+ ":" + 
                         ((Table)arg0.widget).getSelection()[0].getChecked());
     }                         
     else {
       System.out.println(arg0.item + " " + string);
     }
   }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文