source: VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/pages/AdminPage.java @ 5503

Last change on this file since 5503 was 5503, checked in by Twan Goosen, 10 years ago

Implemented the admin page, which now has a drop down selector for a "collections space" (published/user) and the same table as the one on the "browse private collections" page
Refs #589

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1package eu.clarin.cmdi.virtualcollectionregistry.gui.pages;
2
3import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistry;
4import eu.clarin.cmdi.virtualcollectionregistry.gui.table.AdminCollectionsProvider;
5import eu.clarin.cmdi.virtualcollectionregistry.model.User;
6import java.util.ArrayList;
7import java.util.List;
8import org.apache.wicket.authorization.strategies.role.Roles;
9import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeAction;
10import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
11import org.apache.wicket.markup.html.form.DropDownChoice;
12import org.apache.wicket.markup.html.form.Form;
13import org.apache.wicket.markup.html.form.IChoiceRenderer;
14import org.apache.wicket.model.IModel;
15import org.apache.wicket.model.LoadableDetachableModel;
16import org.apache.wicket.model.Model;
17import org.apache.wicket.spring.injection.annot.SpringBean;
18
19/**
20 * Page that allows the admin to select a "space" (public or user private) and
21 * show all collections in that space with options to edit/delete/publish
22 *
23 * @author twagoo
24 */
25@AuthorizeInstantiation(Roles.ADMIN)
26@AuthorizeAction(action = "ENABLE", roles = {Roles.ADMIN})
27public class AdminPage extends BasePage {
28
29    @SpringBean
30    private VirtualCollectionRegistry vc;
31
32    public AdminPage() {
33        super();
34
35        // user model shared between spaces form and the table's provider
36        final IModel<User> userModel = new Model<>(null);
37
38        // create form that allows admin to select a space
39        final Form spaceSelectForm = new Form("spaceSelectForm");
40        final DropDownChoice<User> spacesDropDown = createSpacesDropDown("space", userModel);
41        spaceSelectForm.add(spacesDropDown);
42        add(spaceSelectForm);
43
44        // create table showing the collections in the space
45        final AdminCollectionsProvider provider = new AdminCollectionsProvider(userModel);
46        add(new BrowseEditableCollectionsPanel("collections", provider));
47    }
48
49    private DropDownChoice<User> createSpacesDropDown(String id, final IModel<User> userModel) {
50        final IModel<List<User>> usersModel = new LoadableDetachableModel<List<User>>() {
51
52            @Override
53            protected List<User> load() {
54                final List<User> users = vc.getUsers();
55
56                // merge with a 'null' entry to represent the public space
57                final List<User> spaces = new ArrayList<>(users.size() + 1);
58                spaces.add(null);
59                spaces.addAll(users);
60                return spaces;
61            }
62        };
63        final IChoiceRenderer<User> choiceRenderer = new IChoiceRenderer<User>() {
64
65            @Override
66            public Object getDisplayValue(User user) {
67                if (user == null) {
68                    return "Published profiles";
69                } else {
70                    final String displayName = user.getDisplayName();
71                    if (displayName == null) {
72                        return user.getName();
73                    } else {
74                        return displayName;
75                    }
76                }
77            }
78
79            @Override
80            public String getIdValue(User user, int index) {
81                if (user == null) {
82                    return "___PUBLIC___";
83                } else {
84                    return user.getName();
85                }
86            }
87        };
88        final DropDownChoice<User> spacesDropDown = new DropDownChoice<>(id, userModel, usersModel, choiceRenderer);
89        spacesDropDown.setNullValid(true);
90        return spacesDropDown;
91    }
92
93} // class AdminPage
Note: See TracBrowser for help on using the repository browser.