Example usage for com.google.gwt.user.client.ui MenuItem setCommand

List of usage examples for com.google.gwt.user.client.ui MenuItem setCommand

Introduction

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

Prototype

@Deprecated
public void setCommand(Command cmd) 

Source Link

Document

Sets the command associated with this item.

Usage

From source file:com.qualogy.qafe.gwt.client.factory.WindowFactory.java

License:Apache License

private static void processMenu(MenuItemGVO root, MenuBar menuBar, final String uuid) {
    MenuBar subMenuBar = null;/*w  w w .j ava  2s .c  om*/
    if (QAFEKeywordsGVO.SYSTEM_MENU_APPLICATIONS.equals(root.getId())) {
        MenuBar applicationsMenu = new MenuBar(true);
        applicationsMenu.setAutoOpen(true);
        ClientApplicationContext.getInstance().setApplicationsMenu(applicationsMenu);

        subMenuBar = ClientApplicationContext.getInstance().getApplicationsMenu();
        subMenuBar.setAnimationEnabled(true);
        subMenuBar.setAutoOpen(true);
        MenuItem menuItem = GWTUIGenerator.createMenuItem(root.getId(), root.getDisplayname(), uuid,
                root.getContext(), subMenuBar);
        menuBar.addItem(menuItem);
    }

    if (root.getSubMenus() != null) {
        if (subMenuBar == null) {
            subMenuBar = new MenuBar(true);
            subMenuBar.setAnimationEnabled(true);
            subMenuBar.setAutoOpen(true);
            MenuItem menuItem = GWTUIGenerator.createMenuItem(root.getId(), root.getDisplayname(), uuid,
                    root.getContext(), subMenuBar);
            menuBar.addItem(menuItem);
        }

        for (int i = 0; i < root.getSubMenus().length; i++) {
            processMenu(root.getSubMenus()[i], subMenuBar, uuid);
        }
        ClientApplicationContext.getInstance().addMenu(root.getId(), subMenuBar);

    } else {
        if (!QAFEKeywordsGVO.SYSTEM_MENU_APPLICATIONS.equals(root.getId()) && root.getDisplayname() != null
                && !root.getDisplayname().equals(menuBar.getTitle())) {
            MenuItem menuItem = new MenuItem(root.getDisplayname(), (Command) null);
            RendererHelper.fillIn(root, menuItem, uuid, null, root.getContext());
            // DOM.setElementAttribute(menuItem.getElement(), "id",
            // root.getId());
            Command cmd = null;
            if (QAFEKeywordsGVO.SYSTEM_MENUITEM_LOGGING.equals(root.getId())) {
                cmd = new Command() {
                    public void execute() {

                    }
                };
            } else if (QAFEKeywordsGVO.SYSTEM_MENUITEM_RELOAD.equals(root.getId())) {
                cmd = new Command() {

                    public void execute() {
                        if (ClientApplicationContext.getInstance().getReloadable()) {
                            MainFactoryActions.processReloadUIFromApplicationContext();
                        } else {
                            ClientApplicationContext.getInstance().log("Not available",
                                    "Reloading of application is only available in debug mode", true);
                        }
                    }
                };
            } else if (QAFEKeywordsGVO.SYSTEM_MENUITEM_TRYME.equals(root.getId())) {
                cmd = new Command() {

                    public void execute() {
                        if (ClientApplicationContext.getInstance().isDebugMode()) {
                            MainFactory.createTryMeWindow(QAFEKeywordsGVO.SYSTEM_MENUITEM_TRYME);
                        } else {
                            ClientApplicationContext.getInstance().log("Not available",
                                    "Try me feature is only available in debug mode", true);
                        }
                    }
                };
            } else if (QAFEKeywordsGVO.SYSTEM_MENUITEM_TRYME_FORMS.equals(root.getId())) {
                cmd = new Command() {

                    public void execute() {
                        if (ClientApplicationContext.getInstance().isDebugMode()) {
                            MainFactory.createTryMeWindow(QAFEKeywordsGVO.SYSTEM_MENUITEM_TRYME_FORMS);
                        } else {
                            ClientApplicationContext.getInstance().log("Not available",
                                    "Try me feature is only available in debug mode", true);
                        }
                    }
                };

            } else {
                if ((root.getEvents() != null) && (root.getEvents().length > 0)) {
                    EventListenerGVO eventListenerGVO = root.getEvents()[0];
                    cmd = EventFactory.createCommandListener(menuItem, eventListenerGVO, null);
                }
            }
            menuItem.setCommand(cmd);
            menuBar.addItem(menuItem);
        } else if (root instanceof MenuItemSeparatorGVO) {
            MenuItemSeparator menuItemSeparator = new MenuItemSeparator();
            menuBar.addSeparator(menuItemSeparator);
            //menuBar.addItem((MenuItem)menuItemSeparator);
        }
    }
}

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

