Rewrite UI plugin action description API
Using methods on an interface that plugins/extensions implement makes for a very brittle API. We cannot safely add a new method without breaking all existing code or introducing another interface for plugins to implement. Change the UI action description to be a single method interface that returns an instance of a concrete description object. Plugins can populate the fields they know about and need for their use case, and the server will do its best to honor what the plugin has given. New methods can be added to the description without affecting the API versioning, enabling Gerrit to add more features in the future. The confirmation message feature has been removed. In the near future plugins will have the ability to register JavaScript code to be executed client-side when the button is activated and before the RPC is started. This will allow plugins to perform more custom logic, such as obtaining additional input. Looking even further ahead plugins may register their own JS handler to render a button, allowing the plugin to use a more complex widget. The UiAction.Description type may need to be extended to allow server side view code to pass custom data to the UI rendering logic. Change-Id: If5e0e6b42d6d1e8a111a2d304ce54b9d8834688a
This commit is contained in:
@@ -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.
|
||||
* <p>
|
||||
* 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<R extends RestResource> extends RestView<R> {
|
||||
public static enum Place {
|
||||
PATCHSET_ACTION_PANEL;
|
||||
};
|
||||
|
||||
Set<Place> getPlaces();
|
||||
String getLabel(R resource);
|
||||
String getTitle(R resource);
|
||||
boolean isVisible(R resource);
|
||||
boolean isEnabled(R resource);
|
||||
String getConfirmationMessage(R resource);
|
||||
private PrivateInternals_UiActionDescription() {
|
||||
}
|
||||
}
|
||||
@@ -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<R extends RestResource> extends RestView<R> {
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user