Create a ChangeCache for ChangeDetails in ChangeScreen
Create a ChangeCache as a general place to hold client side data about changes. Having a common place to store change data will allow multiple UI widgets to refer to the same data without having to be connected to or aware of other widgets. In this change, the ChangeCache only holds ChangeDetailCaches, but in the future it may hold more Change data. Combining all Change related objects into a single ChangeCache and placing them in a Map allows efficient combined lookups by Change over placing each separate data type into its own Map. ChanegDetailsCaches are also new in this change and can hold a ChangeDetail while being listened to. A ChangeDetailCache will inform its listeners when a new ChangeDetail is loaded into the cache. Make the ChangeScreen listen to the ChangeDetailCache and update itself when the ChangeDetail changes. This gives components another way to tell a ChangeScreen to update itself without having to hold a reference to the ChangeScreen, and without actually even having any knowledge that such a screen even exits. This will allow current and new UI sub or super components to be more independent from a ChangeScreen. The current way to update the ChangeScreen's ChangeDetail is for widgets to hold a reference to the ChangeScreen and to call its update() method with a ChangeDetail. While this change introduces the ability to update a ChangeScreen via the ChangeDetailCache, this new method is only used internally so far (onLoad), no external components use this facility yet. To use this feature, components need only grab a ChangeDetailCache from the ChangeCache for the current Change, and then update the ChangeDetailCache with a call to set(ChangeDetail). Or more likely, if they need to make an RPC call which will return a ChangeDetail, they may statically obtain a GerritCallback from the ChangeDetailCache class which knows how to update the appropriate ChangeDetailCache for them directly. Both of these approaches will enable any listeners to the ChangeDetail value to be aware that they need to update themselves to the new value of the ChangeDetail. The ChangeScreen is now such a listener and does exactly that. Change-Id: Iaa0a9a2faece760f3b54f6e204f268d9d6ef2c5b
This commit is contained in:

committed by
Edwin Kempin

parent
15182323b4
commit
b6c912cc0d
@@ -17,7 +17,6 @@ package com.google.gerrit.client.changes;
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.CommentPanel;
|
||||
import com.google.gerrit.client.ui.ComplexDisclosurePanel;
|
||||
import com.google.gerrit.client.ui.ExpandAllCommand;
|
||||
@@ -39,6 +38,8 @@ import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.i18n.client.LocaleInfo;
|
||||
import com.google.gwt.user.client.ui.DisclosurePanel;
|
||||
@@ -59,9 +60,11 @@ import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ChangeScreen extends Screen {
|
||||
public class ChangeScreen extends Screen
|
||||
implements ValueChangeHandler<ChangeDetail> {
|
||||
private final Change.Id changeId;
|
||||
private final PatchSet.Id openPatchSetId;
|
||||
private ChangeDetailCache detailCache;
|
||||
|
||||
private Image starChange;
|
||||
private boolean starred;
|
||||
@@ -130,7 +133,7 @@ public class ChangeScreen extends Screen {
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
refresh();
|
||||
detailCache.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,21 +159,6 @@ public class ChangeScreen extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
Util.DETAIL_SVC.changeDetail(changeId,
|
||||
new ScreenLoadCallback<ChangeDetail>(this) {
|
||||
@Override
|
||||
protected void preDisplay(final ChangeDetail r) {
|
||||
display(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postDisplay() {
|
||||
patchSetsBlock.setRegisterKeys(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setStarred(final boolean s) {
|
||||
if (s) {
|
||||
starChange.setResource(Gerrit.RESOURCES.starFilled());
|
||||
@@ -183,6 +171,12 @@ public class ChangeScreen extends Screen {
|
||||
@Override
|
||||
protected void onInitUI() {
|
||||
super.onInitUI();
|
||||
|
||||
ChangeCache cache = ChangeCache.get(changeId);
|
||||
|
||||
detailCache = cache.getChangeDetailCache();
|
||||
detailCache.addValueChangeHandler(this);
|
||||
|
||||
addStyleName(Gerrit.RESOURCES.css().changeScreen());
|
||||
|
||||
keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
|
||||
@@ -284,9 +278,15 @@ public class ChangeScreen extends Screen {
|
||||
setPageTitle(titleBuf.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChange(ValueChangeEvent<ChangeDetail> event) {
|
||||
if (isAttached()) {
|
||||
display(event.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void update(final ChangeDetail detail) {
|
||||
display(detail);
|
||||
patchSetsBlock.setRegisterKeys(true);
|
||||
detailCache.set(detail);
|
||||
}
|
||||
|
||||
private void display(final ChangeDetail detail) {
|
||||
@@ -348,6 +348,11 @@ public class ChangeScreen extends Screen {
|
||||
dependenciesPanel.getHeader().add(new InlineLabel(
|
||||
Util.M.outdatedHeader(outdated)));
|
||||
}
|
||||
|
||||
if (!isCurrentView()) {
|
||||
display();
|
||||
}
|
||||
patchSetsBlock.setRegisterKeys(true);
|
||||
}
|
||||
|
||||
private void addComments(final ChangeDetail detail) {
|
||||
|
Reference in New Issue
Block a user