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.apache.oozie.tools.workflowgenerator.client.OozieWorkflowGenerator.java

License:Apache License

/**
 * Initialize menu panel on top//from  w w w  .  j  a v a  2s. c om
 *
 * @return
 */
public MenuBar initMenu() {

    // Menu bar
    Command cmd = new Command() {
        public void execute() {
            Window.alert("To be implemented soon");
        }
    };

    Command mr_cmd = new Command() {
        public void execute() {
            initWidget();
            MapReduceActionWidget mr = new MapReduceActionWidget(OozieWorkflowGenerator.this);
            mr.setName("MR_0");
            addWidget(mr, 300, 100);
            ((OozieDiagramController) controller).addConnection(start, mr);
            ((OozieDiagramController) controller).addConnection(mr, end);
            mr.updateOnSelection();
        }
    };

    Command pig_cmd = new Command() {

        public void execute() {
            clear();
            initWidget();
            PigActionWidget pig = new PigActionWidget(OozieWorkflowGenerator.this);
            pig.setName("Pig_0");
            addWidget(pig, 300, 100);
            ((OozieDiagramController) controller).addConnection(start, pig);
            ((OozieDiagramController) controller).addConnection(pig, end);
            pig.updateOnSelection();
        }
    };

    Command java_cmd = new Command() {

        public void execute() {
            clear();
            initWidget();
            JavaActionWidget java = new JavaActionWidget(OozieWorkflowGenerator.this);
            java.setName("Java_0");
            addWidget(java, 300, 100);
            ((OozieDiagramController) controller).addConnection(start, java);
            ((OozieDiagramController) controller).addConnection(java, end);
            java.updateOnSelection();
        }
    };

    Command forkjoin_cmd = new Command() {

        public void execute() {
            clear();
            initWidget();
            ForkNodeWidget fork = new ForkNodeWidget(OozieWorkflowGenerator.this);
            fork.setName("Fork_0");
            addWidget(fork, 150, 100);
            ((OozieDiagramController) controller).addConnection(start, fork);

            MapReduceActionWidget mr = new MapReduceActionWidget(OozieWorkflowGenerator.this);
            mr.setName("MR_0");
            addWidget(mr, 300, 30);
            ((OozieDiagramController) controller).addMultiConnection(fork, mr);

            PigActionWidget pig = new PigActionWidget(OozieWorkflowGenerator.this);
            pig.setName("Pig_0");
            addWidget(pig, 300, 200);
            ((OozieDiagramController) controller).addMultiConnection(fork, pig);

            JoinNodeWidget join = new JoinNodeWidget(OozieWorkflowGenerator.this);
            join.setName("Join_0");
            addWidget(join, 450, 100);
            ((OozieDiagramController) controller).addConnection(mr, join);
            ((OozieDiagramController) controller).addConnection(pig, join);
            ((OozieDiagramController) controller).addConnection(join, end);

            fork.updateOnSelection();
            join.updateOnSelection();
            mr.updateOnSelection();
            pig.updateOnSelection();
        }
    };

    Command clear_cmd = new Command() {

        public void execute() {
            clear();
        }

    };

    MenuBar fileMenu = new MenuBar(true);
    fileMenu.setAutoOpen(true);
    fileMenu.setAnimationEnabled(true);
    fileMenu.addItem("New", cmd);
    fileMenu.addItem("Open", cmd);
    fileMenu.addItem("Load XML", cmd);
    fileMenu.addItem("Save", cmd);
    fileMenu.addItem("Save As..", cmd);
    fileMenu.addItem("Generate XML", cmd);
    fileMenu.addItem("Print", cmd);
    fileMenu.addItem("Quit", cmd);

    MenuBar editMenu = new MenuBar(true);
    editMenu.setAutoOpen(true);
    editMenu.setAnimationEnabled(true);
    editMenu.addItem("Undo", cmd);
    editMenu.addItem("Redo", cmd);
    editMenu.addItem("Copy", cmd);
    editMenu.addItem("Cut", cmd);
    editMenu.addItem("Paste", cmd);
    editMenu.addItem("Duplicate", cmd);
    editMenu.addItem("Delete", cmd);
    editMenu.addItem("Clear Diagram", clear_cmd);

    MenuBar examples = new MenuBar(true);
    examples.setAutoOpen(true);
    examples.setAnimationEnabled(true);
    examples.addItem("wrkflow with MR action", mr_cmd);
    examples.addItem("wrkflow with Pig action", pig_cmd);
    examples.addItem("wrkflow with Java action", java_cmd);
    examples.addItem("wrkflow with Fork/Join ", forkjoin_cmd);

    MenuBar helpMenu = new MenuBar(true);
    helpMenu.setAutoOpen(true);
    helpMenu.setAnimationEnabled(true);

    // TODO this should point to a workflowgenerator's maven site, however there is no maven site available. (Not even in
    // Workspace of the jenkins job at https://builds.apache.org/job/oozie-trunk-precommit-build/ws/workflowgenerator/target/)
    // where client, for example, has target/site/apidocs
    // The ideal place is somewhere under http://oozie.apache.org/docs/ once it is generated.
    Command openOozieTopPageComman = new Command() {
        @Override
        public void execute() {
            Window.open("http://oozie.apache.org/", "_blank", "");
        }
    };
    helpMenu.addItem("Documentation", openOozieTopPageComman);
    helpMenu.addItem("Online Help", openOozieTopPageComman);

    Command aboutCommand = new Command() {
        @Override
        public void execute() {
            // Dialogbox
            final DialogBox d = new DialogBox(false, true);
            d.setGlassEnabled(true);
            d.setText("About Oozie Workflow Generator");
            d.center();

            // Set this to workaround the grid z-index issue https://issues.apache.org/jira/browse/OOZIE-1081
            d.getElement().getStyle().setZIndex(ZINDEX_FRONT_OF_GRID);

            // About text
            VerticalPanel vpanel = new VerticalPanel();
            vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
            vpanel.setSpacing(10);
            vpanel.setWidth("150");
            vpanel.add(new Label("Oozie Workflow Generator"));
            vpanel.add(new Label("Version 3.4.0-SNAPSHOT")); // TODO how to get a version number from pom?

            // OK button to close
            Button ok = new Button("OK");
            ok.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    d.hide();
                }

            });

            vpanel.add(ok);
            d.setWidget(vpanel);
            d.show();

        }
    };
    helpMenu.addItem("About", aboutCommand);

    MenuBar menu = new MenuBar();
    menu.addItem("File", fileMenu);
    menu.addItem("Edit", editMenu);
    menu.addItem("Example", examples);
    menu.addItem("Help", helpMenu);

    return menu;
}

