List of usage examples for com.google.gwt.user.client.ui MenuItem getCommand
@Deprecated
public Command getCommand()
From source file:com.jitlogic.zico.widgets.client.MenuBar.java
License:Open Source License
@Override public void onBrowserEvent(Event event) { MenuItem item = find(DOM.eventGetTarget(event)); switch (DOM.eventGetType(event)) { case Event.ONCLICK: if (item != null && item.getCommand() != null && item.isEnabled()) { item.getCommand().execute(); popup.hide();/*from w w w. j a v a 2 s . c o m*/ } break; } super.onBrowserEvent(event); }
From source file:com.vaadin.client.ui.menubar.MenuBar.java
License:Apache License
protected void doItemAction(final MenuItem item, boolean fireCommand) { // If the given item is already showing its menu, we're done. if ((shownChildMenu != null) && (item.getSubMenu() == shownChildMenu)) { return;/*from www. jav a 2 s . co m*/ } // If another item is showing its menu, then hide it. if (shownChildMenu != null) { shownChildMenu.onHide(); popup.hide(); } // If the item has no popup, optionally fire its command. if (item.getSubMenu() == null) { if (fireCommand) { // Close this menu and all of its parents. closeAllParents(); // Fire the item's command. final Command cmd = item.getCommand(); if (cmd != null) { Scheduler.get().scheduleDeferred(cmd); } } return; } // Ensure that the item is selected. selectItem(item); // Create a new popup for this item, and position it next to // the item (below if this is a horizontal menu bar, to the // right if it's a vertical bar). popup = new VOverlay(true) { { setWidget(item.getSubMenu()); item.getSubMenu().onShow(); setOwner(MenuBar.this); } @Override public boolean onEventPreview(Event event) { // Hook the popup panel's event preview. We use this to keep it // from // auto-hiding when the parent menu is clicked. switch (DOM.eventGetType(event)) { case Event.ONCLICK: // If the event target is part of the parent menu, suppress // the // event altogether. final Element target = DOM.eventGetTarget(event); final Element parentMenuElement = item.getParentMenu().getElement(); if (DOM.isOrHasChild(parentMenuElement, target)) { return false; } break; } return super.onEventPreview(event); } }; popup.addPopupListener(this); if (vertical) { popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth(), item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft(), item.getAbsoluteTop() + item.getOffsetHeight()); } shownChildMenu = item.getSubMenu(); item.getSubMenu().parentMenu = this; // Show the popup, ensuring that the menubar's event preview remains on // top // of the popup's. popup.show(); }
From source file:com.vaadin.terminal.gwt.client.ui.MenuBar.java
License:Open Source License
void doItemAction(final MenuItem item, boolean fireCommand) { // If the given item is already showing its menu, we're done. if ((shownChildMenu != null) && (item.getSubMenu() == shownChildMenu)) { return;/*from ww w . j a v a2 s . c om*/ } // If another item is showing its menu, then hide it. if (shownChildMenu != null) { shownChildMenu.onHide(); popup.hide(); } // If the item has no popup, optionally fire its command. if (item.getSubMenu() == null) { if (fireCommand) { // Close this menu and all of its parents. closeAllParents(); // Fire the item's command. final Command cmd = item.getCommand(); if (cmd != null) { Scheduler.get().scheduleDeferred(cmd); } } return; } // Ensure that the item is selected. selectItem(item); // Create a new popup for this item, and position it next to // the item (below if this is a horizontal menu bar, to the // right if it's a vertical bar). popup = new VOverlay(true) { { setWidget(item.getSubMenu()); item.getSubMenu().onShow(); } @Override public boolean onEventPreview(Event event) { // Hook the popup panel's event preview. We use this to keep it // from // auto-hiding when the parent menu is clicked. switch (DOM.eventGetType(event)) { case Event.ONCLICK: // If the event target is part of the parent menu, suppress // the // event altogether. final Element target = DOM.eventGetTarget(event); final Element parentMenuElement = item.getParentMenu().getElement(); if (DOM.isOrHasChild(parentMenuElement, target)) { return false; } break; } return super.onEventPreview(event); } }; popup.addPopupListener(this); if (vertical) { popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth(), item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft(), item.getAbsoluteTop() + item.getOffsetHeight()); } shownChildMenu = item.getSubMenu(); item.getSubMenu().parentMenu = this; // Show the popup, ensuring that the menubar's event preview remains on // top // of the popup's. popup.show(); }
From source file:org.gwtportlets.portlet.client.edit.PageEditorMenuBar.java
License:Open Source License
public MenuItem addItem(MenuItem item) { MenuItem ans = super.addItem(item); final Command cmd = ans.getCommand(); if (cmd != null) { ans.setCommand(new Command() { public void execute() { pageEditor.hideMenu();//from w ww .j a v a 2 s . c om cmd.execute(); } }); } return ans; }
From source file:org.jbpm.formbuilder.client.options.OptionsPresenter.java
License:Apache License
public OptionsPresenter(OptionsView optionsView) { this.view = optionsView; this.bus = CommonGlobals.getInstance().getEventBus(); bus.addHandler(MenuOptionAddedEvent.TYPE, new MenuOptionAddedHandler() { @Override// ww w .j av a2s . c o m public void onEvent(MenuOptionAddedEvent event) { view.addItem(event.getOption()); } }); bus.addHandler(EmbededIOReferenceEvent.TYPE, new EmbededIOReferenceHandler() { @Override public void onEvent(EmbededIOReferenceEvent event) { List<MenuItem> items = view.getItems(); for (MenuItem item : items) { Command cmd = item.getCommand(); if (cmd != null && cmd instanceof BaseCommand) { BaseCommand baseCmd = (BaseCommand) cmd; baseCmd.setEmbeded(event.getProfileName()); } } } }); }
From source file:org.waveprotocol.wave.client.editor.sugg.SuggestionMenu.java
License:Apache License
private void handleEventInner(Event event) { switch (DOM.eventGetType(event)) { case Event.ONCONTEXTMENU: event.preventDefault();//w w w .ja v a 2 s . c om break; case Event.ONKEYPRESS: case Event.ONKEYDOWN: { // NOTE(user): It is necessary to stop propagation on the key events to // prevent them from leaking to the blip/wave presenters. int keyCode = DOM.eventGetKeyCode(event); // Move left/right to previous/next drop down widget switch (keyCode) { case KeyCodes.KEY_LEFT: case KeyCodes.KEY_RIGHT: handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT); event.stopPropagation(); return; case KeyCodes.KEY_ENTER: event.stopPropagation(); } if (keyCode >= '1' && keyCode <= '9') { // TODO(danilatos): Is this ok? i18n etc? int index = keyCode - '1'; if (index >= 0 && index < getItems().size()) { MenuItem item = getItems().get(index); if (item == null) { return; } item.getCommand().execute(); DOM.eventPreventDefault(event); } } break; } case Event.ONMOUSEOUT: { // Need to check that we really seem to have left the menu, as // mouse-out events get triggered whenever the mouse moves between // selections in the menu. EventTarget target = event.getRelatedEventTarget(); Element targetElement = Element.as(target); if (!getElement().isOrHasChild(targetElement)) { handler.handleMouseOut(); } break; } case Event.ONMOUSEOVER: { handler.handleMouseOver(); break; } } }