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:org.jboss.bpm.console.client.task.OpenTasksView.java

License:Open Source License

public void initialize() {
    if (!isInitialized) {
        taskList = new VerticalPanel();

        listBox = new CustomizableListBox<TaskRef>(new CustomizableListBox.ItemFormatter<TaskRef>() {

            public String format(TaskRef taskRef) {
                String result = "";

                result += String.valueOf(taskRef.getPriority());

                result += " ";

                result += taskRef.getProcessId();

                result += " ";

                result += taskRef.getName();

                result += " ";

                result += String.valueOf(taskRef.getCurrentState());

                result += " ";

                result += taskRef.getDueDate() != null ? dateFormat.format(taskRef.getDueDate()) : "";

                return result;
            }/*  w  w  w. j ava  2s  .  c o  m*/
        });

        listBox.setFirstLine("Priority, Process, Task Name, Status, Due Date");

        listBox.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                TaskRef task = getSelection(); // first call always null?
                if (task != null) {
                    controller.handleEvent(
                            new Event(UpdateDetailsAction.ID, new DetailViewEvent("OpenDetailView", task)));
                }
            }
        });

        // toolbar
        final VerticalPanel toolBox = new VerticalPanel();
        toolBox.setSpacing(5);

        final MenuBar toolBar = new MenuBar();
        toolBar.addItem("Refresh", new Command() {
            public void execute() {
                reload();
            }
        });

        toolBar.addItem("Claim", new Command() {
            public void execute() {
                TaskRef selection = getSelection();

                if (selection != null) {
                    controller.handleEvent(new Event(ClaimTaskAction.ID,
                            new TaskIdentityEvent(appContext.getAuthentication().getUsername(), selection)));
                } else {
                    Window.alert("Missing selection. Please select a task");
                }
            }
        });

        toolBox.add(toolBar);

        this.taskList.add(toolBox);
        this.taskList.add(listBox);

        pagingPanel = new PagingPanel(new PagingCallback() {
            public void rev() {
                renderUpdate();
            }

            public void ffw() {
                renderUpdate();
            }
        });

        this.taskList.add(pagingPanel);

        // ----

        // create and register views
        detailsView = new TaskDetailView(true);
        controller.addView("OpenDetailView", detailsView);
        detailsView.initialize();

        // deployments model listener
        ErraiBus.get().subscribe(Model.SUBJECT, new MessageCallback() {
            public void callback(Message message) {
                switch (ModelCommands.valueOf(message.getCommandType())) {
                case HAS_BEEN_UPDATED:
                    if (message.get(String.class, ModelParts.CLASS).equals(Model.PROCESS_MODEL)) {
                        reload();
                    }
                    break;
                }
            }
        });

        Timer t = new Timer() {
            @Override
            public void run() {
                // force loading
                reload();
            }
        };

        t.schedule(500);

        isInitialized = true;
    }
}

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  av  a2 s . com
        subMenu.addItem(html, new Command() {
            @Override
            public void execute() {
                reloadLocale(localeName, item);
            }
        });
    }
    item.setSubMenu(subMenu);
    item.setCommand(null);
}

From source file:org.jbpm.formbuilder.client.options.OptionsViewImpl.java

License:Apache License

protected void toMenuBar(MenuBar popup, MainMenuOption option) {
    String html = option.getHtml();
    BaseCommand cmd = option.getCommand();
    List<MainMenuOption> subMenu = option.getSubMenu();
    MenuItem item = null;/* www. j  a  va2s  .  c o  m*/
    if (cmd == null && subMenu != null && !subMenu.isEmpty()) {
        item = popup.addItem(new SafeHtmlBuilder().appendHtmlConstant(html).toSafeHtml(),
                toMenuBar(new MenuBar(true), subMenu));
    } else if (cmd != null && (subMenu == null || subMenu.isEmpty())) {
        item = popup.addItem(new SafeHtmlBuilder().appendHtmlConstant(html).toSafeHtml(), cmd);
        cmd.setItem(item);
    }
    if (item != null) {
        this.items.add(item);
        if (!option.isEnabled()) {
            item.setEnabled(false);
        }
    }

}

