private Group value = null;
- private final boolean supportFlag;
+ private final boolean bySupporter;
- public GroupSelector(String name, boolean supportFlag) {
+ public GroupSelector(String name, boolean bySupporter) {
this.name = HTMLEncoder.encodeHTML(name);
- this.supportFlag = supportFlag;
+ this.bySupporter = bySupporter;
}
public void update(HttpServletRequest r) throws GigiApiException {
String vS = r.getParameter(name);
- value = null;
- for (Group g : Group.values()) {
- if (g.getDatabaseName().equals(vS)) {
- value = g;
- }
+ if (vS == null) {
+ throw new GigiApiException("No value for group.");
+ }
+ try {
+ value = Group.getByString(vS);
+ } catch (IllegalArgumentException e) {
+ throw new GigiApiException("Invalid value for group.");
}
}
public void output(PrintWriter out, Language l, Map<String, Object> vars) {
out.println("<select name='" + name + "'>");
for (Group g : Group.values()) {
- if (supportFlag == g.isManagedBySupport()) {
- out.print("<option value='" + g.getDatabaseName());
+ if (mayManage(g)) {
+ out.print("<option value='" + g.getDBName());
if (g.equals(value)) {
out.print(" selected");
}
out.println("</select>");
}
+ private boolean mayManage(Group g) {
+ return (bySupporter && g.isManagedBySupport()) || ( !bySupporter && g.isManagedByUser());
+ }
+
public Group getGroup() {
return value;
}