Example usage for com.google.gwt.user.client.ui Button Button

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

Introduction

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

Prototype

public Button() 

Source Link

Document

Creates a button with no caption.

Usage

From source file:asquare.gwt.tests.tabledom.client.Demo.java

License:Apache License

public void onModuleLoad() {
    m_textArea.setVisibleLines(20);// w w  w  . jav  a  2  s .c om
    m_textArea.setCharacterWidth(80);

    final Button button = new Button();
    DOM.setStyleAttribute(button.getElement(), "display", "block");
    button.setText("Execute");
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            Element tbody = DOM.createTBody();
            setInnerHtml(tbody, "", "setInnerHtml(tbody, \"\")");
            setInnerHtml(tbody, "", "setInnerHtml(tbody, \"\") again");
            Element table = DOM.createTable();
            DOM.appendChild(table, tbody);
            setInnerHtml(tbody, "", "setInnerHtml(table.tbody, \"\")");
            setInnerHtml(tbody, " ", "setInnerHtml(table.tbody, \" \")");
            setInnerHtml(tbody, "<tr></tr>", "setInnerHtml(table.tbody, \"<tr></tr>\")");
            setInnerHtml(tbody, "<tr><td></td></tr>", "setInnerHtml(table.tbody, \"<tr><td></td></tr>\")");
            DOM.appendChild(RootPanel.getBodyElement(), table);
            setInnerHtml(tbody, "", "setInnerHtml(body.table.tbody, \"\")");
            DOM.removeChild(table, tbody);
            setInnerHtml(tbody, "", "setInnerHtml(tbody, \"\")");

            Element td = DOM.createTD();
            setInnerHtml(td, "", "setInnerHtml(td, \"\")");
            Element tr = DOM.createTR();
            DOM.appendChild(tr, td);
            setInnerHtml(td, "", "setInnerHtml(tr.td, \"\")");
            tbody = DOM.createTBody();
            DOM.appendChild(tbody, tr);
            setInnerHtml(td, "", "setInnerHtml(tbody.tr.td, \"\")");
            table = DOM.createTable();
            DOM.appendChild(table, tbody);
            setInnerHtml(td, "", "setInnerHtml(table.tbody.tr.td, \"\")");
            setInnerHtml(tr, "", "setInnerHtml(table.tbody.tr, \"\")");
            setInnerHtml(tbody, "", "setInnerHtml(table.tbody, \"\")");
            setInnerHtml(table, "", "setInnerHtml(table, \"\")");

            setInnerHtml(DOM.createTable(), "", "setInnerHtml(new Table(), \"\")");

            tr = DOM.createTR();
            setInnerHtml(tr, "<td></td>", "setInnerHtml(tr, \"<td></td>\")");
        }
    });
    RootPanel.get().add(button);
    RootPanel.get().add(m_textArea);
}

From source file:asquare.gwt.tk.uitest.alertdialog.client.Demo.java

License:Apache License

public void onModuleLoad() {
    Debug.enable();//from   w w w .  ja v  a 2 s.co  m

    new DebugEventListener('x', Event.ONMOUSEDOWN, null) {
        @Override
        protected void doEvent(Event event) {
            Element target = DOM.eventGetTarget(event);
            Debug.println("target=" + DebugUtil.prettyPrintElement(target));
            int screenX = DOM.eventGetScreenX(event);
            int screenY = DOM.eventGetScreenY(event);
            int clientX = DOM.eventGetClientX(event);
            int clientY = DOM.eventGetClientY(event);
            int absLeft = DOM.getAbsoluteLeft(target);
            int absTop = DOM.getAbsoluteTop(target);
            int offsetLeft = getOffsetLeft(target);
            int offsetTop = getOffsetTop(target);
            int docScrollX = Window.getScrollLeft();
            int docScrollY = Window.getScrollTop();
            Debug.println("screenX=" + screenX + ",screenY=" + screenY + ",clientX=" + clientX + ",clientY="
                    + clientY + ",absLeft=" + absLeft + ",absTop=" + absTop + ",offsetLeft=" + offsetLeft
                    + ",offsetTop=" + offsetTop + ",docScrollX=" + docScrollX + ",docScrollY=" + docScrollY);
        }
    }.install();
    new DebugEventListener('z', Event.ONMOUSEDOWN, "Offset hierarchy inspector") {
        @Override
        protected void doEvent(Event event) {
            Element target = DOM.eventGetTarget(event);
            printOffsetTopHierarchy(target);
        }
    }.install();

    new DebugHierarchyInspector().install();

    new DebugElementDumpInspector().install();

    new DebugEventListener(Event.ONMOUSEDOWN | Event.ONMOUSEUP).install();

    if (!GWT.isScript()) {
        DebugConsole.getInstance().disable();
    }

    final Button button = new Button();
    button.setText("Default Info dialog");
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final AlertDialog alert = AlertDialog.createInfo(new Command() {
                public void execute() {
                    Debug.println("OK clicked");
                }
            }, "Info Dialog", "this is a default info dialog");
            alert.show();
        }
    });
    RootPanel.get().add(button);

    Command showDialog = new Command() {
        private AlertDialog m_dialog;

        public void execute() {
            if (m_dialog == null) {
                m_dialog = AlertDialog.createWarning(this, "Caption text", null);
                ScrollPanel message = new ScrollPanel();
                message.setAlwaysShowScrollBars(true);
                message.setWidth("100%");
                message.setHeight("100px");
                message.setWidget(new Label(
                        "These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work.These packages contain reference information about the main GWT user interface and utility classes. For higher-level explanations of how to take advantage of all this stuff, check out the Developer Guide. Among other things, there's a handy widget gallery and an explanation of how remote procedure calls work."));
                m_dialog.setMessage(message);
                m_dialog.setSize("400px", "300px");
                m_dialog.addController(new ControllerAdaptor(Controller.class, Event.ONMOUSEDOWN) {
                    @Override
                    public void onBrowserEvent(Widget widget, Event event) {
                        int x = DomUtil.eventGetAbsoluteX(event) - DOM.getAbsoluteLeft(widget.getElement());
                        int y = DomUtil.eventGetAbsoluteY(event) - DOM.getAbsoluteTop(widget.getElement());
                        Debug.println("onMouseDown(" + x + "," + y + ")");
                    }
                });
            }
            m_dialog.show();
        }
    };
    showDialog.execute();
}

