Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.extensions.webui; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.extensions.conditions.BooleanCondition; 19 : import com.google.gerrit.extensions.restapi.RestResource; 20 : import com.google.gerrit.extensions.restapi.RestView; 21 : 22 : public interface UiAction<R extends RestResource> extends RestView<R> { 23 : /** 24 : * Get the description of the action customized for the resource. 25 : * 26 : * @param resource the resource the view would act upon if the action is invoked by the client. 27 : * Information from the resource can be used to customize the description. 28 : * @return a description of the action. The server will populate the {@code id} and {@code method} 29 : * properties. If null the action will assumed unavailable and not presented. This is usually 30 : * the same as {@code setVisible(false)}. 31 : */ 32 : @Nullable 33 : Description getDescription(R resource) throws Exception; 34 : 35 : /** Describes an action invokable through the web interface. */ 36 61 : class Description { 37 : private String method; 38 : private String id; 39 : private String label; 40 : private String title; 41 61 : private BooleanCondition visible = BooleanCondition.TRUE; 42 61 : private BooleanCondition enabled = BooleanCondition.TRUE; 43 : 44 : public String getMethod() { 45 57 : return method; 46 : } 47 : 48 : /** {@code PrivateInternals_UiActionDescription.setMethod()} */ 49 : void setMethod(String method) { 50 61 : this.method = method; 51 61 : } 52 : 53 : public String getId() { 54 57 : return id; 55 : } 56 : 57 : /** {@code PrivateInternals_UiActionDescription.setId()} */ 58 : void setId(String id) { 59 61 : this.id = id; 60 61 : } 61 : 62 : public String getLabel() { 63 57 : return label; 64 : } 65 : 66 : /** Set the label to appear on the button to activate this action. */ 67 : public Description setLabel(String label) { 68 61 : this.label = label; 69 61 : return this; 70 : } 71 : 72 : public String getTitle() { 73 57 : return title; 74 : } 75 : 76 : /** Set the tool-tip text to appear when the mouse hovers on the button. */ 77 : public Description setTitle(String title) { 78 61 : this.title = title; 79 61 : return this; 80 : } 81 : 82 : public boolean isVisible() { 83 61 : return getVisibleCondition().value(); 84 : } 85 : 86 : public BooleanCondition getVisibleCondition() { 87 61 : return visible; 88 : } 89 : 90 : /** 91 : * Set if the action's button is visible on screen for the current client. If not visible the 92 : * action description may not be sent to the client. 93 : */ 94 : public Description setVisible(boolean visible) { 95 61 : return setVisible(BooleanCondition.valueOf(visible)); 96 : } 97 : 98 : /** 99 : * Set if the action's button is visible on screen for the current client. If not visible the 100 : * action description may not be sent to the client. 101 : */ 102 : public Description setVisible(BooleanCondition visible) { 103 61 : this.visible = visible; 104 61 : return this; 105 : } 106 : 107 : public boolean isEnabled() { 108 57 : return getEnabledCondition().value(); 109 : } 110 : 111 : public BooleanCondition getEnabledCondition() { 112 61 : return BooleanCondition.and(enabled, visible); 113 : } 114 : 115 : /** Set if the button should be invokable (true), or greyed out (false). */ 116 : public Description setEnabled(boolean enabled) { 117 50 : return setEnabled(BooleanCondition.valueOf(enabled)); 118 : } 119 : 120 : /** Set if the button should be invokable (true), or greyed out (false). */ 121 : public Description setEnabled(BooleanCondition enabled) { 122 50 : this.enabled = enabled; 123 50 : return this; 124 : } 125 : } 126 : }