miscMenu.addItem("Radios", radiosMenu);
// context menues
final MenuPopup contextMenu = new MenuPopup(true);
contextMenu.addItem("Item 1", new AlertCommand("'Item 1' was clicked"));
contextMenu.addItem("Item 2", new AlertCommand("'Item 2' was clicked"));
contextMenu.addItem("Item 3", new AlertCommand("'Item 3' was clicked"));
Menu subMenu = new Menu(true);
subMenu.addItem("Option 1", new AlertCommand("'Option 1' was clicked"));
subMenu.addItem("option2", "Option 2", new AlertCommand("'Option 2' was clicked"));
subMenu.addItem("Option 3", new AlertCommand("'Option 3' was clicked"));
contextMenu.addSubMenu("Options", subMenu);
BasicLabel label = new BasicLabel("Right-click Here");
label.addContextMenuHandler(new com.google.gwt.event.dom.client.ContextMenuHandler() {
public void onContextMenu(final ContextMenuEvent event) {
contextMenu.setPopupPositionAndShow(new Popup.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
int x = event.getNativeEvent().getClientX();
int y = event.getNativeEvent().getClientY();
contextMenu.setPopupPosition(x, y);
}
});
}
});
main.add(label);
label.setWidth("150px");
label.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
DOM.setStyleAttribute(label.getElement(), "cursor", "default");
DOM.setStyleAttribute(label.getElement(), "border", "1px solid gray");
DOM.setStyleAttribute(label.getElement(), "marginTop", "150px");
final CheckBox checkBox = new CheckBox("Disable Option 2");
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> event) {
MenuItemBase item = contextMenu.getMenu().getItem("Options.option2");
item.setEnabled(!event.getValue());
}
});
main.add(checkBox);