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.objetdirect.gwt.umlapi.client.artifacts.object.ObjectPartAttributesArtifact.java

License:Open Source License

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

    for (final Entry<GfxObject, UMLObjectAttribute> 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);
    }/*  ww w . j  a  va2 s . c  o m*/
    rightMenu.addItem("Add new", this.editCommand());
    return rightMenu;
}

From source file:com.objetdirect.gwt.umlapi.client.artifacts.object.ObjectRelationLinkArtifact.java

License:Open Source License

/**
 * Build a menubar to edit or create a role. The role is the name for a side of the relation.
 * /*  w  ww.j a v a 2s .co m*/
 * If the role is empty, the menu bar is just a "create" item.
 * 
 * Else, the menu has two items : edit or delete.
 * 
 * @param gfxObjectToEdit
 *            If the role is empty, null Else the gfxObject which display the role. Ie leftRoleGfxObject or
 *            rightRoleGfxObject.
 * @param editorPart
 *            The editor the edit the role
 * @return
 */
private MenuBar buildRoleMenuBar(final GfxObject gfxObjectToEdit, final EditorPart editorPart) {
    MenuBar menu = new MenuBar(true);

    if (editorPart.getText().isEmpty()) {
        Command createCommand = new Command() {
            @Override
            public void execute() {
                editorPart.setText("Role");
                rebuildGfxObject();
            }
        };

        menu.addItem("Role", createCommand);
    } else {
        Command editCommand = new Command() {
            @Override
            public void execute() {
                edit(gfxObjectToEdit);
            }
        };

        Command deleteCommand = new Command() {
            @Override
            public void execute() {
                editorPart.setText("");
                rebuildGfxObject();
            }
        };

        menu.addItem("Edit", editCommand);
        menu.addItem("Delete", deleteCommand);
    }

    return menu;
}

From source file:com.objetdirect.gwt.umlapi.client.contextMenu.ContextMenu.java

License:Open Source License

/**
 * Build the internal contextual menu.//from   w  w  w  .  j  av a  2  s.c o  m
 */
protected void makeMenu() {
    contextMenu = new PopupMenu();
    contextMenu.setAutoOpen(true);
    contextMenu.setAutoHideEnabled(true);
    if (specificRightMenu != null) {
        final MenuBar specificSubMenu = specificRightMenu.getSubMenu();
        specificSubMenu.addItem("Delete", removeCommand);
        contextMenu.addItem(specificRightMenu.getName(), specificSubMenu);
        contextMenu.addSeparator();
    }

    makeSpecificDiagramMenu();

    contextMenu.addItem("Add new note", addNewNoteCommand);

    addSpecificRelationDiagramMenu();

    contextMenu.addItem("Cut", cutCommand);
    contextMenu.addItem("Copy", copyCommmand);
    contextMenu.addItem("Paste", pasteCommand);

    contextMenu.addSeparator();
    contextMenu.addItem("Switch links style", changeLinkStyleCommand);

    contextMenu.addItem("Clear diagram", clearDiagramCommand);
    contextMenu.addItem("Hotkeys...", bringHelpCommand);
}

From source file:com.objetdirect.gwt.umlapi.client.contextMenu.ContextMenu.java

License:Open Source License

/**
 * Add a relation menu item on the given menu.
 * /*  w  ww .j  a v  a  2 s . com*/
 * @param subMenu
 *            The menu where the new menu item is added
 * @param relationName
 *            The name of the menu item
 * @param relationKind
 *            the kind of relation
 */
protected void addRelationCommand(final MenuBar subMenu, String relationName, final LinkKind relationKind) {
    final Command relationCommand = new Command() {
        @Override
        public void execute() {
            canvas.toLinkMode(relationKind);
        }
    };

    subMenu.addItem(relationName, relationCommand);
}

From source file:com.objetdirect.gwt.umlapi.client.contextMenu.ObjectContextMenu.java

License:Open Source License

