*/
package org.wamblee.photos.wicket;
+import java.util.List;
import java.util.logging.Logger;
+import javax.inject.Inject;
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.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.Model;
+import org.wamblee.security.authentication.UserAdministration;
+import org.wamblee.security.authentication.UserMgtException;
/**
* Homepage
private static final long serialVersionUID = 1L;
+ @Inject
+ private transient UserAdministration _userAdmin;
+
+ private TextField _groupName;
+
/**
* Constructor that is invoked when page is invoked without a session.
*
*/
public AdminPage(final PageParameters parameters) throws Exception {
super();
+
+ RepeatingView groupDelete = new RepeatingView("groupDelete") {
+ @Override
+ protected void onPopulate() {
+ removeAll();
+ List<String> groups = _userAdmin.getGroups();
+ for (final String group : groups) {
+ WebMarkupContainer container = new WebMarkupContainer(newChildId());
+ add(container);
+ container.add(new Label("groupName", group));
+ container.add(new Link("groupDelete") {
+ @Override
+ public void onClick() {
+ try {
+ _userAdmin.removeGroup(group);
+ info("Group '" + group + "' removed");
+ }
+ catch (UserMgtException e) {
+ error("Could not remove group '" + group + "'");
+ }
+ }
+
+ @Override
+ public boolean isVisible() {
+ return _userAdmin.getUsers(group).isEmpty();
+ }
+ });
+ }
+ }
+ };
+ add(groupDelete);
+
+ Form groupCreate = new Form("groupCreate") {
+ @Override
+ protected void onSubmit() {
+ String name = _groupName.getValue();
+ if (name == null || name.length() == 0) {
+ return;
+ }
+ try {
+ _userAdmin.createGroup(name);
+ _groupName.setModel(new Model(""));
+ info("Group '" + name + "' created");
+ }
+ catch (UserMgtException e) {
+ error("Group '" + name + "' could not be created");
+ }
+ }
+ };
+ add(groupCreate);
+ _groupName = new TextField("groupName", new Model(""));
+ groupCreate.add(_groupName);
}
@Override