diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index e66de7eb31..f1b2e99ccc 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -2317,10 +2317,6 @@ the user hovers the mouse. If true the action is permitted at this time and the caller is likely allowed to execute it. This may change if state is updated at the server or permissions are modified. Not present if false. -|`confirmation_message` |optional| -Warning message to display to the user at the client side after -the user has selected to use this action, but before the action -request is sent to the server. |==================================== [[add-reviewer-result]] diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/UiCommandDetail.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/UiCommandDetail.java index 557d05c4d1..cd0118605f 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/UiCommandDetail.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/UiCommandDetail.java @@ -21,5 +21,4 @@ public class UiCommandDetail { public String label; public String title; public boolean enabled; - public String confirmationMessage; } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiCommand.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PrivateInternals_UiActionDescription.java similarity index 58% rename from gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiCommand.java rename to gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PrivateInternals_UiActionDescription.java index c2eb395a5d..6545db8eb2 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiCommand.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PrivateInternals_UiActionDescription.java @@ -14,20 +14,20 @@ package com.google.gerrit.extensions.webui; -import com.google.gerrit.extensions.restapi.RestResource; -import com.google.gerrit.extensions.restapi.RestView; +/** + * Internal implementation helper for Gerrit Code Review server. + *

+ * Extensions and plugins should not invoke this class. + */ +public class PrivateInternals_UiActionDescription { + public static void setMethod(UiAction.Description d, String method) { + d.setMethod(method); + } -import java.util.Set; + public static void setId(UiAction.Description d, String id) { + d.setId(id); + } -public interface UiCommand extends RestView { - public static enum Place { - PATCHSET_ACTION_PANEL; - }; - - Set getPlaces(); - String getLabel(R resource); - String getTitle(R resource); - boolean isVisible(R resource); - boolean isEnabled(R resource); - String getConfirmationMessage(R resource); + private PrivateInternals_UiActionDescription() { + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiAction.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiAction.java new file mode 100644 index 0000000000..63172ce195 --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/UiAction.java @@ -0,0 +1,104 @@ +// Copyright (C) 2013 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.extensions.webui; + +import com.google.gerrit.extensions.restapi.RestResource; +import com.google.gerrit.extensions.restapi.RestView; + +public interface UiAction extends RestView { + /** + * Get the description of the action customized for the resource. + * + * @param resource the resource the view would act upon if the action is + * invoked by the client. Information from the resource can be used to + * customize the description. + * @return a description of the action. The server will populate the + * {@code id} and {@code method} properties. If null the action will + * assumed unavailable and not presented. This is usually the same as + * {@code setVisible(false)}. + */ + public Description getDescription(R resource); + + /** Describes an action invokable through the web interface. */ + public static class Description { + private String method; + private String id; + private String label; + private String title; + private boolean visible = true; + private boolean enabled = true; + + public String getMethod() { + return method; + } + + /** {@code PrivateInternals_UiActionDescription.setMethod()} */ + void setMethod(String method) { + this.method = method; + } + + public String getId() { + return id; + } + + /** {@code PrivateInternals_UiActionDescription.setId()} */ + void setId(String id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + /** Set the label to appear on the button to activate this action. */ + public Description setLabel(String label) { + this.label = label; + return this; + } + + public String getTitle() { + return title; + } + + /** Set the tool-tip text to appear when the mouse hovers on the button. */ + public Description setTitle(String title) { + this.title = title; + return this; + } + + public boolean isVisible() { + return visible; + } + + /** + * Set if the action's button is visible on screen for the current client. + * If not visible the action description may not be sent to the client. + */ + public Description setVisible(boolean visible) { + this.visible = visible; + return this; + } + + public boolean isEnabled() { + return enabled && isVisible(); + } + + /** Set if the button should be invokable (true), or greyed out (false). */ + public Description setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ActionButton.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ActionButton.java index 954413831d..80949e542c 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ActionButton.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ActionButton.java @@ -14,13 +14,13 @@ package com.google.gerrit.client.change; -import com.google.gerrit.client.ConfirmationCallback; -import com.google.gerrit.client.ConfirmationDialog; import com.google.gerrit.client.ErrorDialog; +import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.changes.ChangeApi; import com.google.gerrit.client.changes.ChangeInfo.ActionInfo; import com.google.gerrit.client.rpc.NativeString; import com.google.gerrit.client.rpc.RestApi; +import com.google.gerrit.common.PageLinks; import com.google.gerrit.reviewdb.client.Change; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.event.dom.client.ClickEvent; @@ -56,23 +56,6 @@ class ActionButton extends Button implements ClickHandler { @Override public void onClick(ClickEvent event) { - if (action.confirmation_message() != null - && !action.confirmation_message().isEmpty()) { - new ConfirmationDialog( - action.title(), - new SafeHtmlBuilder().append(action.confirmation_message()), - new ConfirmationCallback() { - @Override - public void onOk() { - send(); - } - }).center(); - } else { - send(); - } - } - - private void send() { setEnabled(false); AsyncCallback cb = new AsyncCallback() { @@ -86,9 +69,10 @@ class ActionButton extends Button implements ClickHandler { public void onSuccess(NativeString msg) { setEnabled(true); if (msg != null && !msg.asString().isEmpty()) { - // TODO Support better UI on UiCommand results. + // TODO Support better UI on UiAction results. Window.alert(msg.asString()); } + Gerrit.display(PageLinks.toChange2(changeId)); } }; diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeInfo.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeInfo.java index 8fad0536d7..cf73d79b99 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeInfo.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeInfo.java @@ -243,7 +243,6 @@ public class ChangeInfo extends JavaScriptObject { public final native String label() /*-{ return this.label; }-*/; public final native String title() /*-{ return this.title; }-*/; public final native boolean enabled() /*-{ return this.enabled || false; }-*/; - public final native String confirmation_message() /*-{ return this.confirmation_message; }-*/; protected ActionInfo() { } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index ab29aa5141..dded70b800 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -13,8 +13,6 @@ // limitations under the License. package com.google.gerrit.client.changes; -import com.google.gerrit.client.ConfirmationCallback; -import com.google.gerrit.client.ConfirmationDialog; import com.google.gerrit.client.Dispatcher; import com.google.gerrit.client.ErrorDialog; import com.google.gerrit.client.FormatUtil; @@ -53,11 +51,10 @@ import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DisclosurePanel; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.Image; 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.Panel; -import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder; import com.google.gwtjsonrpc.common.VoidResult; import java.util.HashSet; @@ -559,24 +556,6 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel b.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { - if (cmd.confirmationMessage != null && - !cmd.confirmationMessage.isEmpty()) { - ConfirmationDialog confirmationDialog = new ConfirmationDialog( - cmd.title, new SafeHtmlBuilder().append(cmd.confirmationMessage), - new ConfirmationCallback() { - @Override - public void onOk() { - postProcessCommand(cmd, b); - } - }); - confirmationDialog.center(); - } else { - postProcessCommand(cmd, b); - } - } - - private void postProcessCommand(final UiCommandDetail cmd, - final Button b) { b.setEnabled(false); AsyncCallback cb = new AsyncCallback() { @@ -592,6 +571,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel if (msg != null && !msg.asString().isEmpty()) { Window.alert(msg.asString()); } + Gerrit.display(PageLinks.toChange(patchSet.getId())); } }; RestApi api = ChangeApi.revision(patchSet.getId()).view(cmd.id); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetDetailFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetDetailFactory.java index 9287278f76..461a26341d 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetDetailFactory.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetDetailFactory.java @@ -14,9 +14,13 @@ package com.google.gerrit.httpd.rpc.changedetail; +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.google.gerrit.common.data.PatchSetDetail; +import com.google.gerrit.common.data.UiCommandDetail; import com.google.gerrit.common.errors.NoSuchEntityException; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.httpd.rpc.Handler; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountDiffPreference; @@ -32,7 +36,7 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.change.ChangeResource; import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.change.Revisions; -import com.google.gerrit.server.extensions.webui.UiCommands; +import com.google.gerrit.server.extensions.webui.UiActions; import com.google.gerrit.server.patch.PatchList; import com.google.gerrit.server.patch.PatchListCache; import com.google.gerrit.server.patch.PatchListKey; @@ -49,7 +53,6 @@ import org.eclipse.jgit.lib.ObjectId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -173,10 +176,22 @@ class PatchSetDetailFactory extends Handler { } } - detail.setCommands(UiCommands.sorted(UiCommands.plugins(UiCommands.from( - revisions, - new RevisionResource(new ChangeResource(control), patchSet), - EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))))); + detail.setCommands(Lists.newArrayList(Iterables.transform( + UiActions.sorted(UiActions.plugins(UiActions.from( + revisions, + new RevisionResource(new ChangeResource(control), patchSet)))), + new Function() { + @Override + public UiCommandDetail apply(UiAction.Description in) { + UiCommandDetail r = new UiCommandDetail(); + r.method = in.getMethod(); + r.id = in.getId(); + r.label = in.getLabel(); + r.title = in.getTitle(); + r.enabled = in.isEnabled(); + return r; + } + }))); return detail; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java index 388f0c7fe9..6b4c0e06c8 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java @@ -21,7 +21,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -42,11 +42,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; public class Abandon implements RestModifyView, - UiCommand { + UiAction { private static final Logger log = LoggerFactory.getLogger(Abandon.class); private final ChangeHooks hooks; @@ -133,34 +131,11 @@ public class Abandon implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(ChangeResource resource) { - return "Abandon"; - } - - @Override - public String getTitle(ChangeResource resource) { - return null; - } - - @Override - public boolean isVisible(ChangeResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(ChangeResource resource) { - return resource.getChange().getStatus().isOpen() - && resource.getControl().canAbandon(); - } - - @Override - public String getConfirmationMessage(ChangeResource resource) { - return null; + public UiAction.Description getDescription(ChangeResource resource) { + return new UiAction.Description() + .setLabel("Abandon") + .setVisible(resource.getChange().getStatus().isOpen() + && resource.getControl().canAbandon()); } private ChangeMessage newMessage(Input input, IdentifiedUser caller, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java index 7a9a879be5..6258d5a4c9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java @@ -46,11 +46,10 @@ import com.google.gerrit.common.data.LabelValue; import com.google.gerrit.common.data.Permission; import com.google.gerrit.common.data.PermissionRange; import com.google.gerrit.common.data.SubmitRecord; -import com.google.gerrit.common.data.UiCommandDetail; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.restapi.Url; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change.Status; @@ -68,7 +67,7 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.account.AccountInfo; import com.google.gerrit.server.config.CanonicalWebUrl; import com.google.gerrit.server.config.GerritServerConfig; -import com.google.gerrit.server.extensions.webui.UiCommands; +import com.google.gerrit.server.extensions.webui.UiActions; import com.google.gerrit.server.git.LabelNormalizer; import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.patch.PatchSetInfoFactory; @@ -293,11 +292,10 @@ public class ChangeJson { if (has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) { out.actions = Maps.newTreeMap(); - for (UiCommandDetail c : UiCommands.from( + for (UiAction.Description d : UiActions.from( changes, - new ChangeResource(control(cd)), - EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) { - out.actions.put(c.id, new ActionInfo(c)); + new ChangeResource(control(cd)))) { + out.actions.put(d.getId(), new ActionInfo(d)); } } lastControl = null; @@ -794,11 +792,10 @@ public class ChangeJson { if (out.isCurrent && has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) { out.actions = Maps.newTreeMap(); - for (UiCommandDetail c : UiCommands.from( + for (UiAction.Description d : UiActions.from( revisions, - new RevisionResource(new ChangeResource(control(cd)), in), - EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) { - out.actions.put(c.id, new ActionInfo(c)); + new RevisionResource(new ChangeResource(control(cd)), in))) { + out.actions.put(d.getId(), new ActionInfo(d)); } } return out; @@ -983,14 +980,12 @@ public class ChangeJson { String label; String title; Boolean enabled; - String confirmationMessage; - ActionInfo(UiCommandDetail c) { - method = c.method; - label = c.label; - title = c.title; - enabled = c.enabled ? true : null; - confirmationMessage = c.confirmationMessage; + ActionInfo(UiAction.Description d) { + method = d.getMethod(); + label = d.getLabel(); + title = d.getTitle(); + enabled = d.isEnabled() ? true : null; } } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java index 83a2b48d50..18f45bb0aa 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java @@ -18,7 +18,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -30,11 +30,8 @@ import com.google.gerrit.server.project.RefControl; import com.google.inject.Inject; import com.google.inject.Provider; -import java.util.EnumSet; -import java.util.Set; - class CherryPick implements RestModifyView, - UiCommand { + UiAction { private final Provider dbProvider; private final Provider cherryPickChange; private final ChangeJson json; @@ -96,32 +93,10 @@ class CherryPick implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(RevisionResource resource) { - return "Cherry Pick To"; - } - - @Override - public String getTitle(RevisionResource resource) { - return "Cherry pick change to a different branch"; - } - - @Override - public boolean isVisible(RevisionResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(RevisionResource resource) { - return resource.getControl().getProjectControl().canUpload(); - } - - @Override - public String getConfirmationMessage(RevisionResource resource) { - return null; + public UiAction.Description getDescription(RevisionResource resource) { + return new UiAction.Description() + .setLabel("Cherry Pick") + .setTitle("Cherry pick change to a different branch") + .setVisible(resource.getControl().getProjectControl().canUpload()); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java index 3fcdb0c483..108756e92e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java @@ -22,7 +22,7 @@ import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -36,11 +36,9 @@ import com.google.inject.Inject; import com.google.inject.Provider; import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; class PutTopic implements RestModifyView, - UiCommand { + UiAction { private final Provider dbProvider; private final ChangeIndexer indexer; private final ChangeHooks hooks; @@ -119,32 +117,9 @@ class PutTopic implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(ChangeResource resource) { - return "Edit Topic"; - } - - @Override - public String getTitle(ChangeResource resource) { - return null; - } - - @Override - public boolean isVisible(ChangeResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(ChangeResource resource) { - return resource.getControl().canEditTopicName(); - } - - @Override - public String getConfirmationMessage(ChangeResource resource) { - return null; + public UiAction.Description getDescription(ChangeResource resource) { + return new UiAction.Description() + .setLabel("Edit Topic") + .setVisible(resource.getControl().canEditTopicName()); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java index 7c8fc96ad7..3831c20acc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java @@ -20,7 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -35,11 +35,9 @@ import com.google.inject.Inject; import com.google.inject.Provider; import java.io.IOException; -import java.util.EnumSet; -import java.util.Set; public class Rebase implements RestModifyView, - UiCommand { + UiAction { public static class Input { } @@ -81,35 +79,13 @@ public class Rebase implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(RevisionResource resource) { - return "Rebase"; - } - - @Override - public String getTitle(RevisionResource resource) { - return "Rebase onto tip of branch or parent change"; - } - - @Override - public boolean isVisible(RevisionResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(RevisionResource resource) { - return resource.getChange().getStatus().isOpen() - && resource.getControl().canRebase() - && rebaseChange.get().canRebase(resource); - } - - @Override - public String getConfirmationMessage(RevisionResource resource) { - return null; + public UiAction.Description getDescription(RevisionResource resource) { + return new UiAction.Description() + .setLabel("Rebase") + .setTitle("Rebase onto tip of branch or parent change") + .setVisible(resource.getChange().getStatus().isOpen() + && resource.getControl().canRebase() + && rebaseChange.get().canRebase(resource)); } public static class CurrentRevision implements diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java index 874b4991da..581c4ba919 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java @@ -20,7 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change.Status; import com.google.gerrit.reviewdb.client.ChangeMessage; @@ -42,11 +42,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; public class Restore implements RestModifyView, - UiCommand { + UiAction { private static final Logger log = LoggerFactory.getLogger(Restore.class); private final ChangeHooks hooks; @@ -94,8 +92,8 @@ public class Restore implements RestModifyView, new AtomicUpdate() { @Override public Change update(Change change) { - if (change.getStatus() == Change.Status.ABANDONED) { - change.setStatus(Change.Status.NEW); + if (change.getStatus() == Status.ABANDONED) { + change.setStatus(Status.NEW); ChangeUtil.updated(change); return change; } @@ -132,34 +130,11 @@ public class Restore implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(ChangeResource resource) { - return "Restore"; - } - - @Override - public String getTitle(ChangeResource resource) { - return null; - } - - @Override - public boolean isVisible(ChangeResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(ChangeResource resource) { - return resource.getChange().getStatus() == Change.Status.ABANDONED - && resource.getControl().canRestore(); - } - - @Override - public String getConfirmationMessage(ChangeResource resource) { - return null; + public UiAction.Description getDescription(ChangeResource resource) { + return new UiAction.Description() + .setLabel("Restore") + .setVisible(resource.getChange().getStatus() == Status.ABANDONED + && resource.getControl().canRestore()); } private ChangeMessage newMessage(Input input, IdentifiedUser caller, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java index efc6beacbc..1d4ad710b9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java @@ -20,7 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change.Status; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -41,11 +41,8 @@ import com.google.inject.Provider; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; -import java.util.EnumSet; -import java.util.Set; - public class Revert implements RestModifyView, - UiCommand { + UiAction { private final ChangeHooks hooks; private final RevertedSender.Factory revertedSenderFactory; private final CommitValidators.Factory commitValidatorsFactory; @@ -113,34 +110,11 @@ public class Revert implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(ChangeResource resource) { - return "Revert"; - } - - @Override - public String getTitle(ChangeResource resource) { - return null; - } - - @Override - public boolean isVisible(ChangeResource resource) { - return isEnabled(resource); - } - - @Override - public boolean isEnabled(ChangeResource resource) { - return resource.getChange().getStatus() == Change.Status.MERGED - && resource.getControl().getRefControl().canUpload(); - } - - @Override - public String getConfirmationMessage(ChangeResource resource) { - return null; + public UiAction.Description getDescription(ChangeResource resource) { + return new UiAction.Description() + .setLabel("Revert") + .setVisible(resource.getChange().getStatus() == Status.MERGED + && resource.getControl().getRefControl().canUpload()); } private static String status(Change change) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java index df26c2e77b..0db520899f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java @@ -24,7 +24,7 @@ import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.client.PatchSet; @@ -50,12 +50,10 @@ import java.io.IOException; import java.sql.Timestamp; import java.util.Collection; import java.util.Collections; -import java.util.EnumSet; import java.util.List; -import java.util.Set; public class Submit implements RestModifyView, - UiCommand { + UiAction { public static class Input { public boolean waitForMerge; } @@ -145,41 +143,15 @@ public class Submit implements RestModifyView, } @Override - public Set getPlaces() { - return EnumSet.of(Place.PATCHSET_ACTION_PANEL); - } - - @Override - public String getLabel(RevisionResource resource) { - return String.format( - "Submit Patch Set %d", - resource.getPatchSet().getPatchSetId()); - } - - @Override - public String getTitle(RevisionResource resource) { - return null; - } - - @Override - public boolean isVisible(RevisionResource resource) { + public UiAction.Description getDescription(RevisionResource resource) { PatchSet.Id current = resource.getChange().currentPatchSetId(); - return resource.getChange().getStatus().isOpen() - && resource.getPatchSet().getId().equals(current) - && isEnabled(resource); - } - - @Override - public boolean isEnabled(RevisionResource resource) { - // Enable based on approximation. If the user has permission enable, - // even if the change has not reached as submittable state according - // to the project rules. - return resource.getControl().canSubmit(); - } - - @Override - public String getConfirmationMessage(RevisionResource resource) { - return null; + return new UiAction.Description() + .setLabel(String.format( + "Submit Revision %d", + resource.getPatchSet().getPatchSetId())) + .setVisible(resource.getChange().getStatus().isOpen() + && resource.getPatchSet().getId().equals(current) + && resource.getControl().canSubmit()); } /** diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiCommands.java b/gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiActions.java similarity index 51% rename from gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiCommands.java rename to gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiActions.java index b39c65f507..9aae367a8e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiCommands.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/extensions/webui/UiActions.java @@ -19,82 +19,76 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.gerrit.common.data.UiCommandDetail; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.RestCollection; import com.google.gerrit.extensions.restapi.RestResource; import com.google.gerrit.extensions.restapi.RestView; -import com.google.gerrit.extensions.webui.UiCommand; +import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription; +import com.google.gerrit.extensions.webui.UiAction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.Comparator; -import java.util.EnumSet; import java.util.List; import javax.annotation.Nullable; -public class UiCommands { - private static final Logger log = LoggerFactory.getLogger(UiCommands.class); +public class UiActions { + private static final Logger log = LoggerFactory.getLogger(UiActions.class); - public static Predicate enabled() { - return new Predicate() { + public static Predicate enabled() { + return new Predicate() { @Override - public boolean apply(UiCommandDetail input) { - return input.enabled; + public boolean apply(UiAction.Description input) { + return input.isEnabled(); } }; } - public static List sorted(Iterable in) { - List s = Lists.newArrayList(in); - Collections.sort(s, new Comparator() { + public static List sorted(Iterable in) { + List s = Lists.newArrayList(in); + Collections.sort(s, new Comparator() { @Override - public int compare(UiCommandDetail a, UiCommandDetail b) { - return a.id.compareTo(b.id); + public int compare(UiAction.Description a, UiAction.Description b) { + return a.getId().compareTo(b.getId()); } }); return s; } - public static Iterable plugins(Iterable in) { + public static Iterable plugins(Iterable in) { return Iterables.filter(in, - new Predicate() { + new Predicate() { @Override - public boolean apply(UiCommandDetail input) { - return input.id.indexOf('~') > 0; + public boolean apply(UiAction.Description input) { + return input.getId().indexOf('~') > 0; } }); } - public static Iterable from( + public static Iterable from( RestCollection collection, - R resource, - EnumSet places) { - return from(collection.views(), resource, places); + R resource) { + return from(collection.views(), resource); } - public static Iterable from( + public static Iterable from( DynamicMap> views, - final R resource, - final EnumSet places) { + final R resource) { return Iterables.filter( Iterables.transform( views, - new Function>, UiCommandDetail> () { + new Function>, UiAction.Description> () { @Override @Nullable - public UiCommandDetail apply(DynamicMap.Entry> e) { + public UiAction.Description apply(DynamicMap.Entry> e) { int d = e.getExportName().indexOf('.'); if (d < 0) { return null; } - String method = e.getExportName().substring(0, d); - String name = e.getExportName().substring(d + 1); RestView view; try { view = e.getProvider().get(); @@ -105,31 +99,31 @@ public class UiCommands { return null; } - if (!(view instanceof UiCommand)) { + if (!(view instanceof UiAction)) { return null; } - UiCommand cmd = (UiCommand) view; - if (Sets.intersection(cmd.getPlaces(), places).isEmpty() - || !cmd.isVisible(resource)) { + UiAction.Description dsc = + ((UiAction) view).getDescription(resource); + if (dsc == null || !dsc.isVisible()) { return null; } - UiCommandDetail dsc = new UiCommandDetail(); - dsc.id = "gerrit".equals(e.getPluginName()) - ? name - : e.getPluginName() + '~' + name; - dsc.method = method; - dsc.label = cmd.getLabel(resource); - dsc.title = cmd.getTitle(resource); - dsc.enabled = cmd.isEnabled(resource); - dsc.confirmationMessage = cmd.getConfirmationMessage(resource); + String name = e.getExportName().substring(d + 1); + PrivateInternals_UiActionDescription.setMethod( + dsc, + e.getExportName().substring(0, d)); + PrivateInternals_UiActionDescription.setId( + dsc, + "gerrit".equals(e.getPluginName()) + ? name + : e.getPluginName() + '~' + name); return dsc; } }), Predicates.notNull()); } - private UiCommands() { + private UiActions() { } }