Example usage for com.google.gwt.user.client.ui MenuBar addItem

List of usage examples for com.google.gwt.user.client.ui MenuBar addItem

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui MenuBar addItem.

Prototype

public MenuItem addItem(String text, MenuBar popup) 

Source Link

Document

Adds a menu item to the bar, that will open the specified menu when it is selected.

Usage

From source file:com.webgocommerce.client.view.uimenubar.UIMenuBarImpl.java

public void createMenu(MenuBar menu, MenuBarProxy beanPadre, List<MenuBarProxy> lista) {
    int cont = 0;
    for (int j = 0; j < lista.size(); j++) {
        MenuBarProxy beanHijo = lista.get(j);
        if (beanPadre.getIdMenuBar() == beanHijo.getIdMenuPadre()
                && beanHijo.getEstado().equalsIgnoreCase("A")) {
            if (beanHijo.getTipo().equalsIgnoreCase("MenuBar")) {
                MenuBar menuBar = new MenuBar(true);
                menuBar.ensureDebugId(beanHijo.getVariable());
                menu.addItem(beanHijo.getDescripcion(), menuBar);
                createMenu(menuBar, beanHijo, lista);
                cont = cont + 1;//from   w  ww .  j a va  2 s . c  o m
            } else if (beanHijo.getTipo().equalsIgnoreCase("MenuItem")) {
                MenuItem menuItem = new MenuItem(beanHijo.getDescripcion(),
                        UIMenuBar.comandos.get(beanHijo.getComando()));
                menu.addItem(menuItem);
            }
        }
        if (cont == beanPadre.getNumSubMenu()) {
            break;
        }
    }

}

From source file:edu.stanford.bmir.protege.web.client.xd.visualization.VOWLControlPortlet.java

License:Open Source License

