Search in sources :

Example 6 with ErrorDialog

use of com.google.gerrit.client.ErrorDialog in project gerrit by GerritCodeReview.

the class GerritCallback method showFailure.

public static void showFailure(Throwable caught) {
    if (isSigninFailure(caught)) {
        new NotSignedInDialog().center();
    } else if (isNoSuchEntity(caught)) {
        new ErrorDialog(Gerrit.C.notFoundBody()).center();
    } else if (isNoSuchAccount(caught)) {
        final String msg = caught.getMessage();
        final String who = msg.substring(NoSuchAccountException.MESSAGE.length());
        final ErrorDialog d = new ErrorDialog(Gerrit.M.noSuchAccountMessage(who));
        d.setText(Gerrit.C.noSuchAccountTitle());
        d.center();
    } else if (isNameAlreadyUsed(caught)) {
        final String msg = caught.getMessage();
        final String alreadyUsedName = msg.substring(NameAlreadyUsedException.MESSAGE.length());
        new ErrorDialog(Gerrit.M.nameAlreadyUsedBody(alreadyUsedName)).center();
    } else if (isNoSuchGroup(caught)) {
        final String msg = caught.getMessage();
        final String group = msg.substring(NoSuchGroupException.MESSAGE.length());
        final ErrorDialog d = new ErrorDialog(Gerrit.M.noSuchGroupMessage(group));
        d.setText(Gerrit.C.noSuchGroupTitle());
        d.center();
    } else if (caught instanceof ServerUnavailableException) {
        new ErrorDialog(RpcConstants.C.errorServerUnavailable()).center();
    } else {
        new ErrorDialog(caught).center();
    }
}
Also used : NotSignedInDialog(com.google.gerrit.client.NotSignedInDialog) ServerUnavailableException(com.google.gwtjsonrpc.client.ServerUnavailableException) ErrorDialog(com.google.gerrit.client.ErrorDialog)

Example 7 with ErrorDialog

use of com.google.gerrit.client.ErrorDialog 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 8 with ErrorDialog

use of com.google.gerrit.client.ErrorDialog in project gerrit by GerritCodeReview.

the class NewAgreementScreen method showCLA.

private void showCLA(AgreementInfo cla) {
    current = cla;
    String url = cla.url();
    if (url != null && url.length() > 0) {
        agreementGroup.setVisible(true);
        agreementHtml.setText(Gerrit.C.rpcStatusWorking());
        if (!url.startsWith("http:") && !url.startsWith("https:")) {
            url = GWT.getHostPageBaseURL() + url;
        }
        final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
        rb.setCallback(new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                new ErrorDialog(exception).center();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                final String ct = response.getHeader("Content-Type");
                if (response.getStatusCode() == 200 && ct != null && (ct.equals("text/html") || ct.startsWith("text/html;"))) {
                    agreementHtml.setHTML(response.getText());
                } else {
                    new ErrorDialog(response.getStatusText()).center();
                }
            }
        });
        try {
            rb.send();
        } catch (RequestException e) {
            new ErrorDialog(e).show();
        }
    } else {
        agreementGroup.setVisible(false);
    }
    finalGroup.setVisible(cla.autoVerifyGroup() != null);
    yesIAgreeBox.setText("");
    submit.setEnabled(false);
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) ErrorDialog(com.google.gerrit.client.ErrorDialog) NativeString(com.google.gerrit.client.rpc.NativeString) RequestException(com.google.gwt.http.client.RequestException)

Example 9 with ErrorDialog

use of com.google.gerrit.client.ErrorDialog in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onCommit.

