Use PatchSet.Id rather than int to enumerate PatchSets
There is no assurance that patch sets don't have a gap in their numbering. A crashed update may have allocated a patch set number, but not actually stored it on the change. Instead use the entire PatchSet.Id object for compares, and keep the order of patch sets in a list so they can be enumerated through during the next/previous traversals. Change-Id: I44be87ba1b6413b338a58d3147f87cd8299a62b4 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import com.google.gwtexpui.globalkey.client.KeyCommand;
|
|||||||
import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composite that displays the patch sets of a change. This composite ensures
|
* Composite that displays the patch sets of a change. This composite ensures
|
||||||
@@ -38,8 +39,8 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class PatchSetsBlock extends Composite {
|
public class PatchSetsBlock extends Composite {
|
||||||
|
|
||||||
private final HashMap<Integer, PatchSetComplexDisclosurePanel> patchSetPanels =
|
private final HashMap<PatchSet.Id, PatchSetComplexDisclosurePanel> patchSetPanels =
|
||||||
new HashMap<Integer, PatchSetComplexDisclosurePanel>();
|
new HashMap<PatchSet.Id, PatchSetComplexDisclosurePanel>();
|
||||||
|
|
||||||
private final ChangeScreen parent;
|
private final ChangeScreen parent;
|
||||||
private final FlowPanel body;
|
private final FlowPanel body;
|
||||||
@@ -49,10 +50,13 @@ public class PatchSetsBlock extends Composite {
|
|||||||
* the patch set id of the patch set for which is the keyboard navigation is
|
* the patch set id of the patch set for which is the keyboard navigation is
|
||||||
* currently enabled
|
* currently enabled
|
||||||
*/
|
*/
|
||||||
private int activePatchSetId = -1;
|
private PatchSet.Id activePatchSetId;
|
||||||
|
|
||||||
/** the patch set id of the current (latest) patch set */
|
/** the patch set id of the current (latest) patch set */
|
||||||
private int currentPatchSetId = -1;
|
private PatchSet.Id currentPatchSetId;
|
||||||
|
|
||||||
|
/** Patch sets on this change, in order. */
|
||||||
|
private List<PatchSet> patchSets;
|
||||||
|
|
||||||
PatchSetsBlock(final ChangeScreen parent) {
|
PatchSetsBlock(final ChangeScreen parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@@ -65,8 +69,10 @@ public class PatchSetsBlock extends Composite {
|
|||||||
clear();
|
clear();
|
||||||
|
|
||||||
final PatchSet currps = detail.getCurrentPatchSet();
|
final PatchSet currps = detail.getCurrentPatchSet();
|
||||||
currentPatchSetId = currps.getPatchSetId();
|
currentPatchSetId = currps.getId();
|
||||||
for (final PatchSet ps : detail.getPatchSets()) {
|
patchSets = detail.getPatchSets();
|
||||||
|
|
||||||
|
for (final PatchSet ps : patchSets) {
|
||||||
if (ps == currps) {
|
if (ps == currps) {
|
||||||
add(new PatchSetComplexDisclosurePanel(parent, detail, detail
|
add(new PatchSetComplexDisclosurePanel(parent, detail, detail
|
||||||
.getCurrentPatchSetDetail()));
|
.getCurrentPatchSetDetail()));
|
||||||
@@ -90,11 +96,11 @@ public class PatchSetsBlock extends Composite {
|
|||||||
private void add(final PatchSetComplexDisclosurePanel patchSetPanel) {
|
private void add(final PatchSetComplexDisclosurePanel patchSetPanel) {
|
||||||
body.add(patchSetPanel);
|
body.add(patchSetPanel);
|
||||||
|
|
||||||
int patchSetId = patchSetPanel.getPatchSet().getPatchSetId();
|
final PatchSet.Id id = patchSetPanel.getPatchSet().getId();
|
||||||
ActivationHandler activationHandler = new ActivationHandler(patchSetId);
|
ActivationHandler activationHandler = new ActivationHandler(id);
|
||||||
patchSetPanel.addOpenHandler(activationHandler);
|
patchSetPanel.addOpenHandler(activationHandler);
|
||||||
patchSetPanel.addClickHandler(activationHandler);
|
patchSetPanel.addClickHandler(activationHandler);
|
||||||
patchSetPanels.put(patchSetId, patchSetPanel);
|
patchSetPanels.put(id, patchSetPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegisterKeys(final boolean on) {
|
public void setRegisterKeys(final boolean on) {
|
||||||
@@ -106,7 +112,7 @@ public class PatchSetsBlock extends Composite {
|
|||||||
keysNavigation.add(new NextPatchSetKeyCommand(0, 'n', Util.C
|
keysNavigation.add(new NextPatchSetKeyCommand(0, 'n', Util.C
|
||||||
.nextPatchSet()));
|
.nextPatchSet()));
|
||||||
regNavigation = GlobalKey.add(this, keysNavigation);
|
regNavigation = GlobalKey.add(this, keysNavigation);
|
||||||
if (activePatchSetId != -1) {
|
if (activePatchSetId != null) {
|
||||||
activate(activePatchSetId);
|
activate(activePatchSetId);
|
||||||
} else {
|
} else {
|
||||||
activate(currentPatchSetId);
|
activate(currentPatchSetId);
|
||||||
@@ -134,8 +140,8 @@ public class PatchSetsBlock extends Composite {
|
|||||||
* This method also ensures that the current row is only highlighted in the
|
* This method also ensures that the current row is only highlighted in the
|
||||||
* table of the active patch set panel.
|
* table of the active patch set panel.
|
||||||
*/
|
*/
|
||||||
private void activate(final int patchSetId) {
|
private void activate(final PatchSet.Id patchSetId) {
|
||||||
if (activePatchSetId != patchSetId) {
|
if (!patchSetId.equals(activePatchSetId)) {
|
||||||
deactivate();
|
deactivate();
|
||||||
PatchSetComplexDisclosurePanel patchSetPanel =
|
PatchSetComplexDisclosurePanel patchSetPanel =
|
||||||
patchSetPanels.get(patchSetId);
|
patchSetPanels.get(patchSetId);
|
||||||
@@ -147,11 +153,11 @@ public class PatchSetsBlock extends Composite {
|
|||||||
|
|
||||||
/** Deactivates the keyboard navigation for the currently active patch set panel. */
|
/** Deactivates the keyboard navigation for the currently active patch set panel. */
|
||||||
private void deactivate() {
|
private void deactivate() {
|
||||||
if (activePatchSetId != -1) {
|
if (activePatchSetId != null) {
|
||||||
PatchSetComplexDisclosurePanel patchSetPanel =
|
PatchSetComplexDisclosurePanel patchSetPanel =
|
||||||
patchSetPanels.get(activePatchSetId);
|
patchSetPanels.get(activePatchSetId);
|
||||||
patchSetPanel.setActive(false);
|
patchSetPanel.setActive(false);
|
||||||
activePatchSetId = -1;
|
activePatchSetId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,12 +171,21 @@ public class PatchSetsBlock extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int indexOf(PatchSet.Id id) {
|
||||||
|
for (int i = 0; i < patchSets.size(); i++) {
|
||||||
|
if (patchSets.get(i).getId().equals(id)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private class ActivationHandler implements OpenHandler<DisclosurePanel>,
|
private class ActivationHandler implements OpenHandler<DisclosurePanel>,
|
||||||
ClickHandler {
|
ClickHandler {
|
||||||
|
|
||||||
private final int patchSetId;
|
private final PatchSet.Id patchSetId;
|
||||||
|
|
||||||
ActivationHandler(int patchSetId) {
|
ActivationHandler(PatchSet.Id patchSetId) {
|
||||||
this.patchSetId = patchSetId;
|
this.patchSetId = patchSetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,8 +212,9 @@ public class PatchSetsBlock extends Composite {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyPress(final KeyPressEvent event) {
|
public void onKeyPress(final KeyPressEvent event) {
|
||||||
if (activePatchSetId > 1) {
|
int index = indexOf(activePatchSetId) - 1;
|
||||||
activate(activePatchSetId - 1);
|
if (0 <= index) {
|
||||||
|
activate(patchSets.get(index).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,8 +226,9 @@ public class PatchSetsBlock extends Composite {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyPress(final KeyPressEvent event) {
|
public void onKeyPress(final KeyPressEvent event) {
|
||||||
if (activePatchSetId > 0 && activePatchSetId < body.getWidgetCount()) {
|
int index = indexOf(activePatchSetId) + 1;
|
||||||
activate(activePatchSetId + 1);
|
if (index < patchSets.size()) {
|
||||||
|
activate(patchSets.get(index).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user