private void createMenuItems() {
    controlBar.moveSelectionDown();/*from w w w .  j a v  a2s  .c o  m*/

    MenuBar exportMenu = new MenuBar(true);
    controlBar.addItem("Export", exportMenu);
    controlBar.addSeparator();

    MenuBar gravityMenu = new MenuBar(true);
    controlBar.addItem("Gravity", gravityMenu);
    controlBar.addSeparator();

    MenuBar filterMenu = new MenuBar(true);
    controlBar.addItem("Filter", filterMenu);
    controlBar.addSeparator();

    MenuBar modesMenu = new MenuBar(true);
    controlBar.addItem("Modes", modesMenu);
    controlBar.addSeparator();

    //MenuBar resetMenu = new MenuBar(true);
    controlBar.addItem("Reset", new Command() {
        public void execute() {
            selection = Arrays.asList("reset");
            notifySelectionListeners(new SelectionEvent(VOWLControlPortlet.this));
        }
    });
    controlBar.addSeparator();

    //MenuBar pauseMenu = new MenuBar(true);
    controlBar.addItem("Pause", new Command() {
        public void execute() {
            selection = Arrays.asList(new String[] { "pause", String.valueOf(paused ? "false" : "true") });
            notifySelectionListeners(new SelectionEvent(VOWLControlPortlet.this));

            if (paused)
                paused = false;
            else
                paused = true;

        }
    });
    controlBar.addSeparator();

    MenuBar aboutMenu = new MenuBar(true);
    controlBar.addItem("About", aboutMenu);

    exportMenu.addItem("Export as SVG", new Command() {
        public void execute() {
            ;
        }
    });
    exportMenu.addItem("Export as JSON", new Command() {
        public void execute() {
            ;
        }
    });
    controlBar.addSeparator();

    TextBox tb = new TextBox();
    tb.setName("classDistance");
    tb.setValue("200");
    tb.setTitle("Class Distance");
    classDistance = new ExtendedMenuItem(new Command() {

        public void execute() {
            addSelectedComponent(classDistance);
        }
    }, tb);

    gravityMenu.addItem(classDistance);

    TextBox tb2 = new TextBox();
    tb2.setName("datatypeDistance");
    tb2.setValue("120");
    tb2.setTitle("Datatype Distance");
    datatypeDistance = new ExtendedMenuItem(new Command() {

        public void execute() {
            addSelectedComponent(datatypeDistance);
        }
    }, tb2);
    gravityMenu.addItem(datatypeDistance);

    controlBar.addSeparator();

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (dataProp.isEnabled())
                dataProp.setEnabled(false);
            else
                dataProp.setEnabled(true);
        }
    };

    dataProp = new ExtendedMenuItem("<input type=\"checkbox\" name=\"dataProp\" value=\"0\"> Datatype prop.",
            true, cmd);
    filterMenu.addItem(dataProp);

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (solSub.isEnabled())
                solSub.setEnabled(false);
            else
                solSub.setEnabled(true);
        }
    };

    solSub = new ExtendedMenuItem("<input type=\"checkbox\" name=\"solSub\" value=\"0\"> Solitary subclass",
            true, cmd);
    filterMenu.addItem(solSub);

    /*
    filterMenu.addItem("Solitary subclass", new Command() {
       public void execute() {
    ;
       }
    });
     */

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (disjInfo.isEnabled())
                disjInfo.setEnabled(false);
            else
                disjInfo.setEnabled(true);
        }
    };

    disjInfo = new ExtendedMenuItem(
            "<input type=\"checkbox\" name=\"disjInfo\" value=\"1\" checked> Disjointness info", true, cmd);
    filterMenu.addItem(disjInfo);

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (setOp.isEnabled())
                setOp.setEnabled(false);
            else
                setOp.setEnabled(true);
        }
    };

    setOp = new ExtendedMenuItem("<input type=\"checkbox\" name=\"setOp\" value=\"0\"> Set operators", true,
            cmd);
    filterMenu.addItem(setOp);

    TextBox tb3 = new TextBox();
    tb3.setName("collapseDegree");
    tb3.setValue("0");
    tb3.setTitle("Degree of collapsing");
    collapseDegree = new ExtendedMenuItem(new Command() {

        public void execute() {
            addSelectedComponent(collapseDegree);
        }
    }, tb3);
    filterMenu.addItem(collapseDegree);

    controlBar.addSeparator();

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);

            if (pickPin.isEnabled())
                pickPin.setEnabled(false);
            else
                pickPin.setEnabled(true);

            selection = Arrays.asList("pickPin");
            notifySelectionListeners(new SelectionEvent(VOWLControlPortlet.this));
        }
    };

    pickPin = new ExtendedMenuItem("<input type=\"checkbox\" name=\"pickPin\" value=\"0\"> Pick & Pin", true,
            cmd);
    modesMenu.addItem(pickPin);

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (nodeScale.isEnabled())
                nodeScale.setEnabled(false);
            else
                nodeScale.setEnabled(true);
        }
    };

    nodeScale = new ExtendedMenuItem(
            "<input type=\"checkbox\" name=\"nodeScale\" value=\"1\" checked> Node Scaling", true, cmd);
    modesMenu.addItem(nodeScale);

    cmd = new Command() {
        public void execute() {
            //addSelectedComponent(dataProp);
            if (compNotation.isEnabled())
                compNotation.setEnabled(false);
            else
                compNotation.setEnabled(true);
        }
    };

    compNotation = new ExtendedMenuItem(
            "<input type=\"checkbox\" name=\"compNotation\" value=\"0\"> Compact Notation", true, cmd);
    modesMenu.addItem(compNotation);

    controlBar.addSeparator();
    aboutMenu.addItem(
            "<a target=\"_blank\" href=\"http://vowl.visualdataweb.org/webvowl/license.txt\">MIT License  2014/15</a>",
            true, new Command() {
                public void execute() {
                    ;
                }
            });
    aboutMenu.addItem("WebVOWL Developers:\r\n" + "Vincent Link, Steffen Lohmann, Eduard Marbach, Stefan Negru",
            new Command() {
                public void execute() {
                    ;
                }
            });
    aboutMenu.addSeparator();
    aboutMenu.addItem(
            "<a target=\"_blank\" href=\"http://vowl.visualdataweb.org/webvowl.html#releases\">\r\n"
                    + "Version: beta 0.4.0\r\n" + "<br>\r\n" + "(release history)\r\n" + "</a>",
            true, new Command() {
                public void execute() {
                    ;
                }
            });
    aboutMenu.addSeparator();
    aboutMenu.addItem("<a target=\"_blank\" href=\"http://purl.org/vowl/\">VOWL Specification </a>\r\n", true,
            new Command() {
                public void execute() {
                    ;
                }
            });
}