From source file:org.datacleaner.monitor.scheduling.widgets.CustomizeAlertClickHandler.java

License:Open Source License

@Override
public void onClick(ClickEvent event) {
    final MenuBar menuBar = new MenuBar(true);

    menuBar.addItem("Edit alert", new Command() {
        @Override/*ww  w .j a va 2s  .  c om*/
        public void execute() {
            final DCPopupPanel popup = new DCPopupPanel("Edit alert");

            final TenantIdentifier tenant = _alertPanel.getSchedule().getTenant();
            final JobIdentifier job = _alertPanel.getSchedule().getJob();
            final AlertDefinition alert = _alertPanel.getAlert();

            descriptorService.getJobMetrics(tenant, job, new DCAsyncCallback<JobMetrics>() {
                @Override
                public void onSuccess(JobMetrics jobMetrics) {
                    final CustomizeAlertPanel customizeAlertPanel = new CustomizeAlertPanel(tenant, job, alert,
                            jobMetrics);
                    final Button button = DCButtons.primaryButton("glyphicon-save", "Save alert");
                    button.addClickHandler(new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            customizeAlertPanel.updateAlert();
                            _alertPanel.updateAlert();
                            popup.hide();
                        }
                    });

                    popup.setWidget(customizeAlertPanel);
                    popup.addButton(button);
                    popup.addButton(new CancelPopupButton(popup));
                    popup.center();
                    popup.show();
                }
            });
        }
    });

    menuBar.addItem("Remove alert", new Command() {
        @Override
        public void execute() {
            _alertPanel.removeAlert();
        }
    });

    final DCPopupPanel popup = new DCPopupPanel(null);
    popup.setGlassEnabled(false);
    popup.setWidget(menuBar);
    popup.setAutoHideEnabled(true);
    popup.getButtonPanel().setVisible(false);
    popup.showRelativeTo((UIObject) event.getSource());
}

