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();
}
}
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);
}
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);
}
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);
}
}
});
}
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);
}
}
});
}
Aggregations