监听到了CTabItem的关闭事件后,我如何不关闭它?

Kite:在CTabFolderEvent中,关闭tabitem的事件不是由item自己管理的,是由CTabFolder管理的,你必须在CTabFolder上添加CTabFolderListener,在 listener里检测你不想关闭的item,然后设置event.doit=false即可。如:
tabFolder = new CTabFolder(this,arg1);
    tabFolder.MIN_TAB_WIDTH = 100;
    
    tabFolder.addCTabFolderListener(new CTabFolderAdapter(){
      public void itemClosed(CTabFolderEvent event){
        CTabItem closingItem = (CTabItem)event.item;
        int index = tabFolder.indexOf(closingItem);
        BrowserTab tab = (BrowserTab)tabs.get(index);
        if(!tab.canClose())
          event.doit = false;
      }
    });


elliott:谢谢kite,搞定了..
.addCTabFolderListener()这个方法在3.0已经不赞成使用了.
用.addCTabFolder2Listener()这个了. 呵呵. 

tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
      public void close(CTabFolderEvent e) {
        if (e.item == tabItemMain) {
          e.doit = false;
        }
      }
    });

Cyper的代码:

public class SQLWindow extends CTabFolder {
    public SQLWindow(Composite parent, int style) {
        super(parent, style);
        this.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                SQLTab tab = (SQLTab) event.item;
                tab.setBusy(tab.isBusy());
            }
        });
        this.addCTabFolder2Listener(new CTabFolder2Adapter() {
            public void close(CTabFolderEvent event) {
                SQLTab tab = (SQLTab) event.item;
                if (tab.isBusy()) {
                    Logger.info("busy, cannot close");
                    event.doit = false;
                }
            }
          });
    }


你可能感兴趣的:(监听到了CTabItem的关闭事件后,我如何不关闭它?)