From source file:org.mobicents.slee.container.management.console.client.common.BrowseContainer.java

License:Open Source License

private void refreshLinks() {

    if (links.size() <= 1)
        return;//from   www  . j  av  a  2  s . c  om

    HorizontalPanel header = new HorizontalPanel();

    header.setStyleName("common-BrowseContainer-links");

    header.setSpacing(5);
    header.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    int firstLink = 0;

    if (!showAllLinks) {
        firstLink = Math.max(0, links.size() - MAX_BREADCRUMB_LINKS);

        if (firstLink > 0) {
            MenuBar hiddenMenu = new MenuBar();
            MenuBar subMenu = new MenuBar(true);

            for (int q = firstLink - 1; q >= 0; q--) {
                final int fq = q;
                Command cmd = new Command() {
                    public void execute() {
                        select(fq);
                    }
                };
                BrowseLink link = (BrowseLink) links.get(q);
                subMenu.addItem(link.getTitle(), cmd);
            }
            MenuItem root = new MenuItem("History", subMenu);
            hiddenMenu.addItem(root);
            /*
             * Hyperlink showAllLink = new Hyperlink("(show hidden)", "(show hidden)"); ClickListener listener = new ClickListener() { public
             * void onClick(Widget source) { showAllLinks = true; refresh(); showAllLinks = false; } }; showAllLink.addClickListener(listener);
             */
            header.add(hiddenMenu);
            header.add(new Image("images/chain.separator.gif"));
        }
    }
    for (int i = firstLink; i <= links.size() - 1; i++) {
        BrowseLink link = links.get(i);
        shortifyAndAddLink(header, link);
        if (i != links.size() - 1) {
            header.add(new Image("images/chain.separator.gif"));
            ((BrowseLink) links.get(i)).setStyle(false);
        } else {
            ((BrowseLink) links.get(i)).setStyle(true);
        }
    }
    rootPanel.add(header);
}

From source file:org.onecmdb.ui.gwt.modeller.client.control.ModelInheritanceTreeControl.java

License:Open Source License

public Widget getWidget(final Object data) {
    HorizontalPanel hpanel = (HorizontalPanel) super.getWidget(data);
    if (data instanceof GWT_CiBean) {
        final GWT_CiBean bean = (GWT_CiBean) data;

        final Image popup = new Image("images/eclipse/tree_menu2.gif");
        hpanel.add(popup);//from w w  w .j a va 2 s.c  o  m
        hpanel.setCellVerticalAlignment(popup, VerticalPanel.ALIGN_MIDDLE);
        popup.addClickListener(new ClickListener() {

            public void onClick(Widget sender) {
                System.out.println("Menu popup...");
                final PopupPanel p = new PopupPanel(true);
                //p.setStyleName("popup-menu");
                Command newInstance = new Command() {
                    public void execute() {
                        p.hide();
                        OneCMDBModelCreator.get().showScreen(OneCMDBModelCreator.NEW_INSTANCE_SCREEN,
                                bean.getAlias(), new Long(0));
                    }
                };
                Command newTemplate = new Command() {
                    public void execute() {
                        p.hide();
                        OneCMDBModelCreator.get().showScreen(OneCMDBModelCreator.NEW_TEMPLATE_SCREEN,
                                bean.getAlias(), new Long(0));
                    }
                };
                Command delete = new Command() {
                    public void execute() {
                        p.hide();
                        delete(bean);
                    }
                };

                // Make some sub-menus that we will cascade from the top menu.
                MenuBar fooMenu = new MenuBar(true);
                if (bean.isTemplate()) {
                    fooMenu.addItem("New Instance", newInstance);
                    fooMenu.addItem("New Template", newTemplate);
                }
                fooMenu.addItem("Delete", delete);

                p.setPopupPosition(popup.getAbsoluteLeft(), popup.getAbsoluteTop());
                p.setWidget(fooMenu);
                p.show();
            }

        });
    }
    return (hpanel);
}

