Merge "Use StringListPanel to render ARRAY project plugin config params"
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.gwt.user.client.ui.CheckBox;
|
|||||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||||
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;
|
||||||
|
import com.google.gwt.user.client.ui.HasEnabled;
|
||||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
import com.google.gwt.user.client.ui.Image;
|
import com.google.gwt.user.client.ui.Image;
|
||||||
import com.google.gwt.user.client.ui.ImageResourceRenderer;
|
import com.google.gwt.user.client.ui.ImageResourceRenderer;
|
||||||
@@ -38,9 +39,9 @@ import com.google.gwtexpui.globalkey.client.NpTextBox;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StringListPanel extends FlowPanel {
|
public class StringListPanel extends FlowPanel implements HasEnabled {
|
||||||
private final StringListTable t;
|
private final StringListTable t;
|
||||||
private final HorizontalPanel titlePanel;
|
private HorizontalPanel titlePanel;
|
||||||
protected final HorizontalPanel buttonPanel;
|
protected final HorizontalPanel buttonPanel;
|
||||||
private final Button deleteButton;
|
private final Button deleteButton;
|
||||||
private Image info;
|
private Image info;
|
||||||
@@ -49,10 +50,12 @@ public class StringListPanel extends FlowPanel {
|
|||||||
public StringListPanel(String title, List<String> fieldNames, FocusWidget w,
|
public StringListPanel(String title, List<String> fieldNames, FocusWidget w,
|
||||||
boolean autoSort) {
|
boolean autoSort) {
|
||||||
widget = w;
|
widget = w;
|
||||||
titlePanel = new HorizontalPanel();
|
if (title != null) {
|
||||||
SmallHeading titleLabel = new SmallHeading(title);
|
titlePanel = new HorizontalPanel();
|
||||||
titlePanel.add(titleLabel);
|
SmallHeading titleLabel = new SmallHeading(title);
|
||||||
add(titlePanel);
|
titlePanel.add(titleLabel);
|
||||||
|
add(titlePanel);
|
||||||
|
}
|
||||||
|
|
||||||
t = new StringListTable(fieldNames, autoSort);
|
t = new StringListTable(fieldNames, autoSort);
|
||||||
add(t);
|
add(t);
|
||||||
@@ -77,7 +80,7 @@ public class StringListPanel extends FlowPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setInfo(String msg) {
|
public void setInfo(String msg) {
|
||||||
if (info == null) {
|
if (info == null && titlePanel != null) {
|
||||||
info = new Image(Gerrit.RESOURCES.info());
|
info = new Image(Gerrit.RESOURCES.info());
|
||||||
titlePanel.add(info);
|
titlePanel.add(info);
|
||||||
}
|
}
|
||||||
@@ -88,14 +91,24 @@ public class StringListPanel extends FlowPanel {
|
|||||||
return t.getValues();
|
return t.getValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getValues(int i) {
|
||||||
|
List<List<String>> allValuesList = getValues();
|
||||||
|
List<String> singleValueList = new ArrayList<>(allValuesList.size());
|
||||||
|
for (List<String> values : allValuesList) {
|
||||||
|
singleValueList.add(values.get(i));
|
||||||
|
}
|
||||||
|
return singleValueList;
|
||||||
|
}
|
||||||
|
|
||||||
private class StringListTable extends NavigationTable<List<String>> {
|
private class StringListTable extends NavigationTable<List<String>> {
|
||||||
|
private final Button addButton;
|
||||||
private final List<NpTextBox> inputs;
|
private final List<NpTextBox> inputs;
|
||||||
private final boolean autoSort;
|
private final boolean autoSort;
|
||||||
|
|
||||||
StringListTable(List<String> names, boolean autoSort) {
|
StringListTable(List<String> names, boolean autoSort) {
|
||||||
this.autoSort = autoSort;
|
this.autoSort = autoSort;
|
||||||
|
|
||||||
Button addButton =
|
addButton =
|
||||||
new Button(new ImageResourceRenderer().render(Gerrit.RESOURCES.listAdd()));
|
new Button(new ImageResourceRenderer().render(Gerrit.RESOURCES.listAdd()));
|
||||||
addButton.setTitle(Gerrit.C.stringListPanelAdd());
|
addButton.setTitle(Gerrit.C.stringListPanelAdd());
|
||||||
OnEditEnabler e = new OnEditEnabler(addButton);
|
OnEditEnabler e = new OnEditEnabler(addButton);
|
||||||
@@ -312,5 +325,30 @@ public class StringListPanel extends FlowPanel {
|
|||||||
protected Object getRowItemKey(List<String> item) {
|
protected Object getRowItemKey(List<String> item) {
|
||||||
return item.get(0);
|
return item.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setEnabled(boolean enabled) {
|
||||||
|
addButton.setVisible(enabled);
|
||||||
|
for (int row = 2; row < table.getRowCount(); row++) {
|
||||||
|
table.getWidget(row, 0).setVisible(enabled);
|
||||||
|
if (!autoSort) {
|
||||||
|
table.getWidget(row, inputs.size() + 1).setVisible(enabled);
|
||||||
|
table.getWidget(row, inputs.size() + 2).setVisible(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (enabled) {
|
||||||
|
updateNavigationLinks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return deleteButton.isVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
t.setEnabled(enabled);
|
||||||
|
deleteButton.setVisible(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.client.admin;
|
package com.google.gerrit.client.admin;
|
||||||
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.StringListPanel;
|
||||||
import com.google.gerrit.client.access.AccessMap;
|
import com.google.gerrit.client.access.AccessMap;
|
||||||
import com.google.gerrit.client.access.ProjectAccessInfo;
|
import com.google.gerrit.client.access.ProjectAccessInfo;
|
||||||
import com.google.gerrit.client.actions.ActionButton;
|
import com.google.gerrit.client.actions.ActionButton;
|
||||||
@@ -47,7 +48,7 @@ import com.google.gwt.user.client.ui.Button;
|
|||||||
import com.google.gwt.user.client.ui.CheckBox;
|
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.HasEnabled;
|
||||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
import com.google.gwt.user.client.ui.Image;
|
import com.google.gwt.user.client.ui.Image;
|
||||||
import com.google.gwt.user.client.ui.Label;
|
import com.google.gwt.user.client.ui.Label;
|
||||||
@@ -59,7 +60,10 @@ import com.google.gwt.user.client.ui.Widget;
|
|||||||
import com.google.gwtexpui.globalkey.client.NpTextArea;
|
import com.google.gwtexpui.globalkey.client.NpTextArea;
|
||||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@@ -77,7 +81,7 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
private ListBox contentMerge;
|
private ListBox contentMerge;
|
||||||
private NpTextBox maxObjectSizeLimit;
|
private NpTextBox maxObjectSizeLimit;
|
||||||
private Label effectiveMaxObjectSizeLimit;
|
private Label effectiveMaxObjectSizeLimit;
|
||||||
private Map<String, Map<String, FocusWidget>> pluginConfigWidgets;
|
private Map<String, Map<String, HasEnabled>> pluginConfigWidgets;
|
||||||
|
|
||||||
// Section: Contributor Agreements
|
// Section: Contributor Agreements
|
||||||
private ListBox contributorAgreements;
|
private ListBox contributorAgreements;
|
||||||
@@ -160,8 +164,8 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
maxObjectSizeLimit.setEnabled(isOwner);
|
maxObjectSizeLimit.setEnabled(isOwner);
|
||||||
|
|
||||||
if (pluginConfigWidgets != null) {
|
if (pluginConfigWidgets != null) {
|
||||||
for (Map<String, FocusWidget> widgetMap : pluginConfigWidgets.values()) {
|
for (Map<String, HasEnabled> widgetMap : pluginConfigWidgets.values()) {
|
||||||
for (FocusWidget widget : widgetMap.values()) {
|
for (HasEnabled widget : widgetMap.values()) {
|
||||||
widget.setEnabled(isOwner);
|
widget.setEnabled(isOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,7 +362,7 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
pluginConfigWidgets = new HashMap<>();
|
pluginConfigWidgets = new HashMap<>();
|
||||||
|
|
||||||
for (String pluginName : info.pluginConfig().keySet()) {
|
for (String pluginName : info.pluginConfig().keySet()) {
|
||||||
Map<String, FocusWidget> widgetMap = new HashMap<>();
|
Map<String, HasEnabled> widgetMap = new HashMap<>();
|
||||||
pluginConfigWidgets.put(pluginName, widgetMap);
|
pluginConfigWidgets.put(pluginName, widgetMap);
|
||||||
LabeledWidgetsGrid g = new LabeledWidgetsGrid();
|
LabeledWidgetsGrid g = new LabeledWidgetsGrid();
|
||||||
g.addHeader(new SmallHeading(Util.M.pluginProjectOptionsTitle(pluginName)));
|
g.addHeader(new SmallHeading(Util.M.pluginProjectOptionsTitle(pluginName)));
|
||||||
@@ -367,7 +371,7 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
info.pluginConfig(pluginName);
|
info.pluginConfig(pluginName);
|
||||||
pluginConfig.copyKeysIntoChildren("name");
|
pluginConfig.copyKeysIntoChildren("name");
|
||||||
for (ConfigParameterInfo param : Natives.asList(pluginConfig.values())) {
|
for (ConfigParameterInfo param : Natives.asList(pluginConfig.values())) {
|
||||||
FocusWidget w;
|
HasEnabled w;
|
||||||
switch (param.type()) {
|
switch (param.type()) {
|
||||||
case "STRING":
|
case "STRING":
|
||||||
case "INT":
|
case "INT":
|
||||||
@@ -381,7 +385,7 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
w = renderListBox(g, param);
|
w = renderListBox(g, param);
|
||||||
break;
|
break;
|
||||||
case "ARRAY":
|
case "ARRAY":
|
||||||
w = renderTextArea(g, param);
|
w = renderStringListPanel(g, param);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("unsupported widget type");
|
throw new UnsupportedOperationException("unsupported widget type");
|
||||||
@@ -498,24 +502,21 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
return listBox;
|
return listBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NpTextArea renderTextArea(LabeledWidgetsGrid g,
|
private StringListPanel renderStringListPanel(LabeledWidgetsGrid g,
|
||||||
ConfigParameterInfo param) {
|
ConfigParameterInfo param) {
|
||||||
NpTextArea txtArea = new NpTextArea();
|
StringListPanel p =
|
||||||
txtArea.setVisibleLines(4);
|
new StringListPanel(null, Arrays.asList(getDisplayName(param)),
|
||||||
txtArea.setCharacterWidth(40);
|
saveProject, false);
|
||||||
StringBuilder sb = new StringBuilder();
|
List<List<String>> values = new ArrayList<>();
|
||||||
for (int i = 0; i < param.values().length(); i++) {
|
for (String v : Natives.asList(param.values())) {
|
||||||
String v = param.values().get(i);
|
values.add(Arrays.asList(v));
|
||||||
sb.append(v).append("\n");
|
|
||||||
}
|
}
|
||||||
txtArea.setText(sb.toString());
|
p.display(values);
|
||||||
if (param.editable()) {
|
if (!param.editable()) {
|
||||||
saveEnabler.listenTo(txtArea);
|
p.setEnabled(false);
|
||||||
} else {
|
|
||||||
txtArea.setEnabled(false);
|
|
||||||
}
|
}
|
||||||
addWidget(g, txtArea, param);
|
addWidget(g, p, param);
|
||||||
return txtArea;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWidget(LabeledWidgetsGrid g, Widget w, ConfigParameterInfo param) {
|
private void addWidget(LabeledWidgetsGrid g, Widget w, ConfigParameterInfo param) {
|
||||||
@@ -590,11 +591,11 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
private Map<String, Map<String, ConfigParameterValue>> getPluginConfigValues() {
|
private Map<String, Map<String, ConfigParameterValue>> getPluginConfigValues() {
|
||||||
Map<String, Map<String, ConfigParameterValue>> pluginConfigValues =
|
Map<String, Map<String, ConfigParameterValue>> pluginConfigValues =
|
||||||
new HashMap<>(pluginConfigWidgets.size());
|
new HashMap<>(pluginConfigWidgets.size());
|
||||||
for (Entry<String, Map<String, FocusWidget>> e : pluginConfigWidgets.entrySet()) {
|
for (Entry<String, Map<String, HasEnabled>> e : pluginConfigWidgets.entrySet()) {
|
||||||
Map<String, ConfigParameterValue> values = new HashMap<>(e.getValue().size());
|
Map<String, ConfigParameterValue> values = new HashMap<>(e.getValue().size());
|
||||||
pluginConfigValues.put(e.getKey(), values);
|
pluginConfigValues.put(e.getKey(), values);
|
||||||
for (Entry<String, FocusWidget> e2 : e.getValue().entrySet()) {
|
for (Entry<String, HasEnabled> e2 : e.getValue().entrySet()) {
|
||||||
FocusWidget widget = e2.getValue();
|
HasEnabled widget = e2.getValue();
|
||||||
if (widget instanceof TextBox) {
|
if (widget instanceof TextBox) {
|
||||||
values.put(e2.getKey(), ConfigParameterValue.create()
|
values.put(e2.getKey(), ConfigParameterValue.create()
|
||||||
.value(((TextBox) widget).getValue().trim()));
|
.value(((TextBox) widget).getValue().trim()));
|
||||||
@@ -609,10 +610,11 @@ public class ProjectInfoScreen extends ProjectScreen {
|
|||||||
? listBox.getValue(listBox.getSelectedIndex()) : null;
|
? listBox.getValue(listBox.getSelectedIndex()) : null;
|
||||||
values.put(e2.getKey(), ConfigParameterValue.create()
|
values.put(e2.getKey(), ConfigParameterValue.create()
|
||||||
.value(value));
|
.value(value));
|
||||||
} else if (widget instanceof NpTextArea) {
|
} else if (widget instanceof StringListPanel) {
|
||||||
String text = ((NpTextArea) widget).getText().trim();
|
values.put(e2.getKey(),
|
||||||
values.put(e2.getKey(), ConfigParameterValue.create()
|
ConfigParameterValue.create().values(
|
||||||
.values(text.split("\n")));
|
((StringListPanel) widget).getValues(0)
|
||||||
|
.toArray(new String[] {})));
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("unsupported widget type");
|
throw new UnsupportedOperationException("unsupported widget type");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user