From source file:org.datacleaner.monitor.scheduling.widgets.CustomizeJobClickHandler.java

License:Open Source License

@Override
public void onClick(ClickEvent event) {
    final JobIdentifier job = _schedulePanel.getSchedule().getJob();
    final MenuBar menuBar = new MenuBar(true);

    menuBar.addItem("Execution History", new HistoryCommand(_schedule, _service, _tenant, _popup));

    final boolean analysisJob = JobIdentifier.JOB_TYPE_ANALYSIS_JOB.equals(job.getType());
    if (analysisJob && _clientConfig.isWebstartAvailable()) {
        menuBar.addItem("Edit job", new EditJobCommand(_tenant, _schedule, _popup));
    }//from  w w  w.j  a  v  a  2 s  .c  o  m

    menuBar.addItem("Rename job", new RenameJobCommand(_tenant, job, _popup));
    menuBar.addItem("Copy job", new CopyJobCommand(_tenant, job, _popup));
    menuBar.addItem("Delete job", new DeleteJobCommand(_tenant, job, _popup));
    menuBar.addItem("Add Alert", new AddAlertCommand(_schedule, _service, _popup));

    if (analysisJob) {
        menuBar.addSeparator();
        menuBar.addItem("View Job Definition", new ViewJobDefinitionCommand(_tenant, job, _popup));
    }

    _popup.setWidget(menuBar);
    _popup.showRelativeTo((UIObject) event.getSource());
}

From source file:org.dataconservancy.dcs.access.client.model.JsManifestationFile.java

License:Apache License

public static void display(Panel panel, JsArray<JsManifestationFile> array) {
    // Doesn't deal well with large array
    // FlexTable table = Util.createTable("Path", "Ref");
    // ScrollPanel top = new ScrollPanel(table);
    // top.setSize("300px", "5em");
    ////from  w w w  . j ava2 s  .c  om
    // for (int i = 0; i < array.length(); i++) {
    // JsManifestationFile mf = array.get(i);
    //
    // table.setText(0, i + 1, mf.getPath());
    // table.setWidget(1, i + 1, Util.entityLink(mf.getRef()));
    // }
    //
    // panel.add(top);

    MenuBar top = new MenuBar();
    // TODO work around bug with menubar width
    top.setWidth("15ex");
    top.setAnimationEnabled(true);

    MenuBar refs = new MenuBar(true);

    top.addItem("File refs (" + array.length() + ")", refs);

    for (int i = 0; i < array.length(); i++) {
        final JsManifestationFile mf = array.get(i);
        String label = mf.getPath();

        if (label.isEmpty()) {
            label = mf.getRef();
        }

        refs.addItem(label, new Command() {
            public void execute() {
                History.newItem(State.ENTITY.toToken(mf.getRef()));
            }
        });
    }

    panel.add(top);
}

From source file:org.dataconservancy.dcs.access.client.Util.java

License:Apache License

public static Widget entityLinks(JsArrayString ids) {
    if (ids.length() == 0) {
        return new Label();
    }/*from  w ww . j av  a2s  . c o  m*/

    MenuBar top = new MenuBar();
    // TODO work around bug with menubar width
    top.setWidth("15ex");
    top.setAnimationEnabled(true);

    MenuBar refs = new MenuBar(true);

    top.addItem("Entities (" + ids.length() + ")", refs);

    for (int i = 0; i < ids.length(); i++) {
        final String id = ids.get(i);

        refs.addItem(id, new Command() {
            public void execute() {
                History.newItem(SeadState.ENTITY.toToken(id));
            }
        });
    }

    return top;
}

From source file:org.dataconservancy.dcs.access.client.Util.java

License:Apache License