From source file:edu.umb.jsPedigrees.client.Pelican.Pelican.java

License:Open Source License

private void makeMenus(RootPanel rootPanel) {
    // set up the popup menu that appears when you click on a person
    popup = new PopupPanel();

    MenuBar personMenu = new MenuBar(true);

    MenuBar addMenu = new MenuBar(true);
    addMenu.addItem("1 son", new Command() {
        public void execute() {
            addChildren("1 son");
            popup.hide();// w w w  .  j  a v a2s  . c o  m
        }
    });
    addMenu.addItem("1 daughter", new Command() {
        public void execute() {
            addChildren("1 daughter");
            popup.hide();
        }
    });
    addMenu.addItem("2 sons", new Command() {
        public void execute() {
            addChildren("2 sons");
            popup.hide();
        }
    });
    addMenu.addItem("2 daughters", new Command() {
        public void execute() {
            addChildren("2 daughters");
            popup.hide();
        }
    });
    addMenu.addItem("3 sons", new Command() {
        public void execute() {
            addChildren("3 sons");
            popup.hide();
        }
    });
    addMenu.addItem("3 daughters", new Command() {
        public void execute() {
            addChildren("3 daughters");
            popup.hide();
        }
    });
    addMenu.addItem("Spouse+son", new Command() {
        public void execute() {
            addSpouse("Spouse+son");
            popup.hide();
        }
    });
    addMenu.addItem("Spouse+daughter", new Command() {
        public void execute() {
            addSpouse("Spouse+daughter");
            popup.hide();
        }
    });
    Parents = new MenuItem("Parents", new Command() {
        public void execute() {
            addParents();
            popup.hide();
        }
    });
    addMenu.addItem(Parents);
    personMenu.addItem("Add", addMenu);

    MenuBar changeMenu = new MenuBar(true);

    MenuBar changeAff = new MenuBar(true);
    changeAff.addItem("Affected", new Command() {
        public void execute() {
            currentPerson.affection = PelicanPerson.affected;
            updateDisplay();
            popup.hide();
        }
    });
    changeAff.addItem("Unaffected", new Command() {
        public void execute() {
            currentPerson.affection = PelicanPerson.unaffected;
            updateDisplay();
            popup.hide();
        }
    });
    changeMenu.addItem("Affection", changeAff);

    MenuBar changeSex = new MenuBar(true);
    changeSex.addItem("Male", new Command() {
        public void execute() {
            currentPerson.sex = PelicanPerson.male;
            updateDisplay();
            popup.hide();
        }
    });
    changeSex.addItem("Female", new Command() {
        public void execute() {
            currentPerson.sex = PelicanPerson.female;
            updateDisplay();
            popup.hide();
        }
    });
    changeMenu.addItem("Sex", changeSex);

    personMenu.addItem("Change", changeMenu);

    personMenu.addItem("Delete", new Command() {
        public void execute() {
            deletePerson(currentPerson);
            popup.hide();
        }
    });

    personMenu.addItem("Cancel", new Command() {
        public void execute() {
            popup.hide();
        }
    });

    MenuBar popupMenu = new MenuBar();
    popupMenu.addItem("Edit", personMenu);
    popupMenu.setAutoOpen(true);
    popup.add(popupMenu);

    // main menu
    MenuBar mainMenu = new MenuBar();
    mainMenu.setWidth("50px");
    mainMenu.setAnimationEnabled(true);

    MenuBar editMenu = new MenuBar(true);
    editMenu.setAnimationEnabled(true);

    editMenu.addItem("New Pedigree", new Command() {
        public void execute() {
            newPedigree();
            updateDisplay();
        }
    });
    undoItem = new MenuItem("Undo", new Command() {
        public void execute() {
            if (historyPosition > 1) {
                historyPosition--;
                Vector<PelicanPerson> savedPed = (Vector<PelicanPerson>) history.elementAt(historyPosition - 1);
                loadPedigree(savedPed);
                pedHasChanged = true;
                updateDisplay();
            }
        }
    });
    editMenu.addItem(undoItem);
    redoItem = new MenuItem("Redo", new Command() {
        public void execute() {
            if (historyPosition < history.size()) {
                historyPosition++;
                Vector<PelicanPerson> savedPed = (Vector<PelicanPerson>) history.elementAt(historyPosition - 1);
                loadPedigree(savedPed);
                pedHasChanged = true;
                updateDisplay();
            }
        }
    });
    editMenu.addItem(redoItem);
    editMenu.addItem("Renumber", new Command() {
        public void execute() {
            renumberAll();
            updateDisplay();
        }
    });
    mainMenu.addItem(new MenuItem("Edit", editMenu));

    rootPanel.add(mainMenu);

}

