Only enable the Delete button if an SSH key is selected
Like with the web identities, we only enable the Delete button now if at least one key has been selected for removal. Change-Id: I44bfecf7039ea95836c33b2620004dda9a69f4ea Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -35,6 +35,8 @@ import com.google.gwt.event.dom.client.ClickHandler;
|
|||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||||
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||||
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||||
import com.google.gwt.i18n.client.LocaleInfo;
|
import com.google.gwt.i18n.client.LocaleInfo;
|
||||||
import com.google.gwt.user.client.DOM;
|
import com.google.gwt.user.client.DOM;
|
||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
@@ -57,6 +59,7 @@ import com.google.gwtexpui.globalkey.client.NpTextBox;
|
|||||||
import com.google.gwtjsonrpc.client.RemoteJsonException;
|
import com.google.gwtjsonrpc.client.RemoteJsonException;
|
||||||
import com.google.gwtjsonrpc.client.VoidResult;
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -81,7 +84,7 @@ class SshPanel extends Composite {
|
|||||||
private Button browse;
|
private Button browse;
|
||||||
private Timer appletLoadTimer;
|
private Timer appletLoadTimer;
|
||||||
private NpTextArea addTxt;
|
private NpTextArea addTxt;
|
||||||
private Button delSel;
|
private Button deleteKey;
|
||||||
|
|
||||||
private Panel serverKeys;
|
private Panel serverKeys;
|
||||||
|
|
||||||
@@ -144,14 +147,15 @@ class SshPanel extends Composite {
|
|||||||
body.add(keys);
|
body.add(keys);
|
||||||
{
|
{
|
||||||
final FlowPanel fp = new FlowPanel();
|
final FlowPanel fp = new FlowPanel();
|
||||||
delSel = new Button(Util.C.buttonDeleteSshKey());
|
deleteKey = new Button(Util.C.buttonDeleteSshKey());
|
||||||
delSel.addClickHandler(new ClickHandler() {
|
deleteKey.setEnabled(false);
|
||||||
|
deleteKey.addClickHandler(new ClickHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final ClickEvent event) {
|
public void onClick(final ClickEvent event) {
|
||||||
keys.deleteChecked();
|
keys.deleteChecked();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fp.add(delSel);
|
fp.add(deleteKey);
|
||||||
fp.add(showAddKeyBlock);
|
fp.add(showAddKeyBlock);
|
||||||
body.add(fp);
|
body.add(fp);
|
||||||
}
|
}
|
||||||
@@ -234,7 +238,7 @@ class SshPanel extends Composite {
|
|||||||
|
|
||||||
void setKeyTableVisible(final boolean on) {
|
void setKeyTableVisible(final boolean on) {
|
||||||
keys.setVisible(on);
|
keys.setVisible(on);
|
||||||
delSel.setVisible(on);
|
deleteKey.setVisible(on);
|
||||||
closeAddKeyBlock.setVisible(on);
|
closeAddKeyBlock.setVisible(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,6 +400,7 @@ class SshPanel extends Composite {
|
|||||||
if (!keys.isVisible()) {
|
if (!keys.isVisible()) {
|
||||||
showAddKeyBlock(false);
|
showAddKeyBlock(false);
|
||||||
setKeyTableVisible(true);
|
setKeyTableVisible(true);
|
||||||
|
keys.updateDeleteButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,6 +530,8 @@ class SshPanel extends Composite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SshKeyTable extends FancyFlexTable<AccountSshKey> {
|
private class SshKeyTable extends FancyFlexTable<AccountSshKey> {
|
||||||
|
private ValueChangeHandler<Boolean> updateDeleteHandler;
|
||||||
|
|
||||||
SshKeyTable() {
|
SshKeyTable() {
|
||||||
table.setWidth("");
|
table.setWidth("");
|
||||||
table.setText(0, 2, Util.C.sshKeyStatus());
|
table.setText(0, 2, Util.C.sshKeyStatus());
|
||||||
@@ -538,6 +545,13 @@ class SshPanel extends Composite {
|
|||||||
fmt.addStyleName(0, 3, Gerrit.RESOURCES.css().dataHeader());
|
fmt.addStyleName(0, 3, Gerrit.RESOURCES.css().dataHeader());
|
||||||
fmt.addStyleName(0, 4, Gerrit.RESOURCES.css().dataHeader());
|
fmt.addStyleName(0, 4, Gerrit.RESOURCES.css().dataHeader());
|
||||||
fmt.addStyleName(0, 5, Gerrit.RESOURCES.css().dataHeader());
|
fmt.addStyleName(0, 5, Gerrit.RESOURCES.css().dataHeader());
|
||||||
|
|
||||||
|
updateDeleteHandler = new ValueChangeHandler<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
||||||
|
updateDeleteButton();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteChecked() {
|
void deleteChecked() {
|
||||||
@@ -548,7 +562,9 @@ class SshPanel extends Composite {
|
|||||||
ids.add(k.getKey());
|
ids.add(k.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ids.isEmpty()) {
|
if (ids.isEmpty()) {
|
||||||
|
updateDeleteButton();
|
||||||
|
} else {
|
||||||
Util.ACCOUNT_SEC.deleteSshKeys(ids, new GerritCallback<VoidResult>() {
|
Util.ACCOUNT_SEC.deleteSshKeys(ids, new GerritCallback<VoidResult>() {
|
||||||
public void onSuccess(final VoidResult result) {
|
public void onSuccess(final VoidResult result) {
|
||||||
for (int row = 1; row < table.getRowCount();) {
|
for (int row = 1; row < table.getRowCount();) {
|
||||||
@@ -560,7 +576,9 @@ class SshPanel extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (table.getRowCount() == 1) {
|
if (table.getRowCount() == 1) {
|
||||||
showAddKeyBlock(true);
|
display(Collections.<AccountSshKey> emptyList());
|
||||||
|
} else {
|
||||||
|
updateDeleteButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -568,11 +586,17 @@ class SshPanel extends Composite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void display(final List<AccountSshKey> result) {
|
void display(final List<AccountSshKey> result) {
|
||||||
while (1 < table.getRowCount())
|
if (result.isEmpty()) {
|
||||||
table.removeRow(table.getRowCount() - 1);
|
setKeyTableVisible(false);
|
||||||
|
showAddKeyBlock(true);
|
||||||
for (final AccountSshKey k : result) {
|
} else {
|
||||||
addOneKey(k);
|
while (1 < table.getRowCount())
|
||||||
|
table.removeRow(table.getRowCount() - 1);
|
||||||
|
for (final AccountSshKey k : result) {
|
||||||
|
addOneKey(k);
|
||||||
|
}
|
||||||
|
setKeyTableVisible(true);
|
||||||
|
deleteKey.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +606,10 @@ class SshPanel extends Composite {
|
|||||||
table.insertRow(row);
|
table.insertRow(row);
|
||||||
applyDataRowStyle(row);
|
applyDataRowStyle(row);
|
||||||
|
|
||||||
table.setWidget(row, 1, new CheckBox());
|
final CheckBox sel = new CheckBox();
|
||||||
|
sel.addValueChangeHandler(updateDeleteHandler);
|
||||||
|
|
||||||
|
table.setWidget(row, 1, sel);
|
||||||
if (k.isValid()) {
|
if (k.isValid()) {
|
||||||
table.setText(row, 2, "");
|
table.setText(row, 2, "");
|
||||||
fmt.removeStyleName(row, 2, //
|
fmt.removeStyleName(row, 2, //
|
||||||
@@ -603,6 +630,18 @@ class SshPanel extends Composite {
|
|||||||
|
|
||||||
setRowItem(row, k);
|
setRowItem(row, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDeleteButton() {
|
||||||
|
boolean on = false;
|
||||||
|
for (int row = 1; row < table.getRowCount(); row++) {
|
||||||
|
CheckBox sel = (CheckBox) table.getWidget(row, 1);
|
||||||
|
if (sel.getValue()) {
|
||||||
|
on = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deleteKey.setEnabled(on);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String elide(final String s, final int len) {
|
static String elide(final String s, final int len) {
|
||||||
|
|||||||
Reference in New Issue
Block a user