From source file:bingo.client.Bingo.java

License:Open Source License

private void initAdminGrid(final String userId, final BingoGrid bingoGrid, final boolean hasFinished) {
    final Timer timer = new Timer() {
        int totalParticipants = 0;

        @Override//from w w w . ja  v  a2 s .c om
        public void run() {
            bingoService.getTotalParticipants(userId, new AsyncCallback<Integer>() {
                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(Integer result) {
                    totalParticipants = result.intValue();
                }
            });

            bingoService.getVotes(userId, new AsyncCallback<int[][]>() {
                @Override
                public void onFailure(Throwable caught) {
                    message.setText(caught.getMessage());
                }

                @Override
                public void onSuccess(int[][] result) {
                    if (result == null) {
                        result = new int[BingoGrid.ROW][BingoGrid.COL];
                        for (int i = 0; i < BingoGrid.ROW; i++)
                            for (int j = 0; j < BingoGrid.COL; j++)
                                result[i][j] = 0;
                    }

                    for (int row = 0; row < BingoGrid.ROW; ++row)
                        for (int col = 0; col < BingoGrid.COL; ++col) {
                            bingoGrid.setVoteString(row, col, String.valueOf(result[row][col]),
                                    String.valueOf(totalParticipants));
                        }
                }
            });
        }
    };

    // If the game is not finished, repeat; if so, run once
    if (!hasFinished)
        timer.scheduleRepeating(ADMIN_TIMER);
    else
        timer.run();

    HorizontalPanel panel = new HorizontalPanel();
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    final Button finishButton = new Button();

    // If the game is not finished, allow finishing it; if so, allow download data
    if (!hasFinished)
        finishButton.setText(strings.finishBingo());
    else
        finishButton.setText(strings.download());

    finishButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!hasFinished)
                bingoService.finishBingo(userId, new AsyncCallback<Void>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Void result) {
                        message.setText(strings.finishedBingo());
                        finishButton.setText(strings.download());
                        timer.cancel();
                    }
                });

            bingoService.getVotes(userId, new AsyncCallback<int[][]>() {
                @Override
                public void onFailure(Throwable caught) {
                    message.setText(caught.getMessage());
                }

                @Override
                public void onSuccess(int[][] result) {
                    // Create a popup dialog box
                    final DialogBox box = new DialogBox();
                    box.setText(strings.info());
                    box.setAnimationEnabled(true);

                    final Button boxAcceptButton = new Button(strings.accept());
                    boxAcceptButton.addClickHandler(new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            box.hide();
                        }
                    });

                    Label boxLabel = new Label();
                    boxLabel.setText(strings.finishMessage());
                    HTML voteData = new HTML();
                    if (result == null) {
                        result = new int[BingoGrid.ROW][BingoGrid.COL];
                        for (int i = 0; i < BingoGrid.ROW; i++)
                            for (int j = 0; j < BingoGrid.COL; j++)
                                result[i][j] = 0;
                    }

                    String cellKey = "";
                    String cellString = "";
                    String voteDataString = "";
                    for (int row = 0; row < BingoGrid.ROW; ++row)
                        for (int col = 0; col < BingoGrid.COL; ++col) {
                            cellKey = "cell" + row + col;
                            cellString = strings.map().get(cellKey);
                            voteDataString += "&nbsp;&nbsp;&nbsp;" + cellString + " = " + result[row][col]
                                    + "<br>";
                        }
                    voteData.setHTML(voteDataString);
                    voteData.addStyleName("boxData");

                    VerticalPanel boxPanel = new VerticalPanel();
                    boxPanel.addStyleName("boxPanel");
                    boxPanel.add(boxLabel);
                    boxPanel.add(voteData);

                    HorizontalPanel buttonsPanel = new HorizontalPanel();
                    buttonsPanel.add(boxAcceptButton);
                    boxPanel.add(buttonsPanel);
                    boxPanel.setCellHorizontalAlignment(buttonsPanel, HasHorizontalAlignment.ALIGN_CENTER);

                    box.setWidget(boxPanel);
                    box.center();
                }
            });
        }
    });
    panel.add(finishButton);

    final Button terminateButton = new Button(strings.terminateButton());
    terminateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // Create a popup dialog box
            final DialogBox box = new DialogBox();
            box.setText(strings.warning());
            box.setAnimationEnabled(true);

            final Button boxCancelButton = new Button(strings.cancel());
            boxCancelButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    box.hide();
                }
            });
            final Button boxAcceptButton = new Button(strings.accept());
            boxAcceptButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    bingoService.terminateBingo(userId, new AsyncCallback<Void>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            message.setText(caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            message.setText(strings.terminatedBingo());
                            timer.cancel();
                        }

                    });
                    box.hide();
                }
            });

            final Label boxLabel = new Label();
            boxLabel.setText(strings.terminateMessage());

            VerticalPanel boxPanel = new VerticalPanel();

            boxPanel.addStyleName("boxPanel");
            boxPanel.add(boxLabel);

            HorizontalPanel buttonsPanel = new HorizontalPanel();
            buttonsPanel.add(boxCancelButton);
            buttonsPanel.add(boxAcceptButton);
            boxPanel.add(buttonsPanel);

            box.setWidget(boxPanel);
            box.center();
        }
    });
    panel.add(terminateButton);

    RootPanel.get("buttons").clear();
    RootPanel.get("buttons").add(panel);
}

