PDA

View Full Version : Accordion Layout does not work when it has other accordion layouts inside



paucarre
23 Jan 2012, 11:42 PM
Accordion Layout does not work when it has other accordion layouts inside. It is to say, if you want to create an accordion menu with embedded accordions to have a hierarchy, new widgets are no longer shown

The recursive code to generate the accordion is:


public static Widget createMenuFromMenuModel(MenuModel menuModel) {
ContentPanel panel = new ContentPanel();
panel.setBodyBorder(false);
panel.setPixelSize(200, 325);


Widget widget = getMenuWidgetFromMenuModel(menuModel, null);
panel.add(widget);


VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.setSpacing(10);
verticalPanel.add(panel);
return verticalPanel;


}


private static Widget getMenuWidgetFromMenuModel(MenuModel menuModel,
AccordionLayoutContainer accordionLayoutContainer) {
AccordionLayoutAppearance appearance = GWT
.<AccordionLayoutAppearance> create(AccordionLayoutAppearance.class);
ContentPanel contentPanel = new ContentPanel(appearance);
contentPanel.setAnimCollapse(false);
contentPanel.setHeadingText(menuModel.getTitle());
Widget widgetToReturn = contentPanel;
if (menuModel.getListOfMenuModels().size() > 0) {
accordionLayoutContainer = new AccordionLayoutContainer();
accordionLayoutContainer.setFill(true);
accordionLayoutContainer.add(contentPanel);
accordionLayoutContainer.setWidget(contentPanel);
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.setSpacing(10);
contentPanel.add(verticalPanel);
for (MenuModel currentMenuModel : menuModel.getListOfMenuModels()) {
Widget widget = getMenuWidgetFromMenuModel(currentMenuModel,
accordionLayoutContainer);
verticalPanel.add(widget);
}
} else {
if (menuModel.getListOfOptionModel().size() > 0) {
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.setSpacing(10);
contentPanel.add(verticalPanel);
accordionLayoutContainer.add(contentPanel);
for (OptionModel currentOptionModel : menuModel
.getListOfOptionModel()) {
TextButton textButton = new TextButton();
textButton.setTitle(currentOptionModel.getTitle());
verticalPanel.add(textButton);
}
}
}
return widgetToReturn;
}