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.google.gwt.sample.showcase.client.content.lists.CwMenuBar.java

License:Apache License

/**
 * Initialize this example./*from   ww w .  j a  v  a2  s .co m*/
 */
@ShowcaseSource
@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:com.google.gwt.sample.stockwatcher.client.GuiWorldTree.java

public GuiWorldTree(GuiWorldTreeListener listener) {
    this.listener = listener;

    MenuBar insertMenu = new MenuBar(true);
    insertMenu.addItem("Sphere", new ObjectCommandInsertSphere());
    insertMenu.addItem("Box", new ObjectCommandInsertBox());
    insertMenu.addSeparator();/*  w ww .ja  v  a2 s.c o m*/
    insertMenu.addItem("Add", new ObjectCommandInsertCsgOp(Type.TypeAdd));
    insertMenu.addItem("Subtract", new ObjectCommandInsertCsgOp(Type.TypeSub));
    insertMenu.addItem("Intersect", new ObjectCommandInsertCsgOp(Type.TypeAnd));

    MenuBar objectMenu = new MenuBar();
    objectMenu.addItem(new Icon("shape_square_add.png"), insertMenu);
    objectMenu.addItem(new Icon("shape_square_delete.png"), new ObjectCommandDelete());
    objectMenu.addItem(new Icon("arrow_up.png"), new ObjectCommandMoveUp());
    objectMenu.addItem(new Icon("arrow_down.png"), new ObjectCommandMoveDown());

    guiTree.addSelectionHandler(new TreeSelectionHandler(this));

    FlowPanel menuFlowPanel = new FlowPanel();
    menuFlowPanel.add(objectMenu);
    menuFlowPanel.add(guiTree);
    menuPanel.add(menuFlowPanel);

    addNorth(menuPanel, 200);
}

From source file:com.gwtmodel.table.view.pullmenu.PullMenuView.java

License:Apache License

private void addMenu(MenuBar menu, List<MenuPullDesc> bmenu) {
    for (MenuPullDesc de : bmenu) {
        if (de.isHeader()) {
            MenuBar b = new MenuBar();
            addMenu(b, de.getbList());//  w  ww.ja va 2s  .c om
            menu.addItem(de.getDisplayName(), b);
        } else {
            ControlButtonDesc butt = de.getButt();
            menu.addItem(butt.getDisplayName(), new MenuCommand(butt));

        }
    }
}

From source file:com.gwtmodel.table.view.util.PopupCreateMenu.java

License:Apache License

public static MenuBar createMenu(final ListOfControlDesc coP, final IControlClick cli, final Widget w) {

    IGetStandardMessage iMess = GwtGiniInjector.getI().getStandardMessage();
    MenuBar menu = null;
    if (coP != null) {
        List<ControlButtonDesc> cL = coP.getcList();

        menu = new MenuBar(true);
        for (ControlButtonDesc b : cL) {
            BCall bc = new BCall(b, w, cli);
            // add menu item 'html name' to select it easier by selenium
            MenuItem i = menu.addItem(iMess.getMessage(b.getDisplayName()), bc);
            i.getElement().setId(b.getActionId().getHtmlElementName());
        }/*  w  w  w .j a v  a  2 s . c  o  m*/
    }
    return menu;
}

From source file:com.lushprojects.circuitjs1.client.CirSim.java

License:Open Source License

void processSetupList(byte b[], int len, final boolean openDefault) {
    MenuBar currentMenuBar;
    MenuBar stack[] = new MenuBar[6];
    int stackptr = 0;
    currentMenuBar = new MenuBar(true);
    currentMenuBar.setAutoOpen(true);// w  w  w.  j  a  va2s  .c o m
    menuBar.addItem(LS("Circuits"), currentMenuBar);
    stack[stackptr++] = currentMenuBar;
    int p;
    for (p = 0; p < len;) {
        int l;
        for (l = 0; l != len - p; l++)
            if (b[l + p] == '\n') {
                l++;
                break;
            }
        String line = new String(b, p, l - 1);
        if (line.charAt(0) == '#')
            ;
        else if (line.charAt(0) == '+') {
            //   MenuBar n = new Menu(line.substring(1));
            MenuBar n = new MenuBar(true);
            n.setAutoOpen(true);
            currentMenuBar.addItem(LS(line.substring(1)), n);
            currentMenuBar = stack[stackptr++] = n;
        } else if (line.charAt(0) == '-') {
            currentMenuBar = stack[--stackptr - 1];
        } else {
            int i = line.indexOf(' ');
            if (i > 0) {
                String title = LS(line.substring(i + 1));
                boolean first = false;
                if (line.charAt(0) == '>')
                    first = true;
                String file = line.substring(first ? 1 : 0, i);
                currentMenuBar
                        .addItem(new MenuItem(title, new MyCommand("circuits", "setup " + file + " " + title)));
                if (file.equals(startCircuit) && startLabel == null) {
                    startLabel = title;
                    titleLabel.setText(title);
                }
                if (first && startCircuit == null) {
                    startCircuit = file;
                    startLabel = title;
                    if (openDefault && stopMessage == null)
                        readSetupFile(startCircuit, startLabel, true);
                }
            }
        }
        p += l;
    }
}

From source file:com.novartis.pcs.ontology.webapp.client.OntoBrowser.java

License:Apache License

