Merge changes I18a3eb89,I24fa20bd

* changes:
  RebaseDialog: Clarify purpose of checkbox with comments
  RebaseDialog: Use projectQuery to escape project name in operator
This commit is contained in:
Shawn Pearce 2015-07-17 22:11:09 +00:00 committed by Gerrit Code Review
commit fb567fc442

View File

@ -20,8 +20,10 @@ import com.google.gerrit.client.changes.ChangeList;
import com.google.gerrit.client.changes.Util; import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.Natives; import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.extensions.client.ListChangesOption; import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.CheckBox;
@ -30,14 +32,14 @@ import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwtexpui.globalkey.client.GlobalKey; import com.google.gwtexpui.globalkey.client.GlobalKey;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle; import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
public abstract class RebaseDialog extends CommentedActionDialog { public abstract class RebaseDialog extends CommentedActionDialog {
private final SuggestBox base; private final SuggestBox base;
private final CheckBox cb; private final CheckBox changeParent;
private List<ChangeInfo> changes; private List<ChangeInfo> candidateChanges;
private final boolean sendEnabled; private final boolean sendEnabled;
public RebaseDialog(final String project, final String branch, public RebaseDialog(final String project, final String branch,
@ -46,13 +48,15 @@ public abstract class RebaseDialog extends CommentedActionDialog {
this.sendEnabled = sendEnabled; this.sendEnabled = sendEnabled;
sendButton.setText(Util.C.buttonRebaseChangeSend()); sendButton.setText(Util.C.buttonRebaseChangeSend());
// create the suggestion box // Create the suggestion box to filter over a list of recent changes
// open on the same branch. The list of candidates is primed by the
// changeParent CheckBox (below) getting enabled by the user.
base = new SuggestBox(new HighlightSuggestOracle() { base = new SuggestBox(new HighlightSuggestOracle() {
@Override @Override
protected void onRequestSuggestions(Request request, Callback done) { protected void onRequestSuggestions(Request request, Callback done) {
String query = request.getQuery().toLowerCase(); String query = request.getQuery().toLowerCase();
LinkedList<ChangeSuggestion> suggestions = new LinkedList<>(); List<ChangeSuggestion> suggestions = new ArrayList<>();
for (final ChangeInfo ci : changes) { for (ChangeInfo ci : candidateChanges) {
if (changeId.equals(ci.legacyId())) { if (changeId.equals(ci.legacyId())) {
continue; // do not suggest current change continue; // do not suggest current change
} }
@ -71,23 +75,32 @@ public abstract class RebaseDialog extends CommentedActionDialog {
Util.C.rebasePlaceholderMessage()); Util.C.rebasePlaceholderMessage());
base.setStyleName(Gerrit.RESOURCES.css().rebaseSuggestBox()); base.setStyleName(Gerrit.RESOURCES.css().rebaseSuggestBox());
// the checkbox which must be clicked before the change list is populated // The changeParent checkbox must be clicked to load into browser memory
cb = new CheckBox(Util.C.rebaseConfirmMessage()); // a list of open changes from the same project and same branch that this
cb.addClickHandler(new ClickHandler() { // change may rebase onto.
changeParent = new CheckBox(Util.C.rebaseConfirmMessage());
changeParent.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
boolean checked = ((CheckBox) event.getSource()).getValue(); if (changeParent.getValue()) {
if (checked) {
ChangeList.query( ChangeList.query(
"project:" + project + " AND branch:" + branch PageLinks.projectQuery(new Project.NameKey(project))
+ " AND is:open NOT age:90d", + " " + PageLinks.op("branch", branch)
+ " is:open -age:90d",
Collections.<ListChangesOption> emptySet(), Collections.<ListChangesOption> emptySet(),
new GerritCallback<ChangeList>() { new GerritCallback<ChangeList>() {
@Override @Override
public void onSuccess(ChangeList result) { public void onSuccess(ChangeList result) {
changes = Natives.asList(result); candidateChanges = Natives.asList(result);
updateControls(true); updateControls(true);
} }
@Override
public void onFailure(Throwable err) {
updateControls(false);
changeParent.setValue(false);
super.onFailure(err);
}
}); });
} else { } else {
updateControls(false); updateControls(false);
@ -96,7 +109,7 @@ public abstract class RebaseDialog extends CommentedActionDialog {
}); });
// add the checkbox and suggestbox widgets to the content panel // add the checkbox and suggestbox widgets to the content panel
contentPanel.add(cb); contentPanel.add(changeParent);
contentPanel.add(base); contentPanel.add(base);
contentPanel.setStyleName(Gerrit.RESOURCES.css().rebaseContentPanel()); contentPanel.setStyleName(Gerrit.RESOURCES.css().rebaseContentPanel());
} }
@ -128,7 +141,7 @@ public abstract class RebaseDialog extends CommentedActionDialog {
} }
public String getBase() { public String getBase() {
return cb.getValue() ? base.getText() : null; return changeParent.getValue() ? base.getText() : null;
} }
private static class ChangeSuggestion implements Suggestion { private static class ChangeSuggestion implements Suggestion {