From source file:ca.ubc.ece.netsyslab.tagvalue.client.AuthenticationWidget.java

License:Open Source License

/**
 * Instantiates a new authorization widget.
 *
 * @param service a proxy to the backend service that guides the user.
 *///from  w  ww .java 2  s .  c  o m
public AuthenticationWidget() {
    username = "";
    password = "";
    usernameBox = new TextBox();
    usernameBox.setText("username");
    usernameBox.setTitle("Type your del.icio.us username in the box");
    usernameBox.setFocus(true);
    usernameBox.selectAll();
    usernameBox.addClickHandler(this);
    usernameBox.addKeyUpHandler(this);

    passwordBox = new PasswordTextBox();
    passwordBox.setText("password");
    passwordBox.setTitle("Type your del.icio.us password");
    passwordBox.addClickHandler(this);
    passwordBox.addKeyUpHandler(this);

    startButton = new Button();
    startButton.setText("Start");
    startButton.setTitle("Click here to give consent and start the experiment");
    startButton.addStyleName("sendButton");
    startButton.addClickHandler(this);

    setWidget(0, 0, usernameBox);
    setWidget(0, 1, passwordBox);
    setWidget(0, 2, startButton);
}

From source file:ca.ubc.ece.netsyslab.tagvalue.client.UsernameWidget.java

License:Open Source License

/**
 * Instantiates a new authorization widget.
 *
 * @param service a proxy to the backend service that guides the user.
 *//*from  ww w.jav a2s  . com*/
public UsernameWidget() {
    username = "";
    usernameBox = new TextBox();
    usernameBox.setText("username");
    usernameBox.setTitle("Type your del.icio.us username in the box");
    usernameBox.setFocus(true);
    usernameBox.selectAll();
    usernameBox.addClickHandler(this);
    usernameBox.addKeyUpHandler(this);

    startButton = new Button();
    startButton.setText("Start");
    startButton.setTitle("Click here to give consent and start the experiment");
    startButton.addStyleName("sendButton");
    startButton.addClickHandler(this);

    setWidget(0, 0, usernameBox);
    setWidget(0, 1, startButton);
}

From source file:cc.kune.common.client.actions.gwtui.AbstractGwtButtonGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    super.descriptor = descriptor;
    iconLabel = new IconLabel("");
    if (enableTongle) {
        button = new ToggleButton();
    } else {//from   w ww  .  jav a  2 s  . c  o m
        button = new Button();
    }
    final String value = (String) descriptor.getValue(Action.STYLES);
    if (value == null) {
        // Default btn styles
        button.addStyleName("k-button");
        button.addStyleName("k-btn");
        button.addStyleName("k-5corners");
    } else {
        setStyles(value);
    }
    layout();
    // button.setEnableToggle(enableTongle);
    final String id = descriptor.getId();
    if (id != null) {
        button.ensureDebugId(id);
    }
    isChild = descriptor.isChild();
    if (isChild) {
        // If button is inside a toolbar don't init...
        if (descriptor.isChild()) {
            child = button;
        }
    } else {
        initWidget(button);
    }
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            descriptor.fire(new ActionEvent(button, getTargetObjectOfAction(descriptor),
                    Event.as(event.getNativeEvent())));
        }
    });
    super.create(descriptor);
    configureItemFromProperties();
    return this;
}

From source file:cc.kune.common.client.actions.gwtui.GwtMenuGui.java

License:GNU Affero Public License

