public SimpleMenuButtonSample() {
HorizontalPanel buttons = new HorizontalPanel();
SimpleMenuButton button = new SimpleMenuButton("Vertical Menu", true);
Menu menu = button.getMenu();
menu.addItem("Item 1", new Command() {
public void execute() {
showMessage("Item 1 was clicked");
}
});
menu.addItem("Item 2", new Command() {
public void execute() {
showMessage("Item 2 was clicked");
}
});
Menu subMenu = new Menu(true);
subMenu.addItem("Item 3", new Command() {
public void execute() {
showMessage("Item 3 was clicked");
}
});
menu.addItem("Sub Menu", subMenu);
buttons.add(button);
addGap(buttons, "20px");
button = new SimpleMenuButton("Horizontal Menu", false);
menu = button.getMenu();
menu.addItem("Item 1", new Command() {
public void execute() {
showMessage("Item 1 was clicked");
}
});
menu.addItem("Item 2", new Command() {
public void execute() {
showMessage("Item 2 was clicked");
}
});
subMenu = new Menu(true);
subMenu.addItem("Item 3", new Command() {
public void execute() {
showMessage("Item 3 was clicked");
}
});
menu.addItem("Sub Menu", subMenu);
buttons.add(button);
addGap(buttons, "20px");
SimpleButton sb = new SimpleButton(WidgetImages.Instance.get().icon_CubeBlue().createImage());
button = new SimpleMenuButton(sb, true);
menu = button.getMenu();
menu.addItem("Item 4", new Command() {
public void execute() {
showMessage("Item 1 was clicked");
}
});
menu.addItem("Item 5", new Command() {
public void execute() {
showMessage("Item 2 was clicked");
}
});
buttons.add(button);
addGap(buttons, "40px");
sb = new SimpleButton(WidgetImages.Instance.get().icon_CubeBlue().createImage());
final SimpleMenuButton smb = new SimpleMenuButton(sb, true);
buttons.add(smb);
addGap(buttons, "20px");
SimpleButton addItemBtn = new SimpleButton("Add Item", new ClickHandler() {
public void onClick(ClickEvent event) {
smb.getMenu().addItem("Item 4", new Command() {
public void execute() {
showMessage("Item 1 was clicked");
}
});
}
});
buttons.add(addItemBtn);
addGap(buttons, "20px");
SimpleButton removeItemBtn = new SimpleButton("Remove Items", new ClickHandler() {
public void onClick(ClickEvent event) {
smb.getMenu().clearItems();
}
});
buttons.add(removeItemBtn);