From source file:eu.riscoss.client.RiscossWebApp.java

License:Apache License

void showUI(JSiteMap sitemap) {

    Log.println("Loading UI for domain " + sitemap.domain);

    VerticalPanel vPanel = new VerticalPanel();

    MenuBar menu = new MenuBar();
    menu.setWidth(" 100% ");
    menu.setAnimationEnabled(true);/*from www .j a  v a2s  .  c o m*/
    menu.setStyleName("mainMenu");

    MenuBar account = new MenuBar(true);
    account.setStyleName("subMenu");
    account.setAnimationEnabled(true);
    menu.addItem(username + " (" + sitemap.domain + ")", account);
    account.addItem("Change domain", new Command() {
        @Override
        public void execute() {
            showDomainSelectionDialog();
        }
    });
    account.addItem("Logout", new Command() {
        @Override
        public void execute() {
            Cookies.removeCookie(CookieNames.TOKEN_KEY);
            Cookies.removeCookie(CookieNames.DOMAIN_KEY);
            Window.Location.reload();
        }
    });

    for (JSiteSection subsection : sitemap.getRoot().subsections()) {
        if (subsection.pages().size() < 1)
            continue;
        if (subsection.getLabel().equals("untracked"))
            continue;
        MenuBar submenu = new MenuBar(true);
        submenu.setStyleName("subMenu");
        submenu.setAnimationEnabled(true);
        menu.addItem(subsection.getLabel(), submenu);
        for (JSitePage page : subsection.pages()) {
            access.add(page.getLabel());
            submenu.addItem(page.getLabel(), new MenuCommand(page.getUrl()) {
                @Override
                public void execute() {
                    loadPanel(getUrl());
                }
            });
        }

        if (subsection.getLabel().equals("Configure")) {
            final Button b = new Button("ye");
            final SingleUploader upload = new SingleUploader(FileInputType.CUSTOM.with(b));
            upload.setTitle("Upload new entities document");
            upload.setAutoSubmit(true);
            upload.setServletPath(upload.getServletPath() + "?t=importentities&domain="
                    + RiscossJsonClient.getDomain() + "&token=" + RiscossCall.getToken());
            upload.addOnFinishUploadHandler(new OnFinishUploaderHandler() {
                @Override
                public void onFinish(IUploader uploader) {
                    Log.println("OnFinish");
                    UploadedInfo info = uploader.getServerInfo();
                    String name = info.name;
                    String response = uploader.getServerMessage().getMessage();
                    if (confFileLoaded) {
                        RiscossJsonClient.importEntities(new JsonCallback() {
                            @Override
                            public void onFailure(Method method, Throwable exception) {
                                Window.alert(exception.getMessage());
                            }

                            @Override
                            public void onSuccess(Method method, JSONValue response) {
                                Window.alert("Entity information imported correctly");
                                loadPanel("entities.jsp");
                            }
                        });
                    } else {
                        Window.alert("Missing config xml file. Please, contact an administrator");
                    }
                }
            });
            submenu.addSeparator();
            submenu.addItem("Import entities", new MenuCommand("Import entities") {
                @Override
                public void execute() {
                    upload.fireEvent(new ClickEvent() {
                    });
                    b.fireEvent(new ClickEvent() {
                    });
                }
            });
            vPanel.add(upload);
            upload.setVisible(false);
        }
    }

    MenuBar helpUs = new MenuBar(true);
    helpUs.setStyleName("subMenu");
    helpUs.setAnimationEnabled(true);
    menu.addItem("Help us", helpUs);
    helpUs.addItem("User feedback", new Command() {
        @Override
        public void execute() {
            Window.open("http://www.essi.upc.edu/~e-survey/index.php?sid=356784&lang=en", "_self", "");
        }
    });
    helpUs.addItem("Expert feedback", new Command() {
        @Override
        public void execute() {
            Window.open("http://www.essi.upc.edu/~e-survey/index.php?sid=91563&lang=en", "_self", "");
        }
    });

    HorizontalPanel hPanel = new HorizontalPanel();

    VerticalPanel north = new VerticalPanel();
    //      Image logo = new Image( "http://riscossplatform.ow2.org/riscoss/wiki/wiki1/download/ColorThemes/RISCOSS_2/logo_riscoss_DSP.png" );
    Image logo = new Image("resources/logo_riscoss_DSP.png");
    logo.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent arg0) {
            loadPanel("dashboard.jsp");
        }
    });
    logo.setStyleName("logo");
    north.add(logo);
    north.setHeight("5%"); // any value here seems to resolve the firefox problem of showing only a small frame on the right side
    Label version = new Label("v1.6.0");
    version.setStyleName("version");
    north.add(version);
    //north.setWidth("100%");
    hPanel.add(north);

    //Comment this line if you don't need shortcuts
    generateShortcuts();

    hPanel.add(shortcuts);
    hPanel.setWidth("100%");
    vPanel.add(hPanel);
    vPanel.add(menu);
    vPanel.setWidth("100%");

    RootPanel.get().add(vPanel);
    RootPanel.get().setStyleName("root");
    loadPanel("dashboard.jsp");

}