@Override
protected void addSpecificRelationDiagramMenu() {
    final MenuBar relationsSubMenu = new MenuBar(true);

    if (relationMenu != null && relationMenu.getNumberOfItem() > 0) {
        relationsSubMenu.addItem(relationMenu.getName(), relationMenu.getSubMenu());
    }/* w ww.  j a  v  a2  s . c o m*/

    addRelationCommand(relationsSubMenu, "Association", OBJECT_RELATION);
    addRelationCommand(relationsSubMenu, "Instantiation", INSTANTIATION);
    addRelationCommand(relationsSubMenu, "Note link", NOTE);

    contextMenu.addItem("Add relation", relationsSubMenu);
    contextMenu.addSeparator();
}

From source file:com.qualogy.qafe.gwt.client.ui.renderer.MenuItemRenderer.java

License:Apache License

public UIObject render(ComponentGVO component, String uuid, String parent, String context) {
    UIObject uiObject = null;//  w  ww .  j a v  a 2s .c o  m
    if (component != null) {
        if (component instanceof MenuItemGVO) {
            MenuItemGVO menuItemGVO = (MenuItemGVO) component;
            //            if (menuItemGVO.getIsTopLevelMenu() != null
            //                  && menuItemGVO.getIsTopLevelMenu().booleanValue()) {
            //
            Command cmd = new Command() {
                public void execute() {
                    ClientApplicationContext.getInstance().log("Default MenuItem command",
                            "You selected a menu item!", true);
                }
            };
            MenuItemGVO[] subMenus = menuItemGVO.getSubMenus();
            if (subMenus != null) {
                uiObject = new MenuBar();
                MenuBar menuBar = (MenuBar) uiObject;
                for (int i = 0; i < subMenus.length; i++) {
                    UIObject renderedObject = render(subMenus[i], uuid, parent, context);
                    if (renderedObject instanceof MenuBar) {
                        menuBar.addItem(menuItemGVO.getDisplayname(), (MenuBar) renderedObject);
                    } else if (renderedObject instanceof MenuItem) {
                        menuBar.addItem((MenuItem) renderedObject);
                    }
                }
            } else {
                uiObject = new MenuItem(menuItemGVO.getDisplayname(), cmd);
            }
            //            } else {
            //               Command cmd = new Command() {
            //                  public void execute() {
            //                        ClientApplicationContext.getInstance().log("Default menu item command","You selected a menu item!",true);
            //                  }
            //               };
            //               MenuItemGVO[] subMenus = menuItemGVO.getSubMenus();
            //               if (subMenus != null) {
            //                  uiObject = new MenuBar(true);
            //                  MenuBar menuBar = (MenuBar) uiObject;
            //                  for (int i = 0; i < subMenus.length; i++) {
            //                     UIObject renderedObject = render(subMenus[i],uuid,parent);
            //                     if (renderedObject instanceof MenuBar) {
            //                        menuBar.addItem(menuItemGVO.getDisplayname(),
            //                              (MenuBar) renderedObject);
            //                     } else if (renderedObject instanceof MenuItem) {
            //                        menuBar.addItem((MenuItem) renderedObject);
            //                     }
            //                  }
            //               } else {
            //                  uiObject = new MenuItem(menuItemGVO.getDisplayname(), cmd);
            //               }
            //            }

        }
    }

    return uiObject;
}

From source file:com.qualogy.qafe.gwt.client.ui.renderer.RendererHelper.java

License:Apache License

