// Empty the menu every time it receives new information
if (!getItems().isEmpty()) {
clearItems();
}
UIDL options = uidl.getChildUIDL(0);
// FIXME remove in version 7
if (options.hasAttribute("submenuIcon")) {
submenuIcon = client.translateVaadinUri(uidl.getChildUIDL(0)
.getStringAttribute("submenuIcon"));
} else {
submenuIcon = null;
}
if (uidl.hasAttribute("width")) {
UIDL moreItemUIDL = options.getChildUIDL(0);
StringBuffer itemHTML = new StringBuffer();
if (moreItemUIDL.hasAttribute("icon")) {
itemHTML.append("<img src=\""
+ client.translateVaadinUri(moreItemUIDL
.getStringAttribute("icon")) + "\" class=\""
+ Icon.CLASSNAME + "\" alt=\"\" />");
}
String moreItemText = moreItemUIDL.getStringAttribute("text");
if ("".equals(moreItemText)) {
moreItemText = "►";
}
itemHTML.append(moreItemText);
moreItem = GWT.create(CustomMenuItem.class);
moreItem.setHTML(itemHTML.toString());
moreItem.setCommand(emptyCommand);
collapsedRootItems = new VMenuBar(true,
(VMenuBar) client.getPaintable(uidlId));
moreItem.setSubMenu(collapsedRootItems);
moreItem.addStyleName(CLASSNAME + "-more-menuitem");
}
UIDL uidlItems = uidl.getChildUIDL(1);
Iterator<Object> itr = uidlItems.getChildIterator();
Stack<Iterator<Object>> iteratorStack = new Stack<Iterator<Object>>();
Stack<VMenuBar> menuStack = new Stack<VMenuBar>();
VMenuBar currentMenu = this;
while (itr.hasNext()) {
UIDL item = (UIDL) itr.next();
CustomMenuItem currentItem = null;
final int itemId = item.getIntAttribute("id");
boolean itemHasCommand = item.hasAttribute("command");
boolean itemIsCheckable = item.hasAttribute(ATTRIBUTE_CHECKED);
String itemHTML = buildItemHTML(item);
Command cmd = null;
if (!item.hasAttribute("separator")) {
if (itemHasCommand || itemIsCheckable) {
// Construct a command that fires onMenuClick(int) with the
// item's id-number
cmd = new Command() {
public void execute() {
hostReference.onMenuClick(itemId);
}
};
}
}
currentItem = currentMenu.addItem(itemHTML.toString(), cmd);
currentItem.updateFromUIDL(item, client);
if (item.getChildCount() > 0) {
menuStack.push(currentMenu);
iteratorStack.push(itr);
itr = item.getChildIterator();
currentMenu = new VMenuBar(true, currentMenu);
if (uidl.hasAttribute("style")) {
for (String style : uidl.getStringAttribute("style").split(
" ")) {
currentMenu.addStyleDependentName(style);