From source file:gov.nist.spectrumbrowser.client.SensorDataStream.java

License:Open Source License

private void drawMenuItems() {
    MenuBar menuBar = new MenuBar();
    SafeHtmlBuilder safeHtml = new SafeHtmlBuilder();

    menuBar.addItem(new SafeHtmlBuilder().appendEscaped(SpectrumBrowserShowDatasets.END_LABEL).toSafeHtml(),
            new Scheduler.ScheduledCommand() {

                @Override/*from  ww  w.  j a v  a 2s . c o m*/
                public void execute() {
                    state = STATUS_MESSAGE_NOT_SEEN;
                    closingState = true;
                    websocket.close();
                    spectrumBrowserShowDatasets.draw();
                }
            });
    if (spectrumBrowser.isUserLoggedIn()) {
        menuBar.addItem(safeHtml.appendEscaped(SpectrumBrowser.LOGOFF_LABEL).toSafeHtml(),
                new Scheduler.ScheduledCommand() {

                    @Override
                    public void execute() {
                        state = STATUS_MESSAGE_NOT_SEEN;
                        closingState = true;
                        websocket.close();
                        spectrumBrowser.logoff();

                    }
                });
    }

    verticalPanel.add(menuBar);

    titlePanel = new VerticalPanel();

    verticalPanel.add(titlePanel);

    HorizontalPanel cutoffHorizontalPanel = new HorizontalPanel();

    Label cutoffLabel = new Label("Threshold (dBm):");

    cutoffHorizontalPanel.add(cutoffLabel);

    cutoffTextBox = new TextBox();

    cutoffTextBox.setText(Integer.toString((int) cutoff));

    cutoffHorizontalPanel.add(cutoffTextBox);

    Button cutoffButton = new Button("Change");

    cutoffHorizontalPanel.add(cutoffButton);

    cutoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            String cutoffString = cutoffTextBox.getValue();
            try {
                cutoff = Integer.parseInt(cutoffString);
            } catch (NumberFormatException nfe) {
                Window.alert("Please enter an integer");
                if (cutoff < 0)
                    cutoffTextBox.setText(Integer.toString((int) (cutoff - 0.5)));
                else
                    cutoffTextBox.setText(Integer.toString((int) (cutoff + 0.5)));
            }

        }
    });

    freezeButton = new Button("Freeze");

    freezeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            isFrozen = !isFrozen;
            if (isFrozen) {
                freezeButton.setText("Unfreeze");
            } else {
                freezeButton.setText("Freeze");
            }
        }
    });
    cutoffHorizontalPanel.add(freezeButton);

    lastCaptureButton = new Button("Show Last Acquistion");

    cutoffHorizontalPanel.add(lastCaptureButton);

    lastCaptureButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            websocket.close();
            spectrumBrowser.getSpectrumBrowserService().getLastAcquisitionTime(sensorId,
                    new SpectrumBrowserCallback<String>() {

                        @Override
                        public void onSuccess(String result) {
                            JSONValue jsonValue = JSONParser.parseLenient(result);
                            final long selectionTime = (long) jsonValue.isObject().get("aquisitionTimeStamp")
                                    .isNumber().doubleValue();
                            if (selectionTime != -1) {
                                chartApiLoaded = false;
                                occupancyDataTable = null;
                                websocket.close();
                                state = STATUS_MESSAGE_NOT_SEEN;
                                isFrozen = false;
                                Timer timer = new Timer() {
                                    @Override
                                    public void run() {

                                        ArrayList<SpectrumBrowserScreen> navigation = new ArrayList<SpectrumBrowserScreen>();
                                        navigation.add(spectrumBrowserShowDatasets);
                                        navigation.add(SensorDataStream.this);
                                        new FftPowerOneAcquisitionSpectrogramChart(sensorId, selectionTime,
                                                sys2detect, minFreqHz, maxFreqHz, verticalPanel,
                                                spectrumBrowser, navigation);
                                    }
                                };
                                // Wait for websocket to close.
                                timer.schedule(500);
                            } else {
                                Window.alert("No Capture Found");
                            }
                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            logger.log(Level.SEVERE, "Problem contacting web server.");
                            Window.alert("Problem contacting web server");
                        }
                    });
        }
    });

    verticalPanel.add(cutoffHorizontalPanel);

}