public static void addMenu(ComponentGVO vo, UIObject ui, String uuid, String parent) {
    if (vo != null && ui != null) {
        if (vo.getMenu() != null) {
            MenuBar menu = new MenuBar();
            menu.setAutoOpen(true);//w  ww .  j a  va2 s.  c o m
            menu.setWidth("100%");
            UIObject renderedComponent = new MenuItemRenderer().render(vo.getMenu(), uuid, parent,
                    vo.getContext());
            if (renderedComponent instanceof MenuBar) {
                menu.addItem(vo.getMenu().getDisplayname(), (MenuBar) renderedComponent);
            } else if (renderedComponent instanceof MenuItem) {
                menu.addItem((MenuItem) renderedComponent);
            }
            if (ui instanceof DockPanel) {
                ((DockPanel) ui).add(menu, DockPanel.NORTH);
            } else if (ui instanceof Grid || ui instanceof VerticalPanel || ui instanceof HorizontalPanel)
                ((Panel) ui).add(menu);
        }
    }

}

From source file:com.qualogy.qafe.mgwt.client.ui.renderer.MenuItemRenderer.java

License:Apache License

public UIObject render(ComponentGVO component, String owner, String uuid, String parent, String context,
        AbstractActivity activity) {/*  www. j  a  va 2 s .c o  m*/
    UIObject uiObject = null;
    if (component != null) {
        if (component instanceof MenuItemGVO) {
            MenuItemGVO menuItemGVO = (MenuItemGVO) component;
            //            if (menuItemGVO.getIsTopLevelMenu() != null
            //                  && menuItemGVO.getIsTopLevelMenu().booleanValue()) {
            //
            Command cmd = new Command() {
                public void execute() {
                    ClientApplicationContext.getInstance().log("Default MenuItem command",
                            "You selected a menu item!", true);
                }
            };
            MenuItemGVO[] subMenus = menuItemGVO.getSubMenus();
            if (subMenus != null) {
                uiObject = new MenuBar();
                MenuBar menuBar = (MenuBar) uiObject;
                for (int i = 0; i < subMenus.length; i++) {
                    UIObject renderedObject = render(subMenus[i], owner, uuid, parent, context, activity);
                    if (renderedObject instanceof MenuBar) {
                        menuBar.addItem(menuItemGVO.getDisplayname(), (MenuBar) renderedObject);
                    } else if (renderedObject instanceof MenuItem) {
                        menuBar.addItem((MenuItem) renderedObject);
                    }
                }
            } else {
                uiObject = new MenuItem(menuItemGVO.getDisplayname(), cmd);
            }
            //            } else {
            //               Command cmd = new Command() {
            //                  public void execute() {
            //                        ClientApplicationContext.getInstance().log("Default menu item command","You selected a menu item!",true);
            //                  }
            //               };
            //               MenuItemGVO[] subMenus = menuItemGVO.getSubMenus();
            //               if (subMenus != null) {
            //                  uiObject = new MenuBar(true);
            //                  MenuBar menuBar = (MenuBar) uiObject;
            //                  for (int i = 0; i < subMenus.length; i++) {
            //                     UIObject renderedObject = render(subMenus[i],uuid,parent);
            //                     if (renderedObject instanceof MenuBar) {
            //                        menuBar.addItem(menuItemGVO.getDisplayname(),
            //                              (MenuBar) renderedObject);
            //                     } else if (renderedObject instanceof MenuItem) {
            //                        menuBar.addItem((MenuItem) renderedObject);
            //                     }
            //                  }
            //               } else {
            //                  uiObject = new MenuItem(menuItemGVO.getDisplayname(), cmd);
            //               }
            //            }

        }
    }

    return uiObject;
}

From source file:com.qualogy.qafe.mgwt.client.ui.renderer.RendererHelper.java

License:Apache License

public static void addMenu(ComponentGVO vo, UIObject ui, String uuid, String parent) {
    if (vo != null && ui != null) {
        if (vo.getMenu() != null) {
            MenuBar menu = new MenuBar();
            menu.setAutoOpen(true);/*w  ww.  j a v a  2 s  . co  m*/
            menu.setWidth("100%");
            UIObject renderedComponent = new MenuItemRenderer().render(vo.getMenu(), null, uuid, parent,
                    vo.getContext(), null);
            if (renderedComponent instanceof MenuBar) {
                menu.addItem(vo.getMenu().getDisplayname(), (MenuBar) renderedComponent);
            } else if (renderedComponent instanceof MenuItem) {
                menu.addItem((MenuItem) renderedComponent);
            }
            if (ui instanceof DockPanel) {
                ((DockPanel) ui).add(menu, DockPanel.NORTH);
            } else if (ui instanceof Grid || ui instanceof VerticalPanel || ui instanceof HorizontalPanel)
                ((Panel) ui).add(menu);
        }
    }

}

