diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyWatchedProjectsScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyWatchedProjectsScreen.java index dbb338fb23..aeb1ef4f3d 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyWatchedProjectsScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyWatchedProjectsScreen.java @@ -46,6 +46,7 @@ import com.google.gwtjsonrpc.client.VoidResult; import java.util.HashSet; import java.util.List; +import java.util.Set; public class MyWatchedProjectsScreen extends SettingsScreen { private WatchTable watches; @@ -146,6 +147,12 @@ public class MyWatchedProjectsScreen extends SettingsScreen { add(delSel); } + @Override + protected void onLoad() { + super.onLoad(); + populateWatches(); + } + void doAddNew() { final String projectName = nameTxt.getText(); if ("".equals(projectName)) { @@ -184,16 +191,14 @@ public class MyWatchedProjectsScreen extends SettingsScreen { }); } - @Override - protected void onLoad() { - super.onLoad(); - Util.ACCOUNT_SVC - .myProjectWatch(new ScreenLoadCallback>( - this) { - public void preDisplay(final List result) { - watches.display(result); - } - }); + protected void populateWatches() { + Util.ACCOUNT_SVC.myProjectWatch( + new ScreenLoadCallback>(this) { + @Override + public void preDisplay(final List result) { + watches.display(result); + } + }); } private class WatchTable extends FancyFlexTable { @@ -222,7 +227,30 @@ public class MyWatchedProjectsScreen extends SettingsScreen { } void deleteChecked() { - final HashSet ids = + final Set ids = getCheckedIds(); + if (!ids.isEmpty()) { + Util.ACCOUNT_SVC.deleteProjectWatches(ids, + new GerritCallback() { + public void onSuccess(final VoidResult result) { + remove(ids); + } + }); + } + } + + void remove(Set ids) { + for (int row = 1; row < table.getRowCount();) { + final AccountProjectWatchInfo k = getRowItem(row); + if (k != null && ids.contains(k.getWatch().getKey())) { + table.removeRow(row); + } else { + row++; + } + } + } + + Set getCheckedIds() { + final Set ids = new HashSet(); for (int row = 1; row < table.getRowCount(); row++) { final AccountProjectWatchInfo k = getRowItem(row); @@ -230,21 +258,7 @@ public class MyWatchedProjectsScreen extends SettingsScreen { ids.add(k.getWatch().getKey()); } } - if (!ids.isEmpty()) { - Util.ACCOUNT_SVC.deleteProjectWatches(ids, - new GerritCallback() { - public void onSuccess(final VoidResult result) { - for (int row = 1; row < table.getRowCount();) { - final AccountProjectWatchInfo k = getRowItem(row); - if (k != null && ids.contains(k.getWatch().getKey())) { - table.removeRow(row); - } else { - row++; - } - } - } - }); - } + return ids; } void insertWatch(final AccountProjectWatchInfo k) {