On the first glance there is no easy way for running arbitrary piece of code once one of the CTabItem tab is changed. Lucky there is generic
addListener(int eventType, Listener listener)
delivered with Widget class.
CTabItem item = new CTabItem(tabFolder, SWT.NULL);
item.setText(tabTitle);
Composite container = createContent(item.getParent());
item.setControl(container);
item.addListener(SWT.SELECTED, new Listener() {
@Override
public void handleEvent(Event event) {
masterDetailsBlock.setDefaultSelection();
}
});
But by default there is no such an event notified by CTabFolder. That is why we need take care of it.
tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
tabFolder.getSelection().notifyListeners(SWT.SELECTED, new Event());
}
});
Thats all. Works like a charm ;)
Brak komentarzy:
Prześlij komentarz