From source file:org.openstreetmap.beboj.client.gui.MainMenu.java

License:GNU General Public License

public MainMenu() {
    Command c = new Command() {
        public void execute() {
            Window.alert("Test menu item!");
        }//w  w w.  j  a  v  a 2s . c  o  m
    };

    MenuBar fileMenu = new MenuBar(true);
    fileMenu.addItem("Update selection", c);
    fileMenu.addItem("Update data", c);
    fileMenu.addItem("Download Primitive...", c);

    MenuBar editMenu = new MenuBar(true);
    editMenu.addItem("Undo", c);
    editMenu.addItem("Redo", c);
    editMenu.addItem("Select all", c);

    MenuBar toolsMenu = new MenuBar(true);
    toolsMenu.addItem("Combine Ways", c);
    toolsMenu.addItem("Flip Way", c);
    toolsMenu.addItem("Align Way", c);

    // Make a new menu bar, adding a few cascading menus to it.
    addItem("File", fileMenu);
    addItem("Edit", editMenu);
    addItem("Tools", toolsMenu);
    getElement().setId("menu");
}

From source file:org.pentaho.mantle.client.ui.xul.MantleController.java

License:Open Source License

/**
 * Loads an arbitrary <code>FilePickList</code> into a menu
 * //w  ww  .  j  a  v  a 2  s  . c  om
 * @param pickMenu
 *          The XulMenuBar to host the menu entries
 * @param filePickList
 *          The files to list in natural order
 */
private void refreshPickListMenu(XulMenubar pickMenu,
        final AbstractFilePickList<? extends IFilePickItem> filePickList, PickListType type) {
    final MenuBar menuBar = (MenuBar) pickMenu.getManagedObject();
    menuBar.clearItems();

    final String menuClearMessage = Messages.getString(type.getMenuItemKey());
    final String clearMessage = Messages.getString(type.getMessageKey());

    if (filePickList.size() > 0) {
        for (IFilePickItem filePickItem : filePickList.getFilePickList()) {
            final String text = filePickItem.getFullPath();
            menuBar.addItem(filePickItem.getTitle(), new Command() {
                public void execute() {
                    SolutionBrowserPanel.getInstance().openFile(text, COMMAND.RUN);
                }
            });
        }
        menuBar.addSeparator();
        menuBar.addItem(menuClearMessage, new Command() {
            public void execute() {
                // confirm the clear
                GwtConfirmBox warning = new GwtConfirmBox();
                warning.setHeight(117);
                warning.setMessage(clearMessage);
                warning.setTitle(menuClearMessage);
                warning.setAcceptLabel(Messages.getString("clearRecentAcceptButtonLabel"));
                warning.setCancelLabel(Messages.getString("clearRecentCancelButtonLabel"));
                warning.addDialogCallback(new XulDialogCallback<String>() {
                    public void onClose(XulComponent sender, Status returnCode, String retVal) {
                        if (returnCode == Status.ACCEPT) {
                            filePickList.clear();
                        }
                    }

                    public void onError(XulComponent sender, Throwable t) {
                    }
                });
                warning.show();
            }
        });
    } else {
        menuBar.addItem(Messages.getString("empty"), new Command() { //$NON-NLS-1$
            public void execute() {
                // Do nothing
            }
        });
    }
}

From source file:org.pentaho.pat.client.ui.panels.TopMenu.java

License:Open Source License