@Override
public AbstractGuiItem create(final GuiActionDescrip descriptor) {
    super.descriptor = descriptor;
    descriptor.putValue(ParentWidget.PARENT_UI, this);
    // Standalone menus are menus without and associated button in a toolbar
    // (sometimes, a menu showed in a grid, or other special widgets)
    notStandAlone = !((MenuDescriptor) descriptor).isStandalone();
    if (notStandAlone) {
        button = new Button();
        button.removeStyleName("gwt-Button");
        descriptor.putValue(MenuDescriptor.MENU_SHOW_NEAR_TO, button);
        iconLabel = new IconLabel("");
        final ImageResource rightIcon = ((MenuDescriptor) descriptor).getRightIcon();
        if (rightIcon != null) {
            iconLabel.setRightIconResource(rightIcon);
            // iconLabel.addRightIconStyle("k-fr");
        }/*from   w  ww.j a v a  2s.co  m*/
        button.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(final ClickEvent event) {
                if (button.isEnabled()) {
                    event.stopPropagation();
                    showRelativeTo(button);
                }
            }
        });
        final String id = descriptor.getId();
        if (id != null) {
            button.ensureDebugId(id);
        }
        if (!descriptor.isChild()) {
            initWidget(button);
        } else {
            child = button;
        }
    } else {
        initWidget(new Label());
    }
    super.create(descriptor);
    configureItemFromProperties();
    descriptor.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            final Object newValue = event.getNewValue();
            if (event.getPropertyName().equals(MenuDescriptor.MENU_RIGHTICON)) {
                setIconRightResource((ImageResource) newValue);
            }
        }
    });

    return this;
}

From source file:ch.heftix.mailxel.client.MailSendGrid.java

License:Open Source License

public MailSendGrid(final MailServiceAsync mailxelService, final MailxelPanel mailxelPanel, final MailTO mailTO,
        final char type) {

    this.mailxelService = mailxelService;
    this.mailxelPanel = mailxelPanel;

    cTO = mailxelPanel.getConfig();/*w ww .  j  av  a 2 s .com*/

    HorizontalPanel toolbar = new HorizontalPanel();

    final Image addAttachement = new Image("img/add-attachment.png");
    addAttachement.setTitle("Add Attachement");
    addAttachement.setStylePrimaryName("mailxel-toolbar-item");
    addAttachement.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            final PopupPanel pup = new PopupPanel(true);

            HorizontalPanel hp = new HorizontalPanel();

            final TextBox tb = new TextBox();
            tb.setWidth("300px");

            hp.add(tb);

            // final FileUpload upload = new FileUpload();
            // hp.add(upload);

            Button b = new Button();
            b.setText("Add");
            b.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent sender) {
                    // String name = upload.getFilename();
                    // // upload.g
                    String name = tb.getText();
                    if (null != name) {
                        name = name.trim();
                        if (name.length() > 0) {
                            AttachmentTO aTO = new AttachmentTO();
                            aTO.name = name;
                            attachmentBar.addCheckableAttachement(aTO);
                            pup.hide();
                        }
                    }
                }
            });

            hp.add(b);

            pup.add(hp);

            int x = addAttachement.getAbsoluteLeft();
            int y = addAttachement.getAbsoluteTop();

            pup.setPopupPosition(x, y);
            pup.show();
        }
    });

    final Image setFrom = new Image("img/set-from.png");
    setFrom.setTitle("Set From address");
    setFrom.setStylePrimaryName("mailxel-toolbar-item");
    setFrom.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            grid.insertRow(0);
            grid.setText(0, 0, "From");
            MailSendGrid.this.fromBar = new AddressEditBar(mailxelService, mailxelPanel);
            grid.setWidget(0, 1, fromBar);
        }
    });

    Image postpone = new Image("img/save.png");
    postpone.setTitle("Postpone Message");
    postpone.setStylePrimaryName("mailxel-toolbar-item");
    postpone.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            final StatusItem si = mailxelPanel.statusStart("postpone");

            MailTO mt = createMail();

            mailxelService.postpone(mt, new AsyncCallback<String>() {

                public void onFailure(Throwable caught) {
                    si.error(caught);
                }

                public void onSuccess(String result) {
                    if (null != result && result.startsWith("200 OK")) {
                        si.done();
                        mailxelPanel.closeTab(MailSendGrid.this);
                    } else {
                        si.error("Postpone failed: " + result);
                    }
                }
            });
        }
    });

    Image send = new Image("img/paper-plane.png");
    if (TYPE_SELF == type) {
        send.setTitle("Store Note");
    } else {
        send.setTitle("Send Mail");
    }
    send.setStylePrimaryName("mailxel-toolbar-item");
    send.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            final StatusItem si = mailxelPanel.statusStart("send/store");
            if (sending) {
                si.error("mail send is already in process");
                return;
            } else {
                sending = true;
            }

            MailTO mt = createMail();

            if (TYPE_SELF == type) {
                mailxelService.storeNote(mt, new AsyncCallback<String>() {

                    public void onFailure(Throwable caught) {
                        si.error(caught);
                        sending = false;
                    }

                    public void onSuccess(String result) {
                        if (null != result && result.startsWith("200 OK")) {
                            si.done();
                            sending = false;
                            mailxelPanel.closeTab(MailSendGrid.this);
                        } else {
                            si.error("Storing note failed: " + result);
                            sending = false;
                        }
                    }

                });

            } else {

                mailxelService.send(mt, new AsyncCallback<String>() {

                    public void onFailure(Throwable caught) {
                        si.error(caught);
                        sending = false;
                    }

                    public void onSuccess(String status) {
                        if (status.startsWith("200")) {
                            si.done();
                            sending = false;
                            if (TYPE_NEW != type) {
                                // add a category entry: answered or forwarded
                                String cat = "ANS";
                                if (TYPE_FORWARD == type) {
                                    cat = "FWD";
                                }
                                List<Integer> origMailId = new ArrayList<Integer>();
                                origMailId.add(mailTO.id);
                                final StatusItem sic = mailxelPanel.statusStart("update send/answer flags");
                                mailxelService.updateCategories(origMailId, cat, new AsyncCallback<Void>() {

                                    public void onFailure(Throwable caught) {
                                        sic.error(caught);
                                    }

                                    public void onSuccess(Void result) {
                                        sic.done("sent and flags updated", 0);
                                    }
                                });
                            }
                            // close tab
                            mailxelPanel.closeTab(MailSendGrid.this);
                        } else {
                            si.error(status);
                            sending = false;
                        }
                    }
                });

            }
        }
    });

    if (TYPE_SELF != type) {
        toolbar.add(setFrom);
        toolbar.add(postpone);
    }
    toolbar.add(addAttachement);
    toolbar.add(send);

    add(toolbar);
    add(statusMessage);

    initWidgets(mailTO, type);

}