From source file:com.vaadin.addon.spreadsheet.client.SelectionWidget.java

private void showTouchActions() {
    if (touchMode) {
        // show touch actions in popup

        if (touchActions != null) {
            // remove old
            touchActions.hide();//from w w w . j a v a2 s  . co m
        }

        touchActions = new VOverlay(true);
        touchActions.setOwner((Widget) sheetWidget.actionHandler);
        touchActions.addStyleName("v-contextmenu");

        final MenuBar m = new MenuBar();
        m.addItem(new SafeHtmlBuilder().appendEscaped("Fill").toSafeHtml(), new ScheduledCommand() {

            @Override
            public void execute() {
                setFillMode(true);
                touchActions.hide();
            }
        });

        touchActions.add(m);

        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                touchActions.setPopupPositionAndShow(new PositionCallback() {

                    @Override
                    public void setPosition(int offsetWidth, int offsetHeight) {
                        // above top border
                        int top = 0;
                        int left = 0;
                        int bottom = 0;
                        int width = 0;
                        int parentTop = 0;
                        if (topRight != null && topRight.isVisible()) {
                            top = topRight.top.getAbsoluteTop();
                            left = topRight.top.getAbsoluteLeft();
                            width = topRight.top.getClientWidth();
                            bottom = topRight.bottom.getAbsoluteBottom() + 5;
                            if (topLeft.isVisible()) {
                                width += topLeft.top.getClientWidth();
                            }
                            if (bottomRight.isVisible()) {
                                bottom = bottomRight.bottom.getAbsoluteBottom() + 5;
                            }
                        } else if (topLeft != null && topLeft.isVisible()) {
                            top = topLeft.top.getAbsoluteTop();
                            left = topLeft.top.getAbsoluteLeft();
                            width = topLeft.top.getClientWidth();
                            bottom = topLeft.bottom.getAbsoluteBottom() + 5;
                            if (bottomLeft.isVisible()) {
                                bottom = bottomLeft.bottom.getAbsoluteBottom() + 5;
                            }
                        } else if (bottomLeft != null && bottomLeft.isVisible()) {
                            top = bottomLeft.top.getAbsoluteTop();
                            left = bottomLeft.top.getAbsoluteLeft();
                            width = bottomLeft.top.getClientWidth();
                            bottom = bottomLeft.bottom.getAbsoluteBottom() + 5;
                            if (bottomRight.isVisible()) {
                                width += bottomRight.top.getClientWidth();
                            }
                        } else {
                            top = bottomRight.top.getAbsoluteTop();
                            left = bottomRight.top.getAbsoluteLeft();
                            width = bottomRight.top.getClientWidth();
                            bottom = bottomRight.bottom.getAbsoluteBottom() + 5;
                        }
                        if (width > sheetWidget.getElement().getClientWidth()) {
                            width = sheetWidget.getElement().getClientWidth();
                        }

                        if (sheetWidget.hasFrozenRows()) {
                            parentTop = sheetWidget.getTopRightPane().getAbsoluteTop();
                        } else {
                            parentTop = sheetWidget.getBottomRightPane().getAbsoluteTop();
                        }

                        top -= offsetHeight + 5;
                        left += (width / 2) - (offsetWidth / 2);

                        if (parentTop > top) {
                            // put under instead
                            top = bottom + 5;
                        }
                        touchActions.setPopupPosition(left, top);

                        // TODO check for room
                    }
                });
                touchActions.show();
            }
        });
    }
}