License:Apache License

private static MenuItem createMenuItem(final String title, final String uuid, final String windowId,
        final UIGVO uiGVO, final boolean tryMe) {
    final MenuItem menuItem = new MenuItem(title, (Command) null);
    MenuItemGVO menuItemGVO = new MenuItemGVO();
    menuItemGVO.setId(windowId);//  w  ww.  j  a  v  a 2 s .  c o  m
    RendererHelper.fillIn(menuItemGVO, menuItem, uuid, null, uiGVO.getAppId());

    Command command = new Command() {
        public void execute() {

            if (ClientApplicationContext.getInstance().isDesktopNotificationPossible()
                    && Notification.isNotificationNotAllowed()) {
                Notification.requestPermission();
            }

            // ClientApplicationContext.getInstance().removeWindow(windowId,
            // uuid);
            WindowPanel existingWindowPanel = ClientApplicationContext.getInstance().windowIdExists(windowId,
                    uuid);
            if (existingWindowPanel == null) {
                if (tryMe) {
                    MainFactoryActions.getUIByUUID(uuid, windowId);
                } else {
                    String eventType = QAMLConstants.EVENT_ONCLICK;
                    EventListenerGVO eventGVO = uiGVO.getEventMap().get(windowId);
                    createCallBack4OpenWindow(menuItem, eventType, eventGVO);
                }
                // MainFactoryActions.getUIByUUID(uuid, windowId);
            } else {
                Iterator itr = ClientApplicationContext.getInstance().getHorizontalPanel().iterator();
                while (itr.hasNext()) {
                    Widget w = (Widget) itr.next();
                    if (w.getTitle().equals(title)) {
                        existingWindowPanel.setWindowState(WindowState.NORMAL);
                        existingWindowPanel.show();
                        ClientApplicationContext.getInstance().getHorizontalPanel().remove(w);
                    }
                }
                existingWindowPanel.toFront();
            }
        }

    };
    menuItem.setCommand(command);

    return menuItem;
}

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

License:Apache License