public void setup() {

    this.clearItems();

    // Create a menu bar
    this.setAnimationEnabled(true);

    if (!Pat.isPlugin()) {
        final MenuBar fileMenu = createFileMenu();
        this.addItem(new MenuItem(Pat.CONSTANTS.file(), fileMenu));
    }/*from  ww w . j av  a  2s .c o  m*/

    final MenuBar conMenu = createConnectionMenu();
    conMenu.setAnimationEnabled(true);
    final MenuItem conItem = new MenuItem(Pat.CONSTANTS.connections(), conMenu);
    this.addItem(conItem);

    final MenuBar cubeMenu = createCubesMenu();
    cubeMenu.setAnimationEnabled(true);
    cubeMenu.setAutoOpen(true);
    final MenuItem cubeItem = new MenuItem(Pat.CONSTANTS.cubes(), cubeMenu);
    this.addItem(cubeItem);

    // Create the help menu
    MenuBar helpMenu = new MenuBar(true);
    helpMenu.clearItems();
    this.addItem(new MenuItem(Pat.CONSTANTS.help(), helpMenu));

    helpMenu.addItem("Donate", new Command() {

        public void execute() {
            Pat.openDonation();
        }

    });

    helpMenu.addItem(Pat.CONSTANTS.about(), new Command() {

        public void execute() {
            AboutWindow.display();
        }

    });

}

From source file:org.primordion.xholon.io.AbstractXholonGui.java

License:Open Source License

/**
 * Make a context menu for a specified GUI item.
 * @param guiItem//  w ww .j a  va 2  s .  c  o m
 * @param posX 
 * @param posY 
 */
