Search in sources :

Example 16 with GerritCallback

use of com.google.gerrit.client.rpc.GerritCallback 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)

Example 17 with GerritCallback

use of com.google.gerrit.client.rpc.GerritCallback in project gerrit by GerritCodeReview.

the class MyGpgKeysScreen method refreshKeys.

private void refreshKeys() {
    AccountApi.self().view("gpgkeys").get(NativeMap.copyKeysIntoChildren("id", new GerritCallback<NativeMap<GpgKeyInfo>>() {

        @Override
        public void onSuccess(NativeMap<GpgKeyInfo> result) {
            List<GpgKeyInfo> list = Natives.asList(result.values());
            // TODO(dborowitz): Sort on something more meaningful, like
            // created date?
            Collections.sort(list, new Comparator<GpgKeyInfo>() {

                @Override
                public int compare(GpgKeyInfo a, GpgKeyInfo b) {
                    return a.id().compareTo(b.id());
                }
            });
            keys.clear();
            keyText.setText("");
            errorPanel.setVisible(false);
            addButton.setEnabled(true);
            if (!list.isEmpty()) {
                keys.setVisible(true);
                for (GpgKeyInfo k : list) {
                    keys.addOneKey(k);
                }
                showKeyTable(true);
                showAddKeyBlock(false);
            } else {
                keys.setVisible(false);
                showAddKeyBlock(true);
                showKeyTable(false);
            }
            display();
        }
    }));
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) NativeMap(com.google.gerrit.client.rpc.NativeMap) GpgKeyInfo(com.google.gerrit.client.info.GpgKeyInfo)

Example 18 with GerritCallback

use of com.google.gerrit.client.rpc.GerritCallback in project gerrit by GerritCodeReview.

the class MyWatchesTable method addNotifyButton.

protected void addNotifyButton(final ProjectWatchInfo.Type type, final ProjectWatchInfo info, final int row, final int col) {
    final CheckBox cbox = new CheckBox();
    cbox.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            final Boolean oldVal = info.notify(type);
            info.notify(type, cbox.getValue());
            cbox.setEnabled(false);
            AccountApi.updateWatchedProject("self", info, new GerritCallback<JsArray<ProjectWatchInfo>>() {

                @Override
                public void onSuccess(JsArray<ProjectWatchInfo> watchedProjects) {
                    cbox.setEnabled(true);
                }

                @Override
                public void onFailure(Throwable caught) {
                    cbox.setEnabled(true);
                    info.notify(type, oldVal);
                    cbox.setValue(oldVal);
                    super.onFailure(caught);
                }
            });
        }
    });
    cbox.setValue(info.notify(type));
    table.setWidget(row, col, cbox);
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JsArray(com.google.gwt.core.client.JsArray) CheckBox(com.google.gwt.user.client.ui.CheckBox) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 19 with GerritCallback

use of com.google.gerrit.client.rpc.GerritCallback in project gerrit by GerritCodeReview.

the class ChangeScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    CallbackGroup group = new CallbackGroup();
    if (Gerrit.isSignedIn()) {
        ChangeList.query("change:" + changeId.get() + " has:draft", Collections.<ListChangesOption>emptySet(), group.add(new AsyncCallback<ChangeList>() {

            @Override
            public void onSuccess(ChangeList result) {
                hasDraftComments = result.length() > 0;
            }

            @Override
            public void onFailure(Throwable caught) {
            }
        }));
        ChangeApi.editWithFiles(changeId.get(), group.add(new AsyncCallback<EditInfo>() {

            @Override
            public void onSuccess(EditInfo result) {
                edit = result;
            }

            @Override
            public void onFailure(Throwable caught) {
            }
        }));
    }
    loadChangeInfo(true, group.addFinal(new GerritCallback<ChangeInfo>() {

        @Override
        public void onSuccess(final ChangeInfo info) {
            info.init();
            initCurrentRevision(info);
            final RevisionInfo rev = info.revision(revision);
            CallbackGroup group = new CallbackGroup();
            loadCommit(rev, group);
            group.addListener(new GerritCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    if (base.isBase() && rev.isMerge()) {
                        base = DiffObject.parse(info.legacyId(), Gerrit.getUserPreferences().defaultBaseForMerges().getBase());
                    }
                    loadConfigInfo(info, base);
                    JsArray<MessageInfo> mAr = info.messages();
                    for (int i = 0; i < mAr.length(); i++) {
                        if (mAr.get(i).tag() != null) {
                            hideTaggedComments.setVisible(true);
                            break;
                        }
                    }
                }
            });
            group.done();
        }
    }));
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) JsArray(com.google.gwt.core.client.JsArray) ChangeInfo(com.google.gerrit.client.info.ChangeInfo) RevisionInfo(com.google.gerrit.client.info.ChangeInfo.RevisionInfo) ChangeList(com.google.gerrit.client.changes.ChangeList) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) EditInfo(com.google.gerrit.client.info.ChangeInfo.EditInfo)

Example 20 with GerritCallback

use of com.google.gerrit.client.rpc.GerritCallback in project gerrit by GerritCodeReview.

the class ProjectInfoScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    Project.NameKey project = getProjectKey();
    CallbackGroup cbg = new CallbackGroup();
    AccessMap.get(project, cbg.add(new GerritCallback<ProjectAccessInfo>() {

        @Override
        public void onSuccess(ProjectAccessInfo result) {
            isOwner = result.isOwner();
            configVisible = result.configVisible();
            enableForm();
            saveProject.setVisible(isOwner);
        }
    }));
    ProjectApi.getConfig(project, cbg.addFinal(new ScreenLoadCallback<ConfigInfo>(this) {

        @Override
        public void preDisplay(ConfigInfo result) {
            display(result);
        }
    }));
    savedPanel = INFO;
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) ProjectAccessInfo(com.google.gerrit.client.access.ProjectAccessInfo) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) ScreenLoadCallback(com.google.gerrit.client.rpc.ScreenLoadCallback) ConfigInfo(com.google.gerrit.client.projects.ConfigInfo)

Aggregations

GerritCallback (com.google.gerrit.client.rpc.GerritCallback)25 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)8 ChangeInfo (com.google.gerrit.client.info.ChangeInfo)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 Button (com.google.gwt.user.client.ui.Button)5 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)5 JsArray (com.google.gwt.core.client.JsArray)4 VoidResult (com.google.gerrit.client.VoidResult)3 NativeString (com.google.gerrit.client.rpc.NativeString)3 SmallHeading (com.google.gerrit.client.ui.SmallHeading)3 PopupPanel (com.google.gwt.user.client.ui.PopupPanel)3 ChangeScreen (com.google.gerrit.client.change.ChangeScreen)2 ProjectDashboardScreen (com.google.gerrit.client.changes.ProjectDashboardScreen)2 AccountInfo (com.google.gerrit.client.info.AccountInfo)2 GroupInfo (com.google.gerrit.client.info.GroupInfo)2 NpTextBox (com.google.gwtexpui.globalkey.client.NpTextBox)2 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 ProjectAccessInfo (com.google.gerrit.client.access.ProjectAccessInfo)1 EditPreferences (com.google.gerrit.client.account.EditPreferences)1