@UiHandler("commit")
void onCommit(@SuppressWarnings("unused") ClickEvent event) {
    final ProjectAccess access = driver.flush();
    if (driver.hasErrors()) {
        Window.alert(AdminConstants.I.errorsMustBeFixed());
        return;
    }
    String message = commitMessage.getText().trim();
    if ("".equals(message)) {
        message = null;
    }
    enable(false);
    //
    Util.PROJECT_SVC.changeProjectAccess(//
    getProjectKey(), //
    access.getRevision(), //
    message, //
    access.getLocal(), //
    access.getInheritsFrom(), new GerritCallback<ProjectAccess>() {

        @Override
        public void onSuccess(ProjectAccess newAccess) {
            enable(true);
            commitMessage.setText("");
            error.clear();
            final Set<String> diffs = getDiffs(access, newAccess);
            if (diffs.isEmpty()) {
                displayReadOnly(newAccess);
            } else {
                error.add(new Label(Gerrit.C.projectAccessError()));
                for (final String diff : diffs) {
                    error.add(new Label(diff));
                }
                if (access.canUpload()) {
                    error.add(new Label(Gerrit.C.projectAccessProposeForReviewHint()));
                }
            }
        }

        private Set<String> getDiffs(ProjectAccess wantedAccess, ProjectAccess newAccess) {
            List<AccessSection> wantedSections = mergeSections(removeEmptyPermissionsAndSections(wantedAccess.getLocal()));
            List<AccessSection> newSections = removeEmptyPermissionsAndSections(newAccess.getLocal());
            HashSet<AccessSection> same = new HashSet<>(wantedSections);
            HashSet<AccessSection> different = new HashSet<>(wantedSections.size() + newSections.size());
            different.addAll(wantedSections);
            different.addAll(newSections);
            same.retainAll(newSections);
            different.removeAll(same);
            Set<String> differentNames = new HashSet<>();
            for (AccessSection s : different) {
                differentNames.add(s.getName());
            }
            return differentNames;
        }

        @Override
        public void onFailure(Throwable caught) {
            error.clear();
            enable(true);
            if (caught instanceof RemoteJsonException && caught.getMessage().startsWith(UpdateParentFailedException.MESSAGE)) {
                new ErrorDialog(Gerrit.M.parentUpdateFailed(caught.getMessage().substring(UpdateParentFailedException.MESSAGE.length() + 1))).center();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Label(com.google.gwt.user.client.ui.Label) RemoteJsonException(com.google.gwtjsonrpc.client.RemoteJsonException) ErrorDialog(com.google.gerrit.client.ErrorDialog) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) AccessSection(com.google.gerrit.common.data.AccessSection) List(java.util.List) HashSet(java.util.HashSet) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 10 with ErrorDialog

use of com.google.gerrit.client.ErrorDialog in project gerrit by GerritCodeReview.

the class UsernameField method doSetUserName.

private void doSetUserName() {
    if (!canEditUserName()) {
        return;
    }
    enableUI(false);
    String newName = userNameTxt.getText();
    if ("".equals(newName)) {
        newName = null;
    }
    final String newUserName = newName;
    AccountApi.setUsername("self", newUserName, new GerritCallback<NativeString>() {

        @Override
        public void onSuccess(NativeString result) {
            Gerrit.getUserAccount().username(newUserName);
            userNameLbl.setText(newUserName);
            userNameLbl.setVisible(true);
            userNameTxt.setVisible(false);
            setUserName.setVisible(false);
        }

        @Override
        public void onFailure(Throwable caught) {
            enableUI(true);
            if (RestApi.isExpected(422)) {
                new ErrorDialog(Util.C.invalidUserName()).center();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : NativeString(com.google.gerrit.client.rpc.NativeString) ErrorDialog(com.google.gerrit.client.ErrorDialog) NativeString(com.google.gerrit.client.rpc.NativeString)

Aggregations

ErrorDialog (com.google.gerrit.client.ErrorDialog)11 NativeString (com.google.gerrit.client.rpc.NativeString)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 NotSignedInDialog (com.google.gerrit.client.NotSignedInDialog)1 GroupMap (com.google.gerrit.client.groups.GroupMap)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 RevisionInfo (com.google.gerrit.client.info.ChangeInfo.RevisionInfo)1 BranchInfo (com.google.gerrit.client.projects.BranchInfo)1 TagInfo (com.google.gerrit.client.projects.TagInfo)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 AccessSection (com.google.gerrit.common.data.AccessSection)1 GroupReference (com.google.gerrit.common.data.GroupReference)1 PermissionRule (com.google.gerrit.common.data.PermissionRule)1 ProjectAccess (com.google.gerrit.common.data.ProjectAccess)1 CodeDownloadException (com.google.gwt.core.client.CodeDownloadException)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1