Confirm branch deletion in web UI

With this change the user will get a confirmation
dialog when he tries to delete a branch. With this dialog
the user has a chance to verify that the branch deletion
is really wanted before the branch is permanently deleted.

Bug: issue 352
Signed-off-by: Edwin Kempin <edwin.kempin@gmail.com>
Change-Id: Ie675dd2a731354220cfedafad9056c5c450e13a6
This commit is contained in:
Edwin Kempin
2010-07-12 15:10:15 +02:00
parent 077b2c5dd0
commit ddcf205410
5 changed files with 149 additions and 12 deletions

View File

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

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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 = <b>Session Expired</b>\
<p>You are no longer signed in to Gerrit Code Review.</p>\

View File

@@ -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("<b>").append(Gerrit.C.branchDeletionConfirmationMessage()).append("</b>");
message.append("<p>");
final HashSet<Branch.NameKey> ids = new HashSet<Branch.NameKey>();
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(", <br>");
}
message.append(k.getName());
ids.add(k.getNameKey());
}
}
message.append("</p>");
if (ids.isEmpty()) {
return;
}
Util.PROJECT_SVC.deleteBranch(projectName, ids,
new GerritCallback<Set<Branch.NameKey>>() {
public void onSuccess(final Set<Branch.NameKey> 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<Set<Branch.NameKey>>() {
public void onSuccess(final Set<Branch.NameKey> 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<Branch> result) {