From source file:gov.nist.spectrumbrowser.common.AbstractSpectrumBrowserScreen.java

License:Open Source License

public void drawNavigation() {

    if (navigationScreens != null) {
        MenuBar menuBar = new MenuBar();
        verticalPanel.add(menuBar);/* w  ww  .j  ava  2s. c  om*/
        for (int i = 0; i < navigationScreens.size() - 1; i++) {
            final SpectrumBrowserScreen thisScreen = navigationScreens.get(i);
            menuBar.addItem(
                    new SafeHtmlBuilder().appendEscaped(navigationScreens.get(i).getLabel()).toSafeHtml(),
                    new Scheduler.ScheduledCommand() {

                        @Override
                        public void execute() {
                            thisScreen.draw();
                        }
                    });
        }

        menuBar.addItem(new SafeHtmlBuilder()
                .appendEscaped(navigationScreens.get(navigationScreens.size() - 1).getEndLabel()).toSafeHtml(),
                new Scheduler.ScheduledCommand() {

                    @Override
                    public void execute() {
                        navigationScreens.get(navigationScreens.size() - 1).draw();
                    }
                });

        if (abstractSpectrumBrowser.isUserLoggedIn()) {
            menuBar.addItem(new SafeHtmlBuilder().appendEscaped("Log Off").toSafeHtml(),
                    new Scheduler.ScheduledCommand() {
                        @Override
                        public void execute() {
                            abstractSpectrumBrowser.logoff();
                        }
                    });

        }

    }

}

From source file:gwtquery.plugins.draggable.client.GWTIntegrationSample.java

License:Apache License

/**
 * Create a menu bar. The code comes from the GWT show case :
 * http://gwt.google.com/samples/Showcase/Showcase.html#!CwMenuBar
 *
 * @return/* w ww  . j a v a2  s  .  co m*/
 */
