Adapt and use the StarCache in ChangeTable
Adapt the StarCache to also be able to listen to a ListenableValue of ChangeInfo and use the StarCache in the ChangeTable. If either the ChangeDetail or the ChangeInfo are updated, the starred value will be updated and transferred to the opposing change data container type. Change-Id: I0dd5144e9948f570e1acc289d87d9f1ac2789e16
This commit is contained in:
committed by
Edwin Kempin
parent
7cbccd2216
commit
865b7275f9
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.ui.ListenableValue;
|
||||
import com.google.gerrit.common.data.ChangeInfo;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -35,6 +37,7 @@ public class ChangeCache {
|
||||
|
||||
private Change.Id changeId;
|
||||
private ChangeDetailCache detail;
|
||||
private ListenableValue<ChangeInfo> info;
|
||||
private StarCache starred;
|
||||
|
||||
protected ChangeCache(Change.Id chg) {
|
||||
@@ -52,6 +55,13 @@ public class ChangeCache {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public ListenableValue<ChangeInfo> getChangeInfoCache() {
|
||||
if (info == null) {
|
||||
info = new ListenableValue<ChangeInfo>();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public StarCache getStarCache() {
|
||||
if (starred == null) {
|
||||
starred = new StarCache(changeId);
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.google.gerrit.common.data.ApprovalSummary;
|
||||
import com.google.gerrit.common.data.ApprovalSummarySet;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ChangeInfo;
|
||||
import com.google.gerrit.common.data.ToggleStarRequest;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
@@ -45,7 +44,6 @@ import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
@@ -54,8 +52,6 @@ import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.UIObject;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -136,7 +132,7 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
||||
return;
|
||||
}
|
||||
if (cell.getCellIndex() == C_STAR) {
|
||||
onStarClick(cell.getRowIndex());
|
||||
// Don't do anything (handled by star itself).
|
||||
} else if (cell.getCellIndex() == C_OWNER) {
|
||||
// Don't do anything.
|
||||
} else if (getRowItem(cell.getRowIndex()) != null) {
|
||||
@@ -149,23 +145,7 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
||||
protected void onStarClick(final int row) {
|
||||
final ChangeInfo c = getRowItem(row);
|
||||
if (c != null && Gerrit.isSignedIn()) {
|
||||
final boolean prior = c.isStarred();
|
||||
c.setStarred(!prior);
|
||||
setStar(row, c);
|
||||
|
||||
final ToggleStarRequest req = new ToggleStarRequest();
|
||||
req.toggle(c.getId(), c.isStarred());
|
||||
Util.LIST_SVC.toggleStars(req, new GerritCallback<VoidResult>() {
|
||||
public void onSuccess(final VoidResult result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable caught) {
|
||||
super.onFailure(caught);
|
||||
c.setStarred(prior);
|
||||
setStar(row, c);
|
||||
}
|
||||
});
|
||||
ChangeCache.get(c.getId()).getStarCache().toggleStar();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,10 +192,13 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
||||
}
|
||||
|
||||
private void populateChangeRow(final int row, final ChangeInfo c) {
|
||||
ChangeCache cache = ChangeCache.get(c.getId());
|
||||
cache.getChangeInfoCache().set(c);
|
||||
|
||||
final String idstr = c.getKey().abbreviate();
|
||||
table.setWidget(row, C_ARROW, null);
|
||||
if (Gerrit.isSignedIn()) {
|
||||
setStar(row, c);
|
||||
table.setWidget(row, C_STAR, cache.getStarCache().createStar());
|
||||
}
|
||||
table.setWidget(row, C_ID, new TableChangeLink(idstr, c));
|
||||
|
||||
@@ -247,22 +230,6 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
|
||||
return AccountDashboardLink.link(accountCache, id);
|
||||
}
|
||||
|
||||
private void setStar(final int row, final ChangeInfo c) {
|
||||
final ImageResource star;
|
||||
if (c.isStarred()) {
|
||||
star = Gerrit.RESOURCES.starFilled();
|
||||
} else {
|
||||
star = Gerrit.RESOURCES.starOpen();
|
||||
}
|
||||
|
||||
final Widget i = table.getWidget(row, C_STAR);
|
||||
if (i instanceof Image) {
|
||||
((Image) i).setResource(star);
|
||||
} else {
|
||||
table.setWidget(row, C_STAR, new Image(star));
|
||||
}
|
||||
}
|
||||
|
||||
public void addSection(final Section s) {
|
||||
assert s.parent == null;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.NeedsSignInKeyCommand;
|
||||
import com.google.gerrit.common.data.ChangeDetail;
|
||||
import com.google.gerrit.common.data.ChangeInfo;
|
||||
import com.google.gerrit.common.data.ToggleStarRequest;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
|
||||
@@ -59,6 +60,10 @@ public class StarCache implements HasValueChangeHandlers<Boolean> {
|
||||
if (detail != null) {
|
||||
return detail.isStarred();
|
||||
}
|
||||
ChangeInfo info = cache.getChangeInfoCache().get();
|
||||
if (info != null) {
|
||||
return info.isStarred();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -81,6 +86,10 @@ public class StarCache implements HasValueChangeHandlers<Boolean> {
|
||||
if (detail != null) {
|
||||
detail.setStarred(s);
|
||||
}
|
||||
ChangeInfo info = cache.getChangeInfoCache().get();
|
||||
if (info != null) {
|
||||
info.setStarred(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleStar() {
|
||||
@@ -106,6 +115,7 @@ public class StarCache implements HasValueChangeHandlers<Boolean> {
|
||||
};
|
||||
|
||||
cache.getChangeDetailCache().addValueChangeHandler(starUpdater);
|
||||
cache.getChangeInfoCache().addValueChangeHandler(starUpdater);
|
||||
|
||||
this.addValueChangeHandler(starUpdater);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user