开发者

Eclipse Table widget with SWT.CHECK is fireing two events when a TableItem is selected

开发者 https://www.devze.com 2023-04-13 09:48 出处:网络
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 b

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.setHeaderVi开发者_如何学JAVAsible(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!


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号