Merge "Create a ChangeCache for ChangeDetails in ChangeScreen"
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** A Cache to store common client side data by change */
|
||||
public class ChangeCache {
|
||||
private static Map<Change.Id, ChangeCache> caches =
|
||||
new HashMap<Change.Id, ChangeCache>();
|
||||
|
||||
public static ChangeCache get(Change.Id chg) {
|
||||
ChangeCache cache = caches.get(chg);
|
||||
if (cache == null) {
|
||||
cache = new ChangeCache(chg);
|
||||
caches.put(chg, cache);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
private Change.Id changeId;
|
||||
private ChangeDetailCache detail;
|
||||
|
||||
protected ChangeCache(Change.Id chg) {
|
||||
changeId = chg;
|
||||
}
|
||||
|
||||
public Change.Id getChangeId() {
|
||||
return changeId;
|
||||
}
|
||||
|
||||
public ChangeDetailCache getChangeDetailCache() {
|
||||
if (detail == null) {
|
||||
detail = new ChangeDetailCache(changeId);
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.ui.ListenableValue;
|
||||
import com.google.gerrit.common.data.ChangeDetail;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
public class ChangeDetailCache extends ListenableValue<ChangeDetail> {
|
||||
public static class GerritCallback extends
|
||||
com.google.gerrit.client.rpc.GerritCallback<ChangeDetail> {
|
||||
@Override
|
||||
public void onSuccess(ChangeDetail detail) {
|
||||
setChangeDetail(detail);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IgnoreErrorCallback implements AsyncCallback<ChangeDetail> {
|
||||
@Override
|
||||
public void onSuccess(ChangeDetail detail) {
|
||||
setChangeDetail(detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setChangeDetail(ChangeDetail detail) {
|
||||
Change.Id chgId = detail.getChange().getId();
|
||||
ChangeCache.get(chgId).getChangeDetailCache().set(detail);
|
||||
}
|
||||
|
||||
private final Change.Id changeId;
|
||||
|
||||
public ChangeDetailCache(final Change.Id chg) {
|
||||
changeId = chg;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
Util.DETAIL_SVC.changeDetail(changeId, new GerritCallback());
|
||||
}
|
||||
}
|
@@ -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());
|
||||
@@ -283,9 +277,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) {
|
||||
@@ -352,6 +352,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