DataView<MenuItem> view = new DataView<MenuItem>("menuItems", items) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<MenuItem> item) {
MenuItem entry = item.getModelObject();
if (entry instanceof PageLinkMenuItem) {
// link to another Wicket page
PageLinkMenuItem pageLink = (PageLinkMenuItem) entry;
item.add(new LinkPanel("menuItem", null, null, pageLink.toString(), pageLink.getPageClass(),
pageLink.getPageParameters(), false).setRenderBodyOnly(true));
} else if (entry instanceof ExternalLinkMenuItem) {
// link to a specified href
ExternalLinkMenuItem extLink = (ExternalLinkMenuItem) entry;
item.add(new LinkPanel("menuItem", null, extLink.toString(), extLink.getHref(),
extLink.openInNewWindow()).setRenderBodyOnly(true));
} else if (entry instanceof MenuDivider) {
// divider
item.add(new Label("menuItem").setRenderBodyOnly(true));
WicketUtils.setCssClass(item, "divider");
} else {
ParameterMenuItem parameter = (ParameterMenuItem) entry;
// parameter link for the current page
String icon = null;
if (parameter.isSelected()) {
icon = "icon-ok";
} else {
icon = "icon-ok-white";
}
item.add(new LinkPanel("menuItem", icon, null, entry.toString(), menu.pageClass,
parameter.getPageParameters(), false).setRenderBodyOnly(true));
}
}
};
add(view);