Split several functions in MyWatchedProjectsScreen

Refactor two functions out of deleteChecked():

 remove(Set<AccountProjectWatch.Key> ids)

and

 Set<AccountProjectWatch.Key> getCheckedIds()

This should help clarify how deleteChecked() works and make
maintenance a bit easier since it is now possible to override
each of the methods separately. Also factor out the
populateWatches() function.

Change-Id: Ia1bff8e628be5ed8e911b23b0b2e7bc1133d12f6
This commit is contained in:
Martin Fick
2010-08-25 14:51:12 -06:00
parent 3553c79857
commit 91259f6b66

View File

@@ -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<List<AccountProjectWatchInfo>>(
this) {
public void preDisplay(final List<AccountProjectWatchInfo> result) {
watches.display(result);
}
});
protected void populateWatches() {
Util.ACCOUNT_SVC.myProjectWatch(
new ScreenLoadCallback<List<AccountProjectWatchInfo>>(this) {
@Override
public void preDisplay(final List<AccountProjectWatchInfo> result) {
watches.display(result);
}
});
}
private class WatchTable extends FancyFlexTable<AccountProjectWatchInfo> {
@@ -222,7 +227,30 @@ public class MyWatchedProjectsScreen extends SettingsScreen {
}
void deleteChecked() {
final HashSet<AccountProjectWatch.Key> ids =
final Set<AccountProjectWatch.Key> ids = getCheckedIds();
if (!ids.isEmpty()) {
Util.ACCOUNT_SVC.deleteProjectWatches(ids,
new GerritCallback<VoidResult>() {
public void onSuccess(final VoidResult result) {
remove(ids);
}
});
}
}
void remove(Set<AccountProjectWatch.Key> 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<AccountProjectWatch.Key> getCheckedIds() {
final Set<AccountProjectWatch.Key> ids =
new HashSet<AccountProjectWatch.Key>();
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<VoidResult>() {
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) {