Hi
What i would like to be able to do is cancel a tab selection based on a users input.
So user clicks a tab, a dialog pops up asking them to confirm they want to switch tabs.
but the vetoFocus method does not prevent the focus from changing …
What I did was
dockController.getFocusObserver().addVetoListener(new FocusVetoListener(){
public boolean vetoFocus(MouseFocusObserver controller,
DockTitle title) {
return false;
}
public boolean vetoFocus(MouseFocusObserver controller,
Dockable dockable) {
if (dockable==testDockable && getActiveSituation()==SITUATIONS.TEST) {
return true;
}
return false;
}
});
This worked to prevent the “setFrontDockable” from being called. But the input events where still being processed. What I ended up doing was the following
class MyDefaultMouseFocusObserver extends DefaultMouseFocusObserver {
public AWTEvent event = null;
public MyDefaultMouseFocusObserver(DockController controller,
ControllerSetupCollection setup) {
super(controller, setup);
}
@Override
protected void check(AWTEvent event) {
this.event=event;
super.check(event);
this.event=null;
}
}
dockController = new DockController(new DefaultDockControllerFactory() {
@Override
public MouseFocusObserver createMouseFocusObserver(DockController controller,
ControllerSetupCollection setup) {
return new MyDefaultMouseFocusObserver( controller, setup );
}
});
dockController.getFocusObserver().addVetoListener(new FocusVetoListener(){
public boolean vetoFocus(MouseFocusObserver controller,
DockTitle title) {
// TODO Auto-generated method stub
return false;
}
public boolean vetoFocus(MouseFocusObserver controller,
Dockable dockable) {
if (dockable==testDockable && getActiveSituation()==SITUATIONS.TEST) {
((MouseEvent)((MyDefaultMouseFocusObserver)controller).event).consume();
return true;
}
return false;
}
});
This allowed me to consume the event and prevent the tab from being switched. Can the MouseFocusObserver be changed so that the vetoFocus method can consume the event ? Or is there a better way to do this ?
Thanks
nz