public void makeContextMenu(Object guiItem, int posX, int posY) {
    if (guiItem == null) {
        return;
    }
    IXholon nnode = getXholonNode(guiItem);
    if (nnode == null) {
        return;
    }

    final IXholon node = nnode;
    final Object guiItemFinal = guiItem;
    rememberButton3Selection(node);
    PopupPanel popup = new PopupPanel(true);
    popup.hide();
    //setPopupPosition(int left, int top)
    popup.setPopupPosition(posX, posY);
    MenuBar menu = new MenuBar();

    // Special
    String[] specialItems = node.getActionList();
    String specialXml = app.rcConfig("special", app.findGwtClientBundle());
    //System.out.println(specialItems);
    if ((specialItems != null) || (specialXml != null)) {
        MenuBar specialSubMenu = new MenuBar(true);
        if (specialItems != null) {
            for (int i = 0; i < specialItems.length; i++) {
                final String actionName = specialItems[i];
                specialSubMenu.addItem(specialItems[i], new Command() {
                    @Override
                    public void execute() {
                        node.doAction(actionName);
                        refresh(guiItemFinal, node);
                    }
                });
            }
        }
        if (specialXml != null) {
            //node.consoleLog("special.xml");
            //node.consoleLog(specialXml);
            final Specials specials = new Specials();
            specials.xmlString2Items(specialXml, node);
            String[] moreSpecialItems = specials.getActionList();
            if (moreSpecialItems != null) {
                for (int i = 0; i < moreSpecialItems.length; i++) {
                    final String actionName = moreSpecialItems[i];
                    specialSubMenu.addItem(moreSpecialItems[i], new Command() {
                        @Override
                        public void execute() {
                            //node.consoleLog("execute() " + actionName);
                            specials.doAction(actionName);
                            //refresh(guiItemFinal, node);
                        }
                    });
                }
            }
        }
        menu.addItem("Special", specialSubMenu);
    }

    // Edit
    MenuBar editSubMenu = new MenuBar(true);
    editSubMenu.addItem("Copy", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_COPY_TOCLIPBOARD, node, null);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Cut", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_CUT_TOCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste Last Child", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_LASTCHILD_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste First Child", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_FIRSTCHILD_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste After", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_AFTER_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste Before", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_BEFORE_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste Replacement", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_REPLACEMENT_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Paste Merge", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_PASTE_MERGE_FROMCLIPBOARD, node, null);
            refresh(guiItemFinal, node);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });
    editSubMenu.addItem("Clone Last Child", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_CLONE_LASTCHILD, node, null);
        }
    });
    editSubMenu.addItem("Clone First Child", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_CLONE_FIRSTCHILD, node, null);
        }
    });
    editSubMenu.addItem("Clone After", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_CLONE_AFTER, node, null);
        }
    });
    editSubMenu.addItem("Clone Before", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_CLONE_BEFORE, node, null);
        }
    });
    editSubMenu.addItem("XQuery Thru Clipboard", new Command() {
        public void execute() {

        }
    }).setEnabled(false);
    editSubMenu.addItem("XQuery GUI", new Command() {
        public void execute() {

        }
    }).setEnabled(false);
    editSubMenu.addItem("Log Browser Console", new Command() {
        public void execute() {
            node.consoleLog(node);
        }
    });
    menu.addItem("Edit", editSubMenu);

    // Console
    menu.addItem("Xholon Console", new Command() {
        public void execute() {
            sendXholonHelperService(ISignal.ACTION_START_XHOLON_CONSOLE, node, null);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });

    // Attributes
    menu.addItem("Attributes", new Command() {
        public void execute() {
            createAttributesGui(node, false);
            //currentSelectionField.setText((String)node.handleNodeSelection());
        }
    });

    // Annotation
    MenuItem annMenuItem = menu.addItem("Annotation", new Command() {
        public void execute() {
            node.showAnnotation();
        }
    });
    if (node.hasAnnotation()) {
        annMenuItem.setEnabled(true);
    } else {
        annMenuItem.setEnabled(false);
    }

    // Search Engine
    MenuBar searchSubMenu = new MenuBar(true);
    final IXholon ses = app.getService(IXholonService.XHSRV_SEARCH_ENGINE);
    if (ses != null) {
        String[] sesItems = ses.getActionList();
        if (sesItems != null) {
            for (int i = 0; i < sesItems.length; i++) {
                final String menuName = sesItems[i];
                searchSubMenu.addItem(menuName, new Command() {
                    public void execute() {
                        String str = menuName + "," + node.getXhcName();
                        String roleNameStr = node.getRoleName();
                        if (roleNameStr != null && roleNameStr.length() != 0) {
                            str += "," + roleNameStr;
                        }
                        ses.doAction(str);
                    }
                });
            }
        }
    }

    // https://github.com/kenwebb/Xholon/blob/master/Xholon/src/org/primordion/xholon/base/Attribute.java
    searchSubMenu.addItem("Java source code", new Command() {
        public void execute() {
            StringBuilder sourceUrl = new StringBuilder();
            //sourceUrl.append("http://xholon.cvs.sourceforge.net/viewvc/xholon/xholon/src/");
            sourceUrl.append("https://github.com/kenwebb/Xholon/blob/master/Xholon/src/");
            String className = null;
            if (ClassHelper.isAssignableFrom(XholonClass.class, node.getClass())) {
                className = ((IXholonClass) node).getImplName();
            }
            if (className == null) {
                className = node.getClass().getName();
            }
            if (className != null) {
                if (className.endsWith("GWTGEN")) {
                    // there is no source code for this GWT-generated class
                    // use the original code (the superclass) instead
                    className = className.substring(0, className.length() - 6);
                }
                sourceUrl.append(className.replace('.', '/'));
                //sourceUrl.append(".java?view=markup");
                sourceUrl.append(".java");
                Window.open(sourceUrl.toString(), "_blank", ""); // starts with "http" or "https"
            }

        };
    });

    searchSubMenu.addItem("Java javadoc", new Command() {
        public void execute() {
            // http://www.primordion.com/Xholon/gwt/javadoc/org/primordion/xholon/xmiapps/XhElevator.html
            StringBuilder javadocUrl = new StringBuilder();
            javadocUrl.append(GwtEnvironment.gwtHostPageBaseURL + "javadoc/");
            String className = null;
            if (ClassHelper.isAssignableFrom(XholonClass.class, node.getClass())) {
                className = ((IXholonClass) node).getImplName();
            }
            if (className == null) {
                className = node.getClass().getName();
            }
            if (className != null) {
                if (className.endsWith("GWTGEN")) {
                    // there is no javadoc for this GWT-generated class
                    // use the original code (the superclass) instead
                    className = className.substring(0, className.length() - 6);
                }
                javadocUrl.append(className.replace('.', '/'));
                javadocUrl.append(".html");
                Window.open(javadocUrl.toString(), "_blank", ""); // starts with "http"
            }

        };
    });

    menu.addItem("Search Engine", searchSubMenu);

    // Export to external formats
    final ExternalFormatService efs = GWT.create(org.primordion.xholon.service.ExternalFormatService.class);
    String[] efItems = efs.getActionList();
    if (efItems != null) {
        MenuBar efSubMenu = new MenuBar(true);
        for (int i = 0; i < efItems.length; i++) {
            //System.out.println(efItems[i]);
            if (efItems[i].startsWith("_")) {
                // this is a submenu item
                String[] efItemSubSubMenuStr = efItems[i].substring(1).split(",");
                if (efItemSubSubMenuStr.length >= 2) {
                    final String efItemSubSubMenuName = efItemSubSubMenuStr[0];
                    MenuBar efSubSubMenu = new MenuBar(true);
                    for (int j = 1; j < efItemSubSubMenuStr.length; j++) {
                        final String efItem = efItemSubSubMenuStr[j];
                        efSubSubMenu.addItem(efItem, new Command() {
                            @Override
                            public void execute() {
                                IXholon2ExternalFormat xholon2ef = efs.initExternalFormatWriter(node,
                                        "_" + efItemSubSubMenuName + "," + efItem, null, true);
                                efs.writeAll(xholon2ef);
                            }
                        });
                    }
                    efSubMenu.addItem(efItemSubSubMenuName, efSubSubMenu);
                }
            } else {
                final String efItem = efItems[i];
                efSubMenu.addItem(efItems[i], new Command() {
                    @Override
                    public void execute() {
                        IXholon2ExternalFormat xholon2ef = efs.initExternalFormatWriter(node, efItem, null,
                                true);
                        efs.writeAll(xholon2ef);
                    }
                });

            }
        }
        menu.addItem("Export", efSubMenu);
    }

    // Graphical Network Viewer
    // use ef Xholon2ChapNetwork.java instead
    /*menu.addItem("Graphical Network Viewer", new Command() {
      public void execute() {
        if ((node.getXhcId() == CeStateMachineEntity.StateMachineCE)
    || (node.getXhcId() == CeStateMachineEntity.RegionCE)
    || (node.getXhcId() == CeStateMachineEntity.StateCE)) {
          String myParams = null;
          IViewer viewer = app.invokeGraphicalNetworkViewer(node, myParams);
          //currentSelectionField.setText((String)node.handleNodeSelection());
          //StateMachineXhym smXhym = new StateMachineXhym();
          //smXhym.postConfigure(node, (IGraphicalNetworkViewer)viewer);
        }
        else if (ClassHelper.isAssignableFrom(Application.class, node.getClass())) {
          String myParams = null;
          app.invokeGraphicalNetworkViewer(node, myParams);
          //currentSelectionField.setText((String)node.handleNodeSelection());
        }
        else {
          String myParams = null;
          app.invokeGraphicalNetworkViewer(node, myParams);
          //currentSelectionField.setText((String)node.handleNodeSelection());
        }
      }
    });*/

    // Graphical Tree Viewer
    // use ef Xholon2ChapTree.java instead
    /*menu.addItem("Graphical Tree Viewer", new Command() {
      public void execute() {
        String myParams = null;
        IViewer viewer = app.invokeGraphicalTreeViewer(node, myParams);
        //currentSelectionField.setText((String)node.handleNodeSelection());
      }
    });*/

    // Control
    MenuBar controlSubMenu = new MenuBar(true);
    controlSubMenu.addItem("Start", new Command() {
        public void execute() {
            IXholon cnode = app.getControlRoot().getFirstChild();
            cnode.handleNodeSelection();
        }
    });
    controlSubMenu.addItem("Pause", new Command() {
        public void execute() {
            IXholon cnode = app.getControlRoot().getFirstChild().getNextSibling();
            cnode.handleNodeSelection();
        }
    });
    controlSubMenu.addItem("Step", new Command() {
        public void execute() {
            IXholon cnode = app.getControlRoot().getFirstChild().getNextSibling().getNextSibling();
            cnode.handleNodeSelection();
        }
    });
    controlSubMenu.addItem("Stop", new Command() {
        public void execute() {
            IXholon cnode = app.getControlRoot().getFirstChild().getNextSibling().getNextSibling()
                    .getNextSibling();
            cnode.handleNodeSelection();
        }
    });
    controlSubMenu.addItem("Refresh", new Command() {
        public void execute() {
            refresh();
        }
    });
    menu.addItem("Control", controlSubMenu);

    // Help
    MenuBar helpSubMenu = new MenuBar(true);
    helpSubMenu.addItem("About", new Command() {
        public void execute() {
            if (app != null) {
                app.about();
            }
        }
    });
    helpSubMenu.addItem("Getting Started", new Command() {
        public void execute() {
            gettingStarted("Getting Started with Xholon", splashText, 375, 475);
        }
    });
    helpSubMenu.addItem("Information", new Command() {
        public void execute() {
            if (app != null) {
                app.information();
            }
        }
    });
    helpSubMenu.addItem("JavaScript API", new Command() {
        public void execute() {
            Window.open(GwtEnvironment.gwtHostPageBaseURL + "jsapidoc/modules/XholonJsApi.html", "_blank", "");
        }
    });
    menu.addItem("Help", helpSubMenu);

    popup.add(menu);
    popup.show();
}

