1 | package eu.clarin.cmdi.virtualcollectionregistry.gui.pages; |
---|
2 | |
---|
3 | import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistry; |
---|
4 | import eu.clarin.cmdi.virtualcollectionregistry.gui.table.AdminCollectionsProvider; |
---|
5 | import eu.clarin.cmdi.virtualcollectionregistry.model.User; |
---|
6 | import java.util.ArrayList; |
---|
7 | import java.util.List; |
---|
8 | import org.apache.wicket.authorization.strategies.role.Roles; |
---|
9 | import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeAction; |
---|
10 | import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation; |
---|
11 | import org.apache.wicket.markup.html.form.DropDownChoice; |
---|
12 | import org.apache.wicket.markup.html.form.Form; |
---|
13 | import org.apache.wicket.markup.html.form.IChoiceRenderer; |
---|
14 | import org.apache.wicket.model.IModel; |
---|
15 | import org.apache.wicket.model.LoadableDetachableModel; |
---|
16 | import org.apache.wicket.model.Model; |
---|
17 | import 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}) |
---|
27 | public 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 |
---|