From source file:ch.heftix.mailxel.client.MailxelMainToolBar.java

License:Open Source License

public MailxelMainToolBar(final MailServiceAsync mailxelService, final MailxelPanel mailxelPanel) {

    this.mailxelService = mailxelService;
    this.mailxelPanel = mailxelPanel;

    logo = new Image("img/mailxel.png");
    logo.setTitle("MailXel " + Version.getVersion());
    logo.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {
            PopupPanel pp = new PopupPanel(true);
            DisclosurePanel dp = new DisclosurePanel("MailXel " + Version.getVersion());
            dp.setWidth("400px");
            dp.setOpen(true);/*from www .  j a  va 2s.  c  om*/

            HTML html = new HTML();
            StringBuffer sb = new StringBuffer();
            sb.append("(c) 2008-2010 by Simon Hefti. All rights reserved.<br/>");
            sb.append(
                    "<p>mailxel is licensed under the <a href=\"http://www.eclipse.org/legal/epl-v10.html\">EPL 1.0</a>. mailxel is distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.");
            sb.append("<p>mailxel relies on the following components:");
            sb.append("<ul>");
            sb.append(
                    "<li>GWT, <a href=\"http://code.google.com/webtoolkit\">http://code.google.com/webtoolkit</a></li>");
            sb.append(
                    "<li>sqlite-jdbc, <a href=\"http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC\">http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC</a></li>");
            sb.append(
                    "<li>(and thus on sqlite itself, <a href=\"http://www.sqlite.org\">http://www.sqlite.org</a>)</li>");
            sb.append(
                    "<li>Java Mail API, <a href=\"http://java.sun.com/products/javamail\">http://java.sun.com/products/javamail</a></li>");
            sb.append(
                    "<li>jetty servlet container, <a href=\"http://www.eclipse.org/jetty/\">http://www.eclipse.org/jetty/</a></li>");
            sb.append(
                    "<li>fugue-icons, <a href=\"http://code.google.com/p/fugue-icons-src/\">http://code.google.com/p/fugue-icons-src/</a></li>");
            sb.append("<li>jsoup, <a href=\"http://jsoup.org\">http://jsoup.org</a></li>");
            sb.append("</ul>");
            html.setHTML(sb.toString());
            dp.add(html);
            dp.setOpen(true);

            pp.add(dp);
            pp.show();
        }
    });

    Image home = new Image("img/find.png");
    home.setTitle("Search");
    home.setStylePrimaryName("mailxel-toolbar-item");
    home.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            Panel panel = new MailOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(panel, "Search");
        }
    });

    final Image query = new Image("img/document-task.png");
    query.setTitle("Search (predefined query)");
    query.setStylePrimaryName("mailxel-toolbar-item");
    query.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            final StatusItem si = mailxelPanel.statusStart("retrieve stored message queries");

            mailxelService.searchQueries(MessageQueryTO.T_MESSAGE_QUERY, null,
                    new AsyncCallback<List<MessageQueryTO>>() {

                        public void onFailure(Throwable caught) {
                            si.error(caught);
                        }

                        public void onSuccess(List<MessageQueryTO> result) {
                            si.done();
                            if (null != result && result.size() > 0) {
                                PopupMenu popupMenu = new PopupMenu(query);
                                for (MessageQueryTO mqTO : result) {
                                    String name = mqTO.shortname + " (" + UIUtil.shorten(mqTO.name) + ")";
                                    MenuItem menuItem = new MenuItem(name, new MessageQueryCommand(
                                            mailxelService, mailxelPanel, popupMenu, mqTO));
                                    String url = DirectMailServiceUtil.getIconURL(mqTO.iconId);
                                    if (null != url) {
                                        String html = "<img src=\"" + url + "\"/>&nbsp;" + name;
                                        menuItem.setHTML(html);
                                    }
                                    popupMenu.addItem(menuItem);
                                }
                                popupMenu.show();
                            }
                        }
                    });
        }
    });

    Image mailnew = new Image("img/mail-new.png");
    mailnew.setTitle("New Mail");
    mailnew.setStylePrimaryName("mailxel-toolbar-item");
    mailnew.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {
            final MailSendGrid mailSendGrid = new MailSendGrid(mailxelService, mailxelPanel, null,
                    MailSendGrid.TYPE_NEW);
            mailxelPanel.addTab(mailSendGrid, "New Mail");
        }
    });

    Image noteToSelf = new Image("img/note.png");
    noteToSelf.setTitle("Note to myself");
    noteToSelf.setStylePrimaryName("mailxel-toolbar-item");
    noteToSelf.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {
            final MailSendGrid mailSendGrid = new MailSendGrid(mailxelService, mailxelPanel, null,
                    MailSendGrid.TYPE_SELF);
            mailxelPanel.addTab(mailSendGrid, "New Note");
        }
    });

    Image contacts = new Image("img/address-book.png");
    contacts.setTitle("Address Book");
    contacts.setStylePrimaryName("mailxel-toolbar-item");
    contacts.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {
            AddressOverviewGrid ag = new AddressOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(ag, "Contacts");
        }
    });

    /**
     * mail download menu on click, a menu with the available accounts is
     * displayed, allowing the user is asked to choose the data source.
     */
    final Image download = new Image("img/download-mail.png");
    download.setTitle("Mail download");
    download.setStylePrimaryName("mailxel-toolbar-item");
    download.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            ConfigTO configTO = mailxelPanel.getConfig();
            String[] accounts = configTO.accountNames;

            if (null != accounts && accounts.length > 0) {

                PopupMenu popupMenu = new PopupMenu(download);
                // first item: allow download from all known accounts
                MenuItem menuItem = new MenuItem("Scan all accounts",
                        new ScanMailFolderCommand(mailxelService, mailxelPanel, popupMenu, accounts));
                popupMenu.addItem(menuItem);

                // add one menu item per account
                for (int i = 0; i < accounts.length; i++) {
                    String[] selectedAccount = new String[1];
                    selectedAccount[0] = accounts[i];
                    menuItem = new MenuItem(accounts[i], new ScanMailFolderCommand(mailxelService, mailxelPanel,
                            popupMenu, selectedAccount));
                    popupMenu.addItem(menuItem);
                }
                popupMenu.show();
            }
        }
    });

    final Image reorgMailFolder = new Image("img/wand.png");
    reorgMailFolder.setTitle("reorganize mail folder");
    reorgMailFolder.setStylePrimaryName("mailxel-toolbar-item");
    reorgMailFolder.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            ConfigTO configTO = mailxelPanel.getConfig();
            String[] accounts = configTO.accountNames;

            if (null != accounts && accounts.length > 0) {

                PopupMenu popupMenu = new PopupMenu(reorgMailFolder);
                // first item: allow reorg from all known accounts
                MenuItem menuItem = new MenuItem("All accounts", new ReorgMailFolderCommand(mailxelService,
                        mailxelPanel, popupMenu, reorgMailFolder, accounts));
                popupMenu.addItem(menuItem);

                // add one menu item per account
                for (int i = 0; i < accounts.length; i++) {
                    String[] selectedAccount = new String[1];
                    selectedAccount[0] = accounts[i];
                    menuItem = new MenuItem(accounts[i], new ReorgMailFolderCommand(mailxelService,
                            mailxelPanel, popupMenu, reorgMailFolder, selectedAccount));
                    popupMenu.addItem(menuItem);
                }
                popupMenu.show();
            }
        }
    });

    final Image categories = new Image("img/tags.png");
    categories.setTitle("Manage Categories");
    categories.setStylePrimaryName("mailxel-toolbar-item");
    categories.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {
            CategoryOverviewGrid cog = new CategoryOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(cog, "Categories");
        }
    });

    final Image setup = new Image("img/preferences-system.png");
    setup.setTitle("System Setup");
    setup.setStylePrimaryName("mailxel-toolbar-item");
    setup.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // ConfigTabPanel cg = new ConfigTabPanel();
            ConfigGrid cg = new ConfigGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(cg, "Setup");
        }
    });

    final Image login = new Image("img/lock.png");
    login.setTitle("Login");
    login.setStylePrimaryName("mailxel-toolbar-item");
    login.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            // create login box
            LoginPanel loginPanel = new LoginPanel(mailxelService, mailxelPanel);
            int x = login.getAbsoluteLeft();
            int y = login.getAbsoluteTop();
            loginPanel.setPopupPosition(x, y);
            loginPanel.show();
        }
    });

    final Image additional = new Image("img/context-menu.png");
    additional.setTitle("Additional functions");
    additional.setStylePrimaryName("mailxel-toolbar-item");

    final PopupCommand importMboxCommand = new PopupCommand() {

        public void execute() {

            final PopupPanel pup = new PopupPanel(true);
            HorizontalPanel hp = new HorizontalPanel();
            final TextBox tb = new TextBox();
            tb.setWidth("300px");
            hp.add(tb);

            Button b = new Button();
            b.setText("import");
            b.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent sender) {
                    String name = tb.getText();
                    if (null != name) {
                        name = name.trim();
                        if (name.length() > 0) {
                            final StatusItem si = mailxelPanel.statusStart("Import from mbox: " + name);
                            mailxelService.importMboxFile(name, new AsyncCallback<Void>() {

                                public void onFailure(Throwable caught) {
                                    si.error(caught);
                                }

                                public void onSuccess(Void result) {
                                    si.done();
                                }
                            });
                            pup.hide();
                        }
                    }
                }
            });

            hp.add(b);
            pup.add(hp);

            int x = additional.getAbsoluteLeft();
            int y = additional.getAbsoluteTop();
            pup.setPopupPosition(x, y);
            /** show input box for path to mbox file */
            pup.show();
            /** hide the list of available additional commands */
            hide();
        }
    };

    final PopupCommand addressUploadCommand = new PopupCommand() {

        public void execute() {
            AddressUploadGrid ug = new AddressUploadGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(ug, "Address Upload");
            /** hide the list of available additional commands */
            hide();
        }
    };

    final Command showWelcomePanelCommand = new Command() {

        public void execute() {
            WelcomeToMailxelPanel wp = new WelcomeToMailxelPanel(mailxelService, mailxelPanel);
            mailxelPanel.addTab(wp, "Welcome");
        }
    };

    final PopupCommand deleteConfigCommand = new PopupCommand() {

        public void execute() {

            PopupPanel pop = new PopupPanel(true, true);
            HorizontalPanel hp = new HorizontalPanel();
            Label label = new Label("Really delete all configuration?");
            hp.add(label);
            Button b = new Button();
            b.setText("Ok");
            b.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    final StatusItem si = mailxelPanel.statusStart("deleting configuration");
                    mailxelService.deleteConfig(new AsyncCallback<Void>() {

                        public void onFailure(Throwable caught) {
                            si.error(caught);
                        }

                        public void onSuccess(Void result) {
                            si.done();
                        }
                    });
                }
            });
            hp.add(b);
            pop.add(hp);

            int x = additional.getAbsoluteLeft();
            int y = additional.getAbsoluteTop();
            pop.setPopupPosition(x, y);
            pop.show();
            /** hide the list of available additional commands */
            hide();
        }
    };

    final Command updateToMeFlagCommand = new Command() {

        public void execute() {
            final StatusItem si = mailxelPanel.statusStart("Update 'to me' flag");
            mailxelService.updateToMeFlag(new AsyncCallback<Void>() {

                public void onFailure(Throwable caught) {
                    si.error(caught);
                }

                public void onSuccess(Void result) {
                    si.done();
                }
            });
        }
    };

    final Command updateFromMeFlagCommand = new Command() {

        public void execute() {
            final StatusItem si = mailxelPanel.statusStart("Update 'from me' flag");
            mailxelService.updateFromMeFlag(new AsyncCallback<Void>() {

                public void onFailure(Throwable caught) {
                    si.error(caught);
                }

                public void onSuccess(Void result) {
                    si.done();
                }
            });
        }
    };

    final Command showStatisticsCommand = new Command() {

        public void execute() {
            StatisticsGrid sg = new StatisticsGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(sg, "Statistics");
        }
    };

    final Command showIconsCommand = new Command() {

        public void execute() {
            IconOverviewGrid og = new IconOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(og, "Icons");
        }
    };

    final Command showMessageQueriesCommand = new Command() {

        public void execute() {
            MessageQueryOverviewGrid mqog = new MessageQueryOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(mqog, "Message Queries");
        }
    };

    final Command showAttachmentGridCommand = new Command() {

        public void execute() {
            AttachmentOverviewGrid aog = new AttachmentOverviewGrid(mailxelService, mailxelPanel);
            mailxelPanel.addTab(aog, "Attachment Overview");
        }
    };

    final Command closeAllTabsCommand = new Command() {

        public void execute() {
            mailxelPanel.closeAllNonEditTabs();
        }
    };

    final Command dbHousekeeping = new Command() {

        public void execute() {
            final StatusItem si = mailxelPanel.statusStart("DB housekeeping");
            mailxelService.housekeeping(new AsyncCallback<String>() {

                public void onFailure(Throwable caught) {
                    si.error(caught);
                }

                public void onSuccess(String result) {
                    if (result.startsWith("200 OK")) {
                        si.done();
                    } else {
                        si.error(result);
                    }
                }
            });
        }
    };

    final Command messageCount = new Command() {

        public void execute() {
            updateCounts();
        }
    };

    additional.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent sender) {

            MenuBar popupMenuBar = new MenuBar(true);
            PopupPanel popupPanel = new PopupPanel(true);

            MenuItem menuItem = new MenuItem("Attachment Overview", showAttachmentGridCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Close all Tabs", closeAllTabsCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Message Queries", showMessageQueriesCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("DB Housekeeping", dbHousekeeping);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("update pending messages count", messageCount);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Statistics", showStatisticsCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Icons", showIconsCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Import mbox file", importMboxCommand);
            importMboxCommand.setPopupPanel(popupPanel);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Address upload", addressUploadCommand);
            addressUploadCommand.setPopupPanel(popupPanel);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Welcome", showWelcomePanelCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Delete existing configuration", deleteConfigCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Update 'from me' flag", updateFromMeFlagCommand);
            popupMenuBar.addItem(menuItem);

            menuItem = new MenuItem("Update 'to me' flag", updateToMeFlagCommand);
            popupMenuBar.addItem(menuItem);

            popupMenuBar.setVisible(true);
            popupPanel.add(popupMenuBar);

            int x = additional.getAbsoluteLeft();
            int y = additional.getAbsoluteTop();

            popupPanel.setPopupPosition(x, y);
            popupPanel.show();
        }
    });

    updateCounts();

    add(home);
    add(query);
    add(mailnew);
    add(noteToSelf);
    add(contacts);
    add(categories);
    add(download);
    add(reorgMailFolder);
    add(setup);
    add(login);
    add(additional);
    add(logo);
    add(msgCountAct);
}

