PDA

View Full Version : Keep at least one panel in accordion layout expanded?



eburgerwa
6 Jan 2011, 5:16 PM
Hi,

I need to keep at least one panel in an accordion layout expanded. With the default AccordionLayout you can minimize all panels. The panel will always have one or more contentpanels.

For example, I have panel one expanded, and, as per AccordionLayout functionality, all other panels are collapsed. When the user clicks on the minimize icon of the expanded button, and I want another panel to open. The must always be one open panel.

I have tried listening the Events.Collapse event, and then check if one panel is expanded. If not, expand a (default) panel. It seems the collapsed field of the panel that fires the event is not set to true, which breaks the logic of this method.

The eventInfoArray is an array of contentanels contained within the AccordionLayout panel.


public void ensureOpenPanel()
{
boolean onePanelOpen = false;
int iiterator = 0;

// ensure at least one panel is open
while (!onePanelOpen && (iiterator < eventInfoArray.length))
{
if (eventInfoArray[iiterator].isCollapsed() == false)
{
onePanelOpen = true;
}

iiterator++;
} // end while

if (!onePanelOpen)
{
eventInfoArray[0].expand();
}
}


Any ideas?

sven
7 Jan 2011, 1:42 AM
You can for example listen to the BeforeCollapse event on the ContentPanel and cancel this, if the collapse was done by a user action and not by the AccordionLayout itself. You will need to extend AccordionLAyout for this.