Support int/long project specific plugin parameters for edit in UI

Change-Id: Id406537bf81d749a953f12d94bd6214c52262827
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-11-28 16:43:34 +01:00
parent 9ce4f55626
commit 71dd06291e
4 changed files with 44 additions and 7 deletions

View File

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

View File

@@ -30,6 +30,7 @@ import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.NpIntTextBox;
import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.client.ui.SmallHeading;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
@@ -364,7 +365,9 @@ public class ProjectInfoScreen extends ProjectScreen {
for (ConfigParameterInfo param : Natives.asList(pluginConfig.values())) {
FocusWidget w;
if ("STRING".equals(param.type())) {
w = renderTextBox(g, param);
w = renderTextBox(g, param, false);
} else if ("INT".equals(param.type()) || "LONG".equals(param.type())) {
w = renderTextBox(g, param, true);
} else {
continue;
}
@@ -375,8 +378,9 @@ public class ProjectInfoScreen extends ProjectScreen {
enableForm();
}
private TextBox renderTextBox(LabeledWidgetsGrid g, ConfigParameterInfo param) {
NpTextBox textBox = new NpTextBox();
private TextBox renderTextBox(LabeledWidgetsGrid g,
ConfigParameterInfo param, boolean numbersOnly) {
NpTextBox textBox = numbersOnly ? new NpIntTextBox() : new NpTextBox();
textBox.setValue(param.value());
g.add(param.displayName() != null
? param.displayName() : param.name(), textBox);

View File

@@ -19,7 +19,7 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
@ExtensionPoint
public class ProjectConfigEntry {
public enum Type {
STRING
STRING, INT, LONG
}
private final String displayName;
@@ -27,9 +27,21 @@ public class ProjectConfigEntry {
private final Type type;
public ProjectConfigEntry(String displayName, String defaultValue) {
this(displayName, defaultValue, Type.STRING);
}
public ProjectConfigEntry(String displayName, int defaultValue) {
this(displayName, Integer.toString(defaultValue), Type.INT);
}
public ProjectConfigEntry(String displayName, long defaultValue) {
this(displayName, Long.toString(defaultValue), Type.LONG);
}
private ProjectConfigEntry(String displayName, String defaultValue, Type type) {
this.displayName = displayName;
this.defaultValue = defaultValue;
this.type = Type.STRING;
this.type = type;
}
public String getDisplayName() {

View File

@@ -190,7 +190,27 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
continue;
}
if (v.getValue() != null) {
try {
switch (projectConfigEntry.getType()) {
case INT:
cfg.setInt(v.getKey(), Integer.parseInt(v.getValue()));
break;
case LONG:
cfg.setLong(v.getKey(), Long.parseLong(v.getValue()));
break;
case STRING:
cfg.setString(v.getKey(), v.getValue());
break;
default:
log.warn(String.format(
"The type '%s' of parameter '%s' is not supported.",
projectConfigEntry.getType().name(), v.getKey()));
}
} catch (NumberFormatException ex) {
throw new BadRequestException(String.format(
"The value '%s' of config parameter '%s' of plugin '%s' is invalid: %s",
v.getValue(), v.getKey(), pluginName, ex.getMessage()));
}
} else {
cfg.unset(v.getKey());
}