private void createOntologyMenu(List<Term> terms) {
    MenuBar menu = new MenuBar(true);
    menu.setAnimationEnabled(true);/*  w w w  . j a  va2 s  .  com*/

    for (final Term term : terms) {
        Ontology ontology = term.getOntology();
        if (!ontology.isCodelist()) {
            menu.addItem(ontology.getName(), new Command() {
                public void execute() {
                    History.newItem(term.getReferenceId());
                }
            });
        }
    }

    menuBar.insertItem(new MenuItem("Ontology", menu), 0);
}

From source file:com.novartis.pcs.ontology.webapp.client.OntoBrowser.java

License:Apache License

private void createPopupMenuItem(MenuBar menu, final String text, final OntoBrowserPopup popup) {
    menu.addItem(text, new Command() {
        public void execute() {
            popup.show();//from w  w w  . j av  a  2  s  .c  o m
        }
    });
}

From source file:com.objetdirect.gwt.umlapi.client.artifacts.clazz.ClassPartAttributesArtifact.java

License:Open Source License

@Override
public MenuBarAndTitle getRightMenu() {
    final MenuBarAndTitle rightMenu = new MenuBarAndTitle();
    rightMenu.setName("Attributes");

    for (final Entry<GfxObject, UMLClassAttribute> attribute : attributeGfxObjects.entrySet()) {
        final MenuBar subsubMenu = new MenuBar(true);
        subsubMenu.addItem("Edit ", this.editCommand(attribute.getKey()));
        subsubMenu.addItem("Delete ", this.deleteCommand(attribute.getValue()));
        rightMenu.addItem(attribute.getValue().toString(), subsubMenu);
    }/*from w  w  w.  j a va  2 s.c  o m*/
    rightMenu.addItem("Add new", this.editCommand());
    return rightMenu;
}

From source file:com.objetdirect.gwt.umlapi.client.artifacts.clazz.ClassPartMethodsArtifact.java

License:Open Source License

@Override
public MenuBarAndTitle getRightMenu() {
    final MenuBarAndTitle rightMenu = new MenuBarAndTitle();
    rightMenu.setName("Methods");

    for (final Entry<GfxObject, UMLClassMethod> method : methodGfxObjects.entrySet()) {
        final MenuBar subsubMenu = new MenuBar(true);
        subsubMenu.addItem("Edit ", this.editCommand(method.getKey()));
        subsubMenu.addItem("Delete ", this.deleteCommand(method.getValue()));
        rightMenu.addItem(method.getValue().toString(), subsubMenu);
    }//from   w w w .  j  av a  2 s . c  o  m
    rightMenu.addItem("Add new", this.editCommand());
    return rightMenu;
}

From source file:com.objetdirect.gwt.umlapi.client.artifacts.clazz.ClassRelationLinkArtifact.java

License:Open Source License

@Override
public MenuBarAndTitle getRightMenu() {
    final MenuBarAndTitle rightMenu = new MenuBarAndTitle();
    rightMenu.setName(relation.getLinkKind().getName() + " " + leftClassArtifact.getName() + " "
            + relation.getLeftAdornment().getShape().getIdiom() + "-"
            + relation.getRightAdornment().getShape().getIdiom(true) + " " + rightClassArtifact.getName());
    final MenuBar leftSide = new MenuBar(true);
    final MenuBar rightSide = new MenuBar(true);
    for (final RelationLinkArtifactPart relationLinkArtifactPart : RelationLinkArtifactPart.values()) {
        final MenuBar editDelete = new MenuBar(true);
        if (!relationLinkArtifactPart.getText(relation).equals("")) {
            editDelete.addItem("Edit", this.editCommand(relationLinkArtifactPart));
            editDelete.addItem("Delete", this.deleteCommand(relationLinkArtifactPart));
        } else {/*from  ww  w.  ja  va2s .c o m*/
            editDelete.addItem("Create", this.createCommand(relationLinkArtifactPart));
        }
        if (relationLinkArtifactPart.isLeft()) {
            leftSide.addItem(relationLinkArtifactPart.toString(), editDelete);
        } else {
            if (relationLinkArtifactPart != RelationLinkArtifactPart.NAME) {
                rightSide.addItem(relationLinkArtifactPart.toString(), editDelete);
            } else {
                rightMenu.addItem(relationLinkArtifactPart.toString(), editDelete);
            }
        }
    }

    final MenuBar leftNavigability = new MenuBar(true);
    leftNavigability.addItem("Navigable", this.setNavigabilityCommand(relation, true, true));
    leftNavigability.addItem("Not Navigable", this.setNavigabilityCommand(relation, true, false));
    leftNavigability.addItem("Unknown", this.setNavigabilityCommand(relation, true));
    leftSide.addItem("Navigability", leftNavigability);

    final MenuBar rightNavigability = new MenuBar(true);
    rightNavigability.addItem("Navigable", this.setNavigabilityCommand(relation, false, true));
    rightNavigability.addItem("Not Navigable", this.setNavigabilityCommand(relation, false, false));
    rightNavigability.addItem("Unknown", this.setNavigabilityCommand(relation, false));

    rightSide.addItem("Navigability", rightNavigability);
    rightMenu.addItem(leftClassArtifact.getName() + " side", leftSide);
    rightMenu.addItem(rightClassArtifact.getName() + " side", rightSide);
    rightMenu.addItem("Reverse", this.reverseCommand(relation));

    return rightMenu;
}