private MenuBar createMenuBar() {
    // Create a command that will execute on menu item selection
    Command menuCommand = new Command() {
        private int curPhrase = 0;
        private final String[] phrases = new String[] { "Thank you for selecting a menu item",
                "A fine selection indeed", "Don't you have anything better to do than select menu items?",
                "Try something else", "this is just a menu!", "Another wasted click" };

        public void execute() {
            Window.alert(phrases[curPhrase]);
            curPhrase = (curPhrase + 1) % phrases.length;
        }
    };

    // Create a menu bar
    MenuBar menu = new MenuBar();
    menu.setAutoOpen(false);
    menu.setWidth("500px");
    menu.setAnimationEnabled(true);

    // Create a sub menu of recent documents
    MenuBar recentDocsMenu = new MenuBar(true);
    String[] recentDocs = new String[] { "Fishing in the desert.txt", "How to tame a wild parrot",
            "Idiots Guide to Emu Farms" };
    for (int i = 0; i < recentDocs.length; i++) {
        recentDocsMenu.addItem(recentDocs[i], menuCommand);
    }

    // Create the file menu
    MenuBar fileMenu = new MenuBar(true);
    fileMenu.setAnimationEnabled(true);
    menu.addItem(new MenuItem("File", fileMenu));
    String[] fileOptions = new String[] { "New", "Open", "Close", "Recents", "Exit" };

    for (int i = 0; i < fileOptions.length; i++) {
        if (i == 3) {
            fileMenu.addSeparator();
            fileMenu.addItem(fileOptions[i], recentDocsMenu);
            fileMenu.addSeparator();
        } else {
            fileMenu.addItem(fileOptions[i], menuCommand);
        }
    }

    // Create the edit menu
    MenuBar editMenu = new MenuBar(true);
    menu.addItem(new MenuItem("Edit", editMenu));
    String[] editOptions = new String[] { "Undo", "Redo", "Copy", "Cut", "Paste" };

    for (int i = 0; i < editOptions.length; i++) {
        editMenu.addItem(editOptions[i], menuCommand);
    }

    // Create the GWT menu
    MenuBar gwtMenu = new MenuBar(true);
    menu.addItem(new MenuItem("GWT", true, gwtMenu));
    String[] gwtOptions = new String[] { "Download", "Examples", "Source code", "GWT wit' the program" };

    for (int i = 0; i < gwtOptions.length; i++) {
        gwtMenu.addItem(gwtOptions[i], menuCommand);
    }

    // Create the help menu
    MenuBar helpMenu = new MenuBar(true);
    menu.addSeparator();
    menu.addItem(new MenuItem("Help", helpMenu));
    String[] helpOptions = new String[] { "Contents", "Fortune cookies", "About GWT" };

    for (int i = 0; i < helpOptions.length; i++) {
        helpMenu.addItem(helpOptions[i], menuCommand);
    }

    // Return the menu
    menu.ensureDebugId("cwMenuBar");
    return menu;

}

From source file:net.dancioi.jcsphotogallery.client.view.desktop.TopPanel.java

License:Open Source License