From source file:ch.heftix.mailxel.client.WelcomeToMailxelPanel.java

License:Open Source License

public WelcomeToMailxelPanel(final MailServiceAsync mailxelService, final MailxelPanel mailxelPanel) {

    StringBuffer sb = new StringBuffer(512);
    sb.append("<div style=\"welcome\"><p><b>Welcome and Thank You</b> for choosing mailxel");
    sb.append("<p>This seems to be the first time you start mailxel (*).");
    sb.append("<p>For a quick start, use the configuration form below.");
    sb.append("<p>Note: you can always edit your settings using the preferences");
    sb.append("<img src=\"img/preferences-system.png\"/> function of the menu");

    HTML html = new HTML(sb.toString());
    add(html);//from   ww w.  ja  va  2 s  .  c o  m

    FlexTable grid = new FlexTable();
    int idx = IDX_mail;
    grid.setText(idx, 0, "your main e-mail address");
    boxes[idx] = new TextBox();
    boxes[idx].setWidth("200px");
    boxes[idx].setText("example: some.body@somewhere.com");
    grid.setWidget(idx, 1, boxes[idx]);

    idx = IDX_data;
    grid.setText(idx, 0, "mailxel data directory");
    boxes[idx] = new TextBox();
    boxes[idx].setWidth("200px");
    boxes[idx].setText("example: d:/data/mailxel");
    grid.setWidget(idx, 1, boxes[idx]);

    idx = IDX_smtp;
    grid.setText(idx, 0, "your SMTP host");
    boxes[idx] = new TextBox();
    boxes[idx].setWidth("200px");
    boxes[idx].setText("example: smtp.somewhere.com");
    grid.setWidget(idx, 1, boxes[idx]);

    idx = IDX_imap;
    grid.setText(idx, 0, "your IMAP host");
    boxes[idx] = new TextBox();
    boxes[idx].setWidth("200px");
    boxes[idx].setText("example: imap.somewhere.com");
    grid.setWidget(idx, 1, boxes[idx]);

    add(grid);

    Button b = new Button();
    add(b);
    b.setText("Store and Start");
    b.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            AccountConfigTO aTO = new AccountConfigTO();
            String[] sf = { "inbox", "sent" };
            String[] ef = { "trash" };

            aTO.name = "main";
            aTO.protocol = "imap";
            aTO.isSSL = false;
            aTO.port = "143";
            aTO.user = boxes[IDX_mail].getText();
            aTO.server = boxes[IDX_imap].getText();
            aTO.scannedfolders = sf;
            aTO.excludedfolders = ef;
            aTO.reuseSendPassword = false;
            aTO.reorgRules = new String[0];

            String[] accountNames = { "main" };
            AccountConfigTO[] aTOs = new AccountConfigTO[1];
            aTOs[0] = aTO;

            final ConfigTO cTO = new ConfigTO();

            cTO.localstore = boxes[IDX_data].getText();
            cTO.smtpHost = boxes[IDX_smtp].getText();
            cTO.smtpPort = "25";
            cTO.smtpUser = "";
            cTO.smtpPassword = "";

            cTO.sentHandlingBCC = false;
            cTO.sentHandlingStoreLocally = true;
            cTO.sentHandlingCopySent = true;
            cTO.sentHandlingCopyAccountName = "main";
            cTO.sentHandlingCopyFolderName = "sent";

            cTO.logConfiguration = LOGConstants.PRODUCTION;
            cTO.maxSearchRows = 30;
            cTO.maxAddressSuggestions = 10;

            cTO.me = boxes[IDX_mail].getText();

            cTO.accountNames = accountNames;
            cTO.accounts = aTOs;

            final StatusItem si = mailxelPanel.statusStart("saving welcome configuration");
            mailxelService.saveConfig(cTO, new AsyncCallback<Void>() {

                public void onSuccess(Void result) {
                    si.done();
                    mailxelPanel.setConfig(cTO);
                    ConfigGrid cg = new ConfigGrid(mailxelService, mailxelPanel);
                    mailxelPanel.addTab(cg, "Settings");
                    mailxelPanel.closeTab(WelcomeToMailxelPanel.this);
                }

                public void onFailure(Throwable caught) {
                    si.error(caught);
                }
            });
        }
    });

    sb = new StringBuffer(512);
    sb.append("<p style=\"footnote\">(*) If this is not the case: please ");
    sb.append("<a href=\"http://code.google.com/p/mailxel/issues/entry\">");
    sb.append("report an error</a>.");

    html = new HTML(sb.toString());
    add(html);

}