Support boolean project specific plugin parameters for edit in UI

Change-Id: I2a2955f3e1f158b5aa6d0f45fb5adf5ef7da6e84
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-11-28 16:55:22 +01:00
parent 71dd06291e
commit a6c1c45f48
5 changed files with 38 additions and 8 deletions

View File

@@ -688,15 +688,21 @@ parameter. The export name must be a valid Git variable name. The
variable name is case-insensitive, allows only alphanumeric characters variable name is case-insensitive, allows only alphanumeric characters
and '-', and must start with an alphabetic character. and '-', and must start with an alphabetic character.
The example below shows how the parameter `plugin.helloworld.language` The example below shows how the parameters `plugin.helloworld.enabled`
is bound to be editable from the WebUI. "Preferred Language" is and `plugin.helloworld.language` are bound to be editable from the
provided as display name and "en" is set as default value. WebUI. For the parameter `plugin.helloworld.enabled` "Enable Greeting"
is provided as display name and the default value is set to `true`.
For the parameter `plugin.helloworld.language` "Preferred Language"
is provided as display name and "en" is set as default value.
[source,java] [source,java]
---- ----
class Module extends AbstractModule { class Module extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named("enabled"))
.toInstance(new ProjectConfigEntry("Enable Greeting", true));
bind(ProjectConfigEntry.class) bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named("language")) .annotatedWith(Exports.named("language"))
.toInstance(new ProjectConfigEntry("Preferred Language", "en")); .toInstance(new ProjectConfigEntry("Preferred Language", "en"));

View File

@@ -1295,8 +1295,8 @@ parameter.
|`display_name` |optional| |`display_name` |optional|
The display name of the configuration parameter. The display name of the configuration parameter.
|`type` || |`type` ||
The type of the configuration parameter, can be `STRING`, `INT` or The type of the configuration parameter, can be `STRING`, `INT`, `LONG`
`LONG`. or `BOOLEAN`.
|`value` |optional| |`value` |optional|
The value of the configuration parameter as string. The value of the configuration parameter as string.
|=============================== |===============================

View File

@@ -42,6 +42,7 @@ import com.google.gwt.event.dom.client.ChangeHandler;
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.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusWidget; import com.google.gwt.user.client.ui.FocusWidget;
@@ -368,6 +369,8 @@ public class ProjectInfoScreen extends ProjectScreen {
w = renderTextBox(g, param, false); w = renderTextBox(g, param, false);
} else if ("INT".equals(param.type()) || "LONG".equals(param.type())) { } else if ("INT".equals(param.type()) || "LONG".equals(param.type())) {
w = renderTextBox(g, param, true); w = renderTextBox(g, param, true);
} else if ("BOOLEAN".equals(param.type())) {
w = renderCheckBox(g, param);
} else { } else {
continue; continue;
} }
@@ -382,12 +385,24 @@ public class ProjectInfoScreen extends ProjectScreen {
ConfigParameterInfo param, boolean numbersOnly) { ConfigParameterInfo param, boolean numbersOnly) {
NpTextBox textBox = numbersOnly ? new NpIntTextBox() : new NpTextBox(); NpTextBox textBox = numbersOnly ? new NpIntTextBox() : new NpTextBox();
textBox.setValue(param.value()); textBox.setValue(param.value());
g.add(param.displayName() != null g.add(getDisplayName(param), textBox);
? param.displayName() : param.name(), textBox);
saveEnabler.listenTo(textBox); saveEnabler.listenTo(textBox);
return textBox; return textBox;
} }
private CheckBox renderCheckBox(LabeledWidgetsGrid g,
ConfigParameterInfo param) {
CheckBox checkBox = new CheckBox(getDisplayName(param));
checkBox.setValue(Boolean.parseBoolean(param.value()));
g.add(null, checkBox);
saveEnabler.listenTo(checkBox);
return checkBox;
}
private String getDisplayName(ConfigParameterInfo param) {
return param.displayName() != null ? param.displayName() : param.name();
}
private void initProjectActions(ConfigInfo info) { private void initProjectActions(ConfigInfo info) {
actionsGrid.clear(true); actionsGrid.clear(true);
actionsGrid.removeAllRows(); actionsGrid.removeAllRows();
@@ -443,6 +458,8 @@ public class ProjectInfoScreen extends ProjectScreen {
FocusWidget widget = e2.getValue(); FocusWidget widget = e2.getValue();
if (widget instanceof TextBox) { if (widget instanceof TextBox) {
values.put(e2.getKey(), ((TextBox) widget).getValue().trim()); values.put(e2.getKey(), ((TextBox) widget).getValue().trim());
} else if (widget instanceof CheckBox) {
values.put(e2.getKey(), Boolean.toString(((CheckBox) widget).getValue()));
} }
} }
} }

View File

@@ -19,7 +19,7 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
@ExtensionPoint @ExtensionPoint
public class ProjectConfigEntry { public class ProjectConfigEntry {
public enum Type { public enum Type {
STRING, INT, LONG STRING, INT, LONG, BOOLEAN
} }
private final String displayName; private final String displayName;
@@ -38,6 +38,10 @@ public class ProjectConfigEntry {
this(displayName, Long.toString(defaultValue), Type.LONG); this(displayName, Long.toString(defaultValue), Type.LONG);
} }
public ProjectConfigEntry(String displayName, boolean defaultValue) {
this(displayName, Boolean.toString(defaultValue), Type.BOOLEAN);
}
private ProjectConfigEntry(String displayName, String defaultValue, Type type) { private ProjectConfigEntry(String displayName, String defaultValue, Type type) {
this.displayName = displayName; this.displayName = displayName;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;

View File

@@ -192,6 +192,9 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
if (v.getValue() != null) { if (v.getValue() != null) {
try { try {
switch (projectConfigEntry.getType()) { switch (projectConfigEntry.getType()) {
case BOOLEAN:
cfg.setBoolean(v.getKey(), Boolean.parseBoolean(v.getValue()));
break;
case INT: case INT:
cfg.setInt(v.getKey(), Integer.parseInt(v.getValue())); cfg.setInt(v.getKey(), Integer.parseInt(v.getValue()));
break; break;