public class MenuSample extends Composite implements SamplePanel {
public MenuSample() {
FlowPanel main = new FlowPanel();
Menu menubar = new Menu();
menubar.setWidth("100%");
main.add(menubar);
Menu fileMenu = new Menu(true);
fileMenu.addItem("New", new AlertCommand("'New' was clicked")).setIconStyleName("menu-item-file-new");
fileMenu.addItem("Open...", new AlertCommand("'Open...' was clicked")).setIconStyleName("menu-item-file-open");
fileMenu.addSeparator();
fileMenu.addItem("Save...", new AlertCommand("'Save...' was clicked")).setIconStyleName("menu-item-file-save");
fileMenu.addItem("Save As...", new AlertCommand("'Save As...' was clicked")).setIconStyleName("menu-item-file-save");
fileMenu.addSeparator();
fileMenu.addItem("Exit", new AlertCommand("'Exit' was clicked")).setIconStyleName("menu-item-file-exit");
menubar.addItem("File", fileMenu);
Menu editMenu = new Menu(true);
editMenu.addItem("Undo", new AlertCommand("'Undo' was clicked")).setIconStyleName("menu-item-edit-undo");
editMenu.addItem("Redo", new AlertCommand("'Redo' was clicked")).setIconStyleName("menu-item-edit-redo");
editMenu.addSeparator();
editMenu.addItem("Cut", new AlertCommand("'Cut' was clicked")).setIconStyleName("menu-item-edit-cut");
editMenu.addItem("Copy", new AlertCommand("'Copy' was clicked")).setIconStyleName("menu-item-edit-copy");
editMenu.addItem("Paste", new AlertCommand("'Paste' was clicked")).setIconStyleName("menu-item-edit-paste");
menubar.addItem("Edit", editMenu);
Menu miscMenu = new Menu(true);
menubar.addItem("Misc", miscMenu);
final CheckMenuItem check2 = new CheckMenuItem("Option 2", true);
final CheckMenuItem check1 = new CheckMenuItem("Enable Option 2", true);
check1.setCommand(new Command() {
public void execute() {
check2.setEnabled(check1.isSelected());
}
});
miscMenu.addItem(check1);
check2.setCommand(new Command() {
public void execute() {
Window.alert("'Option 2' is " + (check2.isSelected() ? "checked" : "unchecked"));
}
});
miscMenu.addItem(check2);
miscMenu.addSeparator();
Menu secondary = new Menu(true);
secondary.addItem("Item 1", new AlertCommand("'Item 1' was clicked"));
secondary.addItem("Item 2", new AlertCommand("'Item 2' was clicked")).setEnabled(false);
secondary.addItem("Item 3", new AlertCommand("'Item 3' was clicked"));
miscMenu.addItem("Items", secondary);
miscMenu.addSeparator();
Menu radiosMenu = new Menu(true);
MenuItemSelectionListener listener = new MenuItemSelectionListener() {
public void selectionChanged(SelectionMenuItem item) {
Window.alert("'" + item.getKey() + "' was selected");
}
};
RadioMenuItem radio = new RadioMenuItem("1", "Option 1", false);
radio.addListener(listener);
radio.setGroup("options");
radiosMenu.addItem(radio);
radio = new RadioMenuItem("2", "Option 2", false);
radio.addListener(listener);
radio.setGroup("options");
radiosMenu.addItem(radio);
radio = new RadioMenuItem("3", "Option 3", false);
radio.addListener(listener);
radio.setGroup("options");
radiosMenu.addItem(radio);
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) {