private void initialize() {
    setSize("800px", "25px");

    selectedTags = new ArrayList<Integer>();
    galleryTags = new MenuBar(true);
    MenuBar tagsMenu = new MenuBar();
    tagsMenu.setStyleName("topAlbumsTags");
    tagsMenu.addItem("Sort Albums by tag", galleryTags);
    add(tagsMenu, 650, 1);//from  ww w  .j a  v a 2 s . c o m
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.lists.CwMenuBar.java

License:Apache License

/**
 * Initialize this example.//  ww  w  . ja  va 2s  .c  o m
 */
@Override
public Widget onInitialize() {
    // Create a command that will execute on menu item selection
    Command menuCommand = new Command() {
        private int curPhrase = 0;
        private final String[] phrases = constants.cwMenuBarPrompts();

        public void execute() {
            Window.alert(phrases[curPhrase]);
            curPhrase = (curPhrase + 1) % phrases.length;
        }
    };

    // Create a menu bar
    MenuBar menu = new MenuBar();
    menu.setAutoOpen(true);
    menu.setWidth("500px");
    menu.setAnimationEnabled(true);

    // Create a sub menu of recent documents
    MenuBar recentDocsMenu = new MenuBar(true);
    String[] recentDocs = constants.cwMenuBarFileRecents();
    for (int i = 0; i < recentDocs.length; i++) {
        recentDocsMenu.addItem(recentDocs[i], menuCommand);
    }

    // Create the file menu
    MenuBar fileMenu = new MenuBar(true);
    fileMenu.setAnimationEnabled(true);
    menu.addItem(new MenuItem(constants.cwMenuBarFileCategory(), fileMenu));
    String[] fileOptions = constants.cwMenuBarFileOptions();
    for (int i = 0; i < fileOptions.length; i++) {
        if (i == 3) {
            fileMenu.addSeparator();
            fileMenu.addItem(fileOptions[i], recentDocsMenu);
            fileMenu.addSeparator();
        } else {
            fileMenu.addItem(fileOptions[i], menuCommand);
        }
    }

    // Create the edit menu
    MenuBar editMenu = new MenuBar(true);
    menu.addItem(new MenuItem(constants.cwMenuBarEditCategory(), editMenu));
    String[] editOptions = constants.cwMenuBarEditOptions();
    for (int i = 0; i < editOptions.length; i++) {
        editMenu.addItem(editOptions[i], menuCommand);
    }

    // Create the GWT menu
    MenuBar gwtMenu = new MenuBar(true);
    menu.addItem(new MenuItem("GWT", true, gwtMenu));
    String[] gwtOptions = constants.cwMenuBarGWTOptions();
    for (int i = 0; i < gwtOptions.length; i++) {
        gwtMenu.addItem(gwtOptions[i], menuCommand);
    }

    // Create the help menu
    MenuBar helpMenu = new MenuBar(true);
    menu.addSeparator();
    menu.addItem(new MenuItem(constants.cwMenuBarHelpCategory(), helpMenu));
    String[] helpOptions = constants.cwMenuBarHelpOptions();
    for (int i = 0; i < helpOptions.length; i++) {
        helpMenu.addItem(helpOptions[i], menuCommand);
    }

    // Return the menu
    menu.ensureDebugId("cwMenuBar");
    return menu;
}

From source file:net.sf.gudoku.client.widget.SudokuMenu.java

License:Open Source License

private void buildMenuBar() {
    addStyleName("menuBar");
    MenuBar menuBar = new MenuBar();

    MenuBar game = new MenuBar(true);
    game.addStyleName("menuBar");
    menuBar.addItem("Spiel", game);

    MenuItem newGame = new MenuItem("Spiel des Tages", new Command() {
        public void execute() {
            gudoku.newGame();/*from  ww  w  .ja v a 2 s .c  o  m*/
        }
    });
    newGame.addStyleName("menuItem");
    newGame.setTitle(
            "Lade Spiel des Tages (das jeweils aktuellste Spiel, unabh&auml;ngig des Schwierigkeitsgrades)");
    game.addItem(newGame);

    MenuItem loadGame = new MenuItem("Laden", new Command() {
        public void execute() {
            System.out.println("Laden");
        }
    });
    loadGame.setTitle("Lade Spiel des Tages");
    loadGame.addStyleName("menuItem");
    game.addItem(loadGame);

    MenuItem emptyGame = new MenuItem("Leer", new Command() {
        public void execute() {
            gudoku.newGame();
        }
    });
    emptyGame.setTitle("Erzeuge leeres Spielfeld, um R&auml;tsel manuell zu erzeugen");
    emptyGame.addStyleName("menuItem");
    game.addItem(emptyGame);

    MenuItem saveGame = new MenuItem("Speichern", new Command() {
        public void execute() {
            System.out.println("Speichern");
        }
    });
    saveGame.setTitle("Speichere Spiel");
    saveGame.addStyleName("menuItem");
    game.addItem(saveGame);

    MenuBar options = new MenuBar(true);
    options.addStyleName("menuBar");
    options.addStyleName("menuItem");
    menuBar.addItem("Extras", options);

    MenuItem settings = new MenuItem("Einstellungen", new Command() {
        public void execute() {
            System.out.println("Einstellungen");

        }
    });
    settings.setTitle("Kandidaten zeigen, ...");
    settings.addStyleName("menuItem");
    options.addItem(settings);

    add(menuBar);
}