diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationCallback.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationCallback.java new file mode 100644 index 0000000000..e3b7525ee2 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationCallback.java @@ -0,0 +1,29 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client; + +/** + * Interface that a caller must implement to react on the result of a + * {@link ConfirmationDialog}. + */ +public interface ConfirmationCallback { + + /** + * Called when the {@link ConfirmationDialog} is finished with OK. + * To be overwritten by subclasses. + */ + public void onOk(); + +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationDialog.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationDialog.java new file mode 100644 index 0000000000..c4cb770bce --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ConfirmationDialog.java @@ -0,0 +1,77 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client; + +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwtexpui.globalkey.client.GlobalKey; +import com.google.gwtexpui.user.client.AutoCenterDialogBox; + +public class ConfirmationDialog extends AutoCenterDialogBox { + + + private Button cancelButton; + + public ConfirmationDialog(final String dialogTitle, final HTML message, + final ConfirmationCallback callback) { + super(/* auto hide */false, /* modal */true); + setGlassEnabled(true); + setText(dialogTitle); + + final FlowPanel buttons = new FlowPanel(); + + final Button okButton = new Button(); + okButton.setText(Gerrit.C.confirmationDialogOk()); + okButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + hide(); + callback.onOk(); + } + }); + buttons.add(okButton); + + cancelButton = new Button(); + DOM.setStyleAttribute(cancelButton.getElement(), "marginLeft", "300px"); + cancelButton.setText(Gerrit.C.confirmationDialogCancel()); + cancelButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + buttons.add(cancelButton); + + final FlowPanel center = new FlowPanel(); + center.add(message); + center.add(buttons); + add(center); + + message.setWidth("400px"); + + setWidget(center); + } + + @Override + public void center() { + super.center(); + GlobalKey.dialog(this); + cancelButton.setFocus(true); + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java index 567214acf3..357fc6fd44 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java @@ -32,6 +32,12 @@ public interface GerritConstants extends Constants { String errorDialogTitle(); String errorDialogContinue(); + String confirmationDialogOk(); + String confirmationDialogCancel(); + + String branchDeletionDialogTitle(); + String branchDeletionConfirmationMessage(); + String notSignedInTitle(); String notSignedInBody(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties index e4b54be976..a341fa0117 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties @@ -13,6 +13,12 @@ loginTypeUnsupported = Sign in is not available. errorDialogTitle = Application Error errorDialogContinue = Continue +confirmationDialogOk = OK +confirmationDialogCancel = Cancel + +branchDeletionDialogTitle = Branch Deletion +branchDeletionConfirmationMessage = Do you really want to delete the following branches? + notSignedInTitle = Code Review - Session Expired notSignedInBody = Session Expired\

You are no longer signed in to Gerrit Code Review.

\ diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectBranchesPanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectBranchesPanel.java index 090b000867..170c49171c 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectBranchesPanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectBranchesPanel.java @@ -14,6 +14,8 @@ package com.google.gerrit.client.admin; +import com.google.gerrit.client.ConfirmationCallback; +import com.google.gerrit.client.ConfirmationDialog; import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.ui.FancyFlexTable; @@ -40,6 +42,7 @@ import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Grid; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter; import com.google.gwtexpui.globalkey.client.NpTextBox; @@ -264,31 +267,47 @@ public class ProjectBranchesPanel extends Composite { } void deleteChecked() { + final StringBuilder message = new StringBuilder(); + message.append("").append(Gerrit.C.branchDeletionConfirmationMessage()).append(""); + message.append("

"); final HashSet ids = new HashSet(); for (int row = 1; row < table.getRowCount(); row++) { final Branch k = getRowItem(row); if (k != null && table.getWidget(row, 1) instanceof CheckBox && ((CheckBox) table.getWidget(row, 1)).getValue()) { + if (!ids.isEmpty()) { + message.append(",
"); + } + message.append(k.getName()); ids.add(k.getNameKey()); } } + message.append("

"); if (ids.isEmpty()) { return; } - Util.PROJECT_SVC.deleteBranch(projectName, ids, - new GerritCallback>() { - public void onSuccess(final Set deleted) { - for (int row = 1; row < table.getRowCount();) { - final Branch k = getRowItem(row); - if (k != null && deleted.contains(k.getNameKey())) { - table.removeRow(row); - } else { - row++; + ConfirmationDialog confirmationDialog = + new ConfirmationDialog(Gerrit.C.branchDeletionDialogTitle(), + new HTML(message.toString()), new ConfirmationCallback() { + @Override + public void onOk() { + Util.PROJECT_SVC.deleteBranch(projectName, ids, + new GerritCallback>() { + public void onSuccess(final Set deleted) { + for (int row = 1; row < table.getRowCount();) { + final Branch k = getRowItem(row); + if (k != null && deleted.contains(k.getNameKey())) { + table.removeRow(row); + } else { + row++; + } + } } - } - } - }); + }); + } + }); + confirmationDialog.center(); } void display(final List result) {