PDA

View Full Version : How to stop expanding accordion? I mean how to cancel expand event?



salmondavid888
23 Jan 2012, 6:57 AM
I am using ExtGwt. i have below code.

private ContentPanel mainPanel = new ContentPanel();
private ContentPanel firstAccordion = new ContentPanel();
private ContentPanel secondAccordion = new ContentPanel();
private ContentPanel thirdAccordion = new ContentPanel();
i have accordionlayout set. i have 3 accordions. all are added to mainPanel. when user is viewing secondAccordion, if user clicks on first accordion then first accordion should not be expanded. user should be retained in seconAccordion itself. so, my question is, i have certain condition when to retain the user in the same accordion where he is. if user clicks on any other accordions, then i should stop expandint the other accordion. how can i do that? Please help me.

Thanks!

WesleyMoy
30 Jan 2012, 11:06 AM
You can subclass AccordionPanel and override onBeforeExpand. You can tell which content panel is active by checking which one is expanded. You can tell which content panel the user has tried to select with ComponentEvent.getComponent.

If you don't call super.onBeforeExpand in turn, you will prevent changing which content panel is active.

Here's a quick example with an anonymous inner class subclassing AccordionLayout.



new AccordionLayout() {

@Override
protected void onBeforeExpand(ComponentEvent ce) {
if (ce.getComponent() != firstAccordion) {
super.onBeforeExpand(ce);
}
}

});

You can substitute the if-condition with any other logic you like, including checking for the currently active panel.