Search in sources :

Example 1 with AutoCenterDialogBox

use of com.google.gwtexpui.user.client.AutoCenterDialogBox in project gerrit by GerritCodeReview.

the class ContactPanelShort method doRegisterNewEmail.

private void doRegisterNewEmail() {
    if (!canRegisterNewEmail()) {
        return;
    }
    final AutoCenterDialogBox box = new AutoCenterDialogBox(true, true);
    final VerticalPanel body = new VerticalPanel();
    final NpTextBox inEmail = new NpTextBox();
    inEmail.setVisibleLength(60);
    final Button register = new Button(Util.C.buttonSendRegisterNewEmail());
    final Button cancel = new Button(Util.C.buttonCancel());
    final FormPanel form = new FormPanel();
    form.addSubmitHandler(new FormPanel.SubmitHandler() {

        @Override
        public void onSubmit(final SubmitEvent event) {
            event.cancel();
            final String addr = inEmail.getText().trim();
            if (!addr.contains("@")) {
                new ErrorDialog(Util.C.invalidUserEmail()).center();
                return;
            }
            inEmail.setEnabled(false);
            register.setEnabled(false);
            AccountApi.registerEmail("self", addr, new GerritCallback<EmailInfo>() {

                @Override
                public void onSuccess(EmailInfo result) {
                    box.hide();
                    if (Gerrit.info().auth().isDev()) {
                        currentEmail = addr;
                        if (emailPick.getItemCount() == 0) {
                            AccountInfo me = Gerrit.getUserAccount();
                            me.email(addr);
                            onSaveSuccess(me);
                        } else {
                            save.setEnabled(true);
                        }
                        updateEmailList();
                    }
                }

                @Override
                public void onFailure(final Throwable caught) {
                    inEmail.setEnabled(true);
                    register.setEnabled(true);
                    if (caught.getMessage().startsWith(EmailException.MESSAGE)) {
                        final ErrorDialog d = new ErrorDialog(caught.getMessage().substring(EmailException.MESSAGE.length()));
                        d.setText(Util.C.errorDialogTitleRegisterNewEmail());
                        d.center();
                    } else {
                        super.onFailure(caught);
                    }
                }
            });
        }
    });
    form.setWidget(body);
    register.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            form.submit();
        }
    });
    cancel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            box.hide();
        }
    });
    final FlowPanel buttons = new FlowPanel();
    buttons.setStyleName(Gerrit.RESOURCES.css().patchSetActions());
    buttons.add(register);
    buttons.add(cancel);
    if (!Gerrit.info().auth().isDev()) {
        body.add(new HTML(Util.C.descRegisterNewEmail()));
    }
    body.add(inEmail);
    body.add(buttons);
    box.setText(Util.C.titleRegisterNewEmail());
    box.setWidget(form);
    box.center();
    inEmail.setFocus(true);
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ErrorDialog(com.google.gerrit.client.ErrorDialog) HTML(com.google.gwt.user.client.ui.HTML) NativeString(com.google.gerrit.client.rpc.NativeString) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) AutoCenterDialogBox(com.google.gwtexpui.user.client.AutoCenterDialogBox) FormPanel(com.google.gwt.user.client.ui.FormPanel) Button(com.google.gwt.user.client.ui.Button) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Aggregations

ErrorDialog (com.google.gerrit.client.ErrorDialog)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Button (com.google.gwt.user.client.ui.Button)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 FormPanel (com.google.gwt.user.client.ui.FormPanel)1 SubmitEvent (com.google.gwt.user.client.ui.FormPanel.SubmitEvent)1 HTML (com.google.gwt.user.client.ui.HTML)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 NpTextBox (com.google.gwtexpui.globalkey.client.NpTextBox)1 AutoCenterDialogBox (com.google.gwtexpui.user.client.AutoCenterDialogBox)1