public static void processEvents(ComponentGVO vo, UIObject ui, EventListenerGVO event,
        List<com.qualogy.qafe.gwt.client.vo.ui.event.InputVariableGVO> inputVariables, String appId) {
    if (ui != null) {
        String nonHandledEventName = null;
        String nonHandledEventMessage = null;
        if (event instanceof OnEnterEventListenerGVO) {
            if (ui instanceof HasAllKeyHandlers) {
                HasAllKeyHandlers hasAllKeyHandlers = (HasAllKeyHandlers) ui;
                hasAllKeyHandlers.addKeyDownHandler(EventFactory.createOnEnterListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONENTER;
            }/*  ww w  .  ja  va  2 s.  c  om*/
        }
        if (event instanceof OnFocusEventListenerGVO) {
            if (ui instanceof HasFocusHandlers) {
                HasFocusHandlers hasFocusHandlers = (HasFocusHandlers) ui;
                hasFocusHandlers.addFocusHandler(EventFactory.createFocusListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONFOCUS;
            }
        }
        if (event instanceof OnExitEventListenerGVO) {
            if (ui instanceof HasBlurHandlers) {
                HasBlurHandlers hasBlurHandlers = (HasBlurHandlers) ui;
                hasBlurHandlers.addBlurHandler(EventFactory.createOnExitListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONEXIT;
            }
        }
        if (event instanceof ClickEventListenerGVO) {
            if (ui instanceof HasClickHandlers) {
                ui.addStyleName("qafe_hand");
                HasClickHandlers hasClickHandlers = (HasClickHandlers) ui;
                hasClickHandlers.addClickHandler(EventFactory.createClickListener(event, inputVariables));
            } else if (ui instanceof MenuItem) {
                MenuItem menuItem = (MenuItem) ui;
                menuItem.setCommand(EventFactory.createCommandListener(menuItem, event, inputVariables));
                ui.addStyleName("qafe_hand");
            } else if (ui instanceof AreaWidget) {
                AreaWidget area = (AreaWidget) ui;
                area.setCommand(EventFactory.createCommandListener(area, event, inputVariables));
                ui.addStyleName("qafe_hand");
            } else if (ui instanceof TabPanel) {
                TabPanel tabPanel = (TabPanel) ui;
                String eventComponentId = event.getEventComponentId();
                String[] components = eventComponentId.split("\\.");
                if (components.length == 1) {
                    tabPanel.addSelectionHandler(
                            EventFactory.createTabPanelListener(tabPanel, event, inputVariables));
                    ui.addStyleName("qafe_hand");
                }
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONCLICK;
            }
        }
        if (event instanceof DoubleClickEventListenerGVO) {
            if (ui instanceof HasDoubleClickHandlers) {
                //ui.addStyleName("qafe_hand");
                HasDoubleClickHandlers hasDoubleClickHandlers = (HasDoubleClickHandlers) ui;
                hasDoubleClickHandlers
                        .addDoubleClickHandler(EventFactory.createDoubleClickListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONDBLCLICK;
            }
        }
        if (event instanceof OnChangeEventListenerGVO) {
            if (ui instanceof QSuggestBox) {
                QSuggestBox suggestionBox = (QSuggestBox) ui;
                suggestionBox.addKeyUpHandler(
                        EventFactory.createSuggestionOnKeyUpHandler(suggestionBox, event, inputVariables));
            } else if (ui instanceof QDatePicker && ui instanceof HasValueChangeHandlers) {
                HasValueChangeHandlers hasValueChangeHandlers = (HasValueChangeHandlers) ui;
                hasValueChangeHandlers.addValueChangeHandler(
                        (EventFactory.createOnValueChangeHandler(event, inputVariables)));
            } else if (ui instanceof HasDataChangeHandlers) {
                HasDataChangeHandlers hasDataChangeHandlers = (HasDataChangeHandlers) ui;
                hasDataChangeHandlers
                        .addDataChangeHandler((EventFactory.createOnDataChangeHandler(event, inputVariables)));
            } else if (ui instanceof HasChangeHandlers) {
                HasChangeHandlers hasChangeHandlers = (HasChangeHandlers) ui;
                hasChangeHandlers
                        .addChangeHandler((EventFactory.createOnChangeListener(event, inputVariables)));
            } else if (ui instanceof SourcesChangeEvents) {
                SourcesChangeEvents sourcesChangeEvents = (SourcesChangeEvents) ui;
                sourcesChangeEvents
                        .addChangeListener(EventFactory.createLegacyOnChangeListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONCHANGE;
            }
        }
        if (event instanceof OnMouseEnterEventListenerGVO) {
            if (ui instanceof HasAllMouseHandlers) {
                HasAllMouseHandlers hasAllMouseHandlers = (HasAllMouseHandlers) ui;
                hasAllMouseHandlers
                        .addMouseOverHandler(EventFactory.createOnMouseEnterListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONMOUSE_ENTER;
            }
        }
        if (event instanceof OnMouseExitEventListenerGVO) {
            if (ui instanceof HasAllMouseHandlers) {
                HasAllMouseHandlers hasAllMouseHandlers = (HasAllMouseHandlers) ui;
                hasAllMouseHandlers
                        .addMouseOutHandler(EventFactory.createOnMouseExitListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONMOUSE_EXIT;
            }
        }
        if (event instanceof OnMouseMoveEventListenerGVO) {
            if (ui instanceof HasAllMouseHandlers) {
                HasAllMouseHandlers hasAllMouseHandlers = (HasAllMouseHandlers) ui;
                hasAllMouseHandlers
                        .addMouseMoveHandler(EventFactory.createOnMouseMoveListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONMOUSE_MOVE;
            }
        }
        if (event instanceof OnMouseUpEventListenerGVO) {
            if (ui instanceof HasAllMouseHandlers) {
                HasAllMouseHandlers hasAllMouseHandlers = (HasAllMouseHandlers) ui;
                hasAllMouseHandlers
                        .addMouseUpHandler(EventFactory.createOnMouseUpListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONMOUSE_UP;
            }
        }
        if (event instanceof OnMouseDownEventListenerGVO) {
            if (ui instanceof HasAllMouseHandlers) {
                HasAllMouseHandlers hasAllMouseHandlers = (HasAllMouseHandlers) ui;
                hasAllMouseHandlers
                        .addMouseDownHandler(EventFactory.createOnMouseDownListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONMOUSE_DOWN;
            }
        }
        if (event instanceof OnKeyPressEventListenerGVO) {
            if (ui instanceof HasAllKeyHandlers) {
                HasAllKeyHandlers hasAllKeyHandlers = (HasAllKeyHandlers) ui;
                hasAllKeyHandlers
                        .addKeyPressHandler(EventFactory.createOnKeyPressListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONKEYPRESS;
            }
        }
        if (event instanceof OnKeyDownEventListenerGVO) {
            if (ui instanceof HasAllKeyHandlers) {
                HasAllKeyHandlers hasAllKeyHandlers = (HasAllKeyHandlers) ui;
                hasAllKeyHandlers
                        .addKeyDownHandler(EventFactory.createOnKeyDownListener(event, inputVariables));
            } else if (ui instanceof HasNativeKeyHandlers) {
                HasNativeKeyHandlers hasNativeKeyHandlers = (HasNativeKeyHandlers) ui;
                hasNativeKeyHandlers.addNativeKeyDownHandler(
                        EventFactory.createOnNativeKeyDownListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONKEYDOWN;
            }
        }
        if (event instanceof OnKeyUpEventListenerGVO) {
            if (ui instanceof HasAllKeyHandlers) {
                HasAllKeyHandlers hasAllKeyHandlers = (HasAllKeyHandlers) ui;
                hasAllKeyHandlers.addKeyUpHandler(EventFactory.createOnKeyUpListener(event, inputVariables));
            } else if (ui instanceof HasNativeKeyHandlers) {
                HasNativeKeyHandlers hasNativeKeyHandlers = (HasNativeKeyHandlers) ui;
                hasNativeKeyHandlers
                        .addNativeKeyUpHandler(EventFactory.createOnNativeKeyUpListener(event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONKEYUP;
            }
        }
        if (event instanceof OnLoadEventListenerGVO) {
            if (!(vo instanceof WindowGVO)) {
                nonHandledEventName = QAMLConstants.EVENT_ONLOAD;
                nonHandledEventMessage = "Support on Window only.";
            }
        }
        if (event instanceof OnUnLoadEventListenerGVO) {
            if (!(vo instanceof WindowGVO)) {
                nonHandledEventName = QAMLConstants.EVENT_ONUNLOAD;
                nonHandledEventMessage = "Support on Window only.";
            }
        }
        if (event instanceof OnFinishEventListenerGVO) {
            if (ui instanceof FormPanel) {
                FormPanel formPanel = (FormPanel) ui;
                formPanel.addSubmitCompleteHandler(
                        EventFactory.createSubmitCompleteHandler(ui, event, inputVariables));
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONFINISH;
            }
        }
        if (event instanceof OnTimerEventListenerGVO) {
            //check a timer is already scheduled for this event- this happens when there are multiple component reference mentioned in that event
            if (!ClientApplicationContext.getInstance().isTimerScheduledForEvent(appId, vo.getWindow(),
                    event.getEventId())) {
                OnTimerHandler timerHandler = new OnTimerHandler();
                timerHandler.processOnTimer(ui, vo, appId, event, inputVariables);
            } else {
                nonHandledEventName = QAMLConstants.EVENT_ONTIMER;
                nonHandledEventMessage = "Timer is already scheduled.";
            }
        }
        if (nonHandledEventName != null) {
            if (nonHandledEventMessage == null) {
                nonHandledEventMessage = "";
            }
            ClientApplicationContext.getInstance()
                    .log("The component [" + DOM.getElementAttribute(ui.getElement(), "id") + "] for event ["
                            + event.getEventId() + "] does not support " + nonHandledEventName + " listener. "
                            + nonHandledEventMessage, null);
        }
    }
}

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();/*  w w w.  j  a v  a2s .c om*/
                cmd.execute();
            }
        });
    }
    return ans;
}

From source file:org.jbpm.formbuilder.client.command.LanguageCommand.java

License:Apache License

@Override
public void setItem(final MenuItem item) {
    MenuBar subMenu = new MenuBar(true);
    String[] availableLocaleNames = LocaleInfo.getAvailableLocaleNames();
    for (final String localeName : availableLocaleNames) {
        String html = LocaleInfo.getLocaleNativeDisplayName(localeName);
        if (html == null || "".equals(html)) {
            html = i18n.LocaleDefault();
        }//from  w  w w  .  j  a  v a2 s . c o m
        subMenu.addItem(html, new Command() {
            @Override
            public void execute() {
                reloadLocale(localeName, item);
            }
        });
    }
    item.setSubMenu(subMenu);
    item.setCommand(null);
}