views:

844

answers:

3

I'm trying to catch an event, when I switch the stacks of a StackLayoutPanel in GWT 2.0.
The biggest problem is that I don't know which event gets fired and there seems to be no documentation, I have added a ChangeHandler with addDomHandler() but that hasn't worked.
Unfortunately the StackLayoutPanel doesn't implement the getSelectedIndex()-function so I can't just use an ClickEvent and then check if the selected index has changed.

Is my only solution to use the StackPanel or is there a way to get this to work with the StackLayoutPanel?

+1  A: 

What I did, after some experiments: use a Label as the widget of the header with 100% width and then add a ClickEvent handler attached. Every time the ClickEvent arrives, it means the user clicked the header, so the panel will be visible... Not very nice, but it worked. I tried to wrap the header widget using a ClickWrapper (take a look to the StackLayoutPanel source code), but it didn't worked, I dont know exactly why...

danigb
Finally I had to subclass StackLayoutPanel in order to try to fix the remove bug ;) (http://code.google.com/p/google-web-toolkit/issues/detail?id=4174) ... If you subclass StackLayoutPanel, you can fire events using the ClickWrapper class...
danigb
+1  A: 

I did it this way

public class StackComponent extends StackLayoutPanel implements HasChangeHandlers {

public StackComponent(Unit unit) {
    super(unit);
}

@Override
public void showWidget(Widget widget) {
    super.showWidget(widget);
    fireEvent(new StackChangeEvent(widget));

}

@Override
public HandlerRegistration addChangeHandler(ChangeHandler handler) {
    return addDomHandler(handler, ChangeEvent.getType());
}

}

dev
A: 

I believe in GWT 2.0.3 StackLayoutPanel has method addSelectionHandler. Fired event is SelectionEvent and event.getSelectedItem() returns corresponding stack header id.