public static Widget metadataLinks(JsArrayString ids) {
    if (ids.length() == 0) {
        return new Label();
    }//from w w  w .  j a va 2s .co  m

    MenuBar top = new MenuBar();
    top.setWidth("15ex");
    top.setAnimationEnabled(true);

    final MenuBar refs = new MenuBar(true);

    top.addItem("View Metadata (" + ids.length() + ")", refs);

    for (int i = 0; i < ids.length(); i++) {
        final String id = ids.get(i);
        JsonpRequestBuilder rb = new JsonpRequestBuilder();

        String query = Search.createLiteralQuery("id", id);
        String searchUrl = Search.searchURL(query, 0, true, Constants.MAX_SEARCH_RESULTS);
        rb.requestObject(searchUrl, new AsyncCallback<JsSearchResult>() {

            public void onFailure(Throwable caught) {
                reportInternalError("Viewing entity", caught);
            }

            public void onSuccess(final JsSearchResult result) {
                final JsMatch m = result.matches().get(0);
                if (m.getEntityType().equalsIgnoreCase("file")) {

                    final JsArray<JsFormat> formats = ((JsFile) m.getEntity()).getFormats();
                    if (formats.length() > 0) {

                        refs.addItem(formats.get(0).getFormat(), new Command() {
                            public void execute() {
                                String fileSource = ((JsFile) m.getEntity()).getPrimaryDataLocation()
                                        .getLocation();
                                if (!(fileSource.startsWith("http://") || fileSource.startsWith("https://")))
                                    fileSource = ((JsFile) m.getEntity()).getSource();
                                MetadataPopupPanel statusPopupPanel = new MetadataPopupPanel(fileSource,
                                        formats.get(0).getFormat());
                                statusPopupPanel.show();
                            }
                        });
                    }
                }
            }
        });

    }

    return top;
}

From source file:org.dataconservancy.dcs.access.ui.client.Util.java

License:Apache License

public static Widget entityLinks(JsArrayString ids) {
    if (ids.length() == 0) {
        return new Label();
    }/*from   w w  w. j a  va 2 s  .  c o m*/

    MenuBar top = new MenuBar();
    // TODO work around bug with menubar width
    top.setWidth("15ex");
    top.setAnimationEnabled(true);

    MenuBar refs = new MenuBar(true);

    top.addItem("Entities (" + ids.length() + ")", refs);

    for (int i = 0; i < ids.length(); i++) {
        final String id = ids.get(i);

        refs.addItem(id, new Command() {
            public void execute() {
                History.newItem(State.ENTITY.toToken(id));
            }
        });
    }

    return top;
}

From source file:org.drools.guvnor.client.asseteditor.DefaultMultiViewEditorMenuBarCreator.java

License:Apache License

public MenuBar createMenuBar(final MultiViewEditor editor, EventBus eventBus) {

    MenuBar toolbar = new MenuBar();

    toolbar.addItem(constants.SaveAllChanges(), new Command() {

        public void execute() {
            editor.checkin(false);//from w w  w  .j a  va2s  .  co  m
        }
    });
    toolbar.addItem(constants.SaveAndCloseAll(), new Command() {

        public void execute() {
            editor.checkin(true);
        }
    });

    return toolbar;
}

From source file:org.drools.guvnor.client.asseteditor.drools.standalone.RealAssetsMultiViewEditorMenuBarCreator.java

License:Apache License

@Override
public MenuBar createMenuBar(final MultiViewEditor editor, EventBus eventBus) {
    MenuBar toolbar = super.createMenuBar(editor, eventBus);
    toolbar.addItem(Constants.INSTANCE.Cancel(), this.cancelCommand);
    return toolbar;
}

From source file:org.drools.guvnor.client.asseteditor.drools.standalone.TemporalAssetsMultiViewEditorMenuBarCreator.java

License:Apache License

/**
 * Creates a menu bar with 2 buttons: "Done" and "Cancel". Because this is 
 * meant for temporal rules, this toolbar doesn't check-in any asset. The
 * buttons just call doneCommand and cancelCommand respectively.
 * @param editor/*www  .j  ava  2s  .  c  o  m*/
 * @return
 */
public MenuBar createMenuBar(final MultiViewEditor editor, EventBus eventBus) {
    MenuBar toolbar = new MenuBar();

    toolbar.addItem(Constants.INSTANCE.Done(), doneCommand);
    toolbar.addItem(Constants.INSTANCE.Cancel(), cancelCommand);

    return toolbar;
}