From source file:org.primordion.xholon.io.console.XholonConsole.java

License:Open Source License

public void postConfigure() {
    // set various Xholon attributes for XholonConsole
    IXholonClass ixc = app.getClassNode("XholonConsole");
    if (ixc != null) {
        setXhc(ixc);/*ww w.ja  v  a  2 s.  c o m*/
    }
    setId(app.getNextId());
    setRoleName(context.getName());

    if ((context.getXhc() != null) && context.getXhc().hasAncestor("Avatar")) {
        setTerminalEnabled(true);
        sendMsgAsyncOrSync = SENDMESSAGE_SYNC;
    }

    historyQ = new Queue(historyQSize);

    // append this new node to the View
    /*
    IXholon view = app.getAppRoot().getFirstChild();
    while (view != null) {
      if ("View".equals(view.getRoleName())) {
        break;
      }
      view = view.getNextSibling();
    }
    if (view != null) {
      IXholon viewXholonConsole = view.getFirstChild();
      while (viewXholonConsole != null) {
        if ("XholonConsoles".equals(viewXholonConsole.getRoleName())) {
          break;
        }
        viewXholonConsole = viewXholonConsole.getNextSibling();
      }
      if (viewXholonConsole == null) {
        // create a container XholonConsole node
        viewXholonConsole =
          ((IControl)view).setControlNode("XholonConsoles", (Control)view, view.getXhc());
      }
      appendChild(viewXholonConsole);
    }
    */
    readGuiFromXml();

    // Special menu
    String specialXml = app.rcConfig("special", app.findGwtClientBundle());
    if (specialXml != null) {
        //node.consoleLog("special.xml");
        //node.consoleLog(specialXml);
        final Specials specials = new Specials();
        specials.xmlString2Items(specialXml, this);
        String[] moreSpecialItems = specials.getActionList();
        if (moreSpecialItems != null) {
            MenuBar specialSubMenu = new MenuBar(true);
            for (int i = 0; i < moreSpecialItems.length; i++) {
                final String actionName = moreSpecialItems[i];
                specialSubMenu.addItem(actionName, new Command() {
                    @Override
                    public void execute() {
                        //context.consoleLog("execute() " + actionName);
                        specials.doAction(actionName);
                    }
                });
            }
            special.setSubMenu(specialSubMenu);
        }
    } else {
        //special.setEnabled(false);
        special.getParentMenu().removeItem(special);
    }

    // History menu
    // TODO History menu is only updated if I click on "History"
    // TODO don't add duplicates to the historyQ
    history.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            if (historyQ.getSize() > 0) {
                MenuBar historySubMenu = new MenuBar(true);
                List<String> hitems = (List<String>) historyQ.getItems();
                for (int i = 0; i < hitems.size(); i++) {
                    final String hitem = hitems.get(i);
                    historySubMenu.addItem(limitLength(hitem, 80), new Command() {
                        @Override
                        public void execute() {
                            if (isTerminalEnabled()) {
                                // replace the content of the last line with hitem
                                String taval = getCommand();
                                int lastNewlinePos = taval.lastIndexOf("\n");
                                if (lastNewlinePos == -1) {
                                    setResult(hitem, true);
                                } else {
                                    setResult(taval.substring(0, lastNewlinePos + 1) + hitem, true);
                                }
                            } else {
                                // replace entire console contents with hitem
                                setResult(hitem, true);
                            }
                        }
                    });
                }
                history.setSubMenu(historySubMenu);
            }
        }
    });

    // File menu
    fileopen.setEnabled(false);
    filesave.setEnabled(false);
    filesaveas.setEnabled(false);
    closeguiMI.setEnabled(false);

    // Edit menu

    clearcommand.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            clearCommand();
        }
    });

    increasefontsize.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            changeFontSize(2.0);
        }
    });

    decreasefontsize.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            changeFontSize(-2.0);
        }
    });

    // Mode menu
    //modedefault.setEnabled(true);
    //modexpath.setEnabled(true);
    //modejs.setEnabled(true);
    modeattr.setEnabled(false);

    modedefault.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            setMode("default:");
        }
    });

    modexpath.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            setMode("xpath:");
        }
    });

    modejs.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            setMode("js:");
        }
    });

    modeattr.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            setMode("attr:");
        }
    });

    terminal.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            terminalEnabled = !terminalEnabled;
        }
    });

    // Help menu

    help.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            help();
        }
    });

    xpath.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            xpathExamples();
        }
    });

    jsscript.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            jsScript();
        }
    });

    behaviorScript.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            behaviorScript();
        }
    });

    behaviorScriptProto.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            behaviorScriptProto();
        }
    });

    behaviorScriptInstance.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            behaviorScriptInstance();
        }
    });

    // handle the submit MenuItem
    submit.setScheduledCommand(new Command() {
        @Override
        public void execute() {
            submit();
        }
    });

    // TextArea  handle ENTER key
    // TODO bug - TextArea.wrap(commandPaneTAE), in devmode, fails on assertion that the element is attached
    TextArea ta = null;
    try {
        ta = TextArea.wrap(commandPaneTAE);
    } catch (AssertionError ae) {
        // execute the lines of code that are in TextArea.wrap(); it won't compile
        //ta = new TextArea(commandPaneTAE);
        // Mark it attached and remember it for cleanup.
        //ta.onAttach();
        //RootPanel.detachOnWindowClose(ta);
        this.consoleLog("XholonConsole " + ae.toString());
    } finally {
        if (ta != null) {
            ta.addKeyDownHandler(new KeyDownHandler() {
                @Override
                public void onKeyDown(KeyDownEvent event) {
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                        if (isTerminalEnabled()) {
                            submit();
                        }
                    }
                }
            });
        }
    }
}