import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
{
final TextField newUser = new TextField("user", new Model(""));
final PasswordTextField passwordNewUser = new PasswordTextField("password", new Model(""));
- IModel<List<String>> groups = new LoadableDetachableModel<List<String>>() {
- @Override
- protected List<String> load() {
- return _userAdmin.getGroups();
- }
- };
- /*
- final DropDownChoice groupChoice =
- new DropDownChoice("group", new Model(""), groups, new IChoiceRenderer() {
- @Override
- public Object getDisplayValue(Object object) {
- return object.toString();
- }
-
- @Override
- public String getIdValue(Object object, int index) {
- if (index < 0) {
- return "";
- }
- return object.toString();
- }
- });
- */
Form createUserForm = new Form("createUserForm") {
@Override
protected void onSubmit() {
createUserForm.add(passwordNewUser);
// createUserForm.add(groupChoice);
}
+
+ {
+ IModel<List<String>> users = new LoadableDetachableModel<List<String>>() {
+ @Override
+ protected List<String> load() {
+ return _userAdmin.getUsers();
+ }
+ };
+ final DropDownChoice userChoice =
+ new DropDownChoice("userChoice", new Model(""), users, new MyChoiceRenderer());
+
+ IModel<List<String>> groups = new LoadableDetachableModel<List<String>>() {
+ @Override
+ protected List<String> load() {
+ return _userAdmin.getGroups();
+ }
+ };
+ final DropDownChoice groupChoice =
+ new DropDownChoice("groupChoice", new Model(""), groups, new MyChoiceRenderer());
+
+ Form userToGroupForm = new Form("userToGroupForm") {
+ @Override
+ protected void onSubmit() {
+ String user = userChoice.getValue();
+ String group = groupChoice.getValue();
+ if (!_userAdmin.getUsers().contains(user)) {
+ return;
+ }
+ if (!_userAdmin.getGroups().contains(group)) {
+ return;
+ }
+ if (_userAdmin.isInGroup(user, group)) {
+ info("User '" + user + "' is already in group '" + group + "'");
+ return;
+ }
+
+ try {
+ _userAdmin.addUserToGroup(user, group);
+ info("Added user '" + user + "' to group '" + group + "'");
+ }
+ catch (UserMgtException e) {
+ error("Could not add user '" + user + "' to group '" + group + "': " + e.getMessage());
+ }
+ }
+
+ ;
+ };
+ userToGroupForm.add(userChoice);
+ userToGroupForm.add(groupChoice);
+ add(userToGroupForm);
+ }
}
@Override
protected boolean isAdminPage() {
return true;
}
+
+ private static class MyChoiceRenderer implements IChoiceRenderer {
+
+ @Override
+ public Object getDisplayValue(Object object) {
+ return object.toString();
+ }
+
+ @Override
+ public String getIdValue(Object object, int index) {
+ if (index < 0) {
+ return "";
+ }
+ return object.toString();
+ }
+ }
}
\ No newline at end of file