1 | package eu.clarin.cmdi.virtualcollectionregistry.gui.table; |
---|
2 | |
---|
3 | import java.util.Arrays; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import org.apache.wicket.Component; |
---|
7 | import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; |
---|
8 | import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.ChoiceFilter; |
---|
9 | import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm; |
---|
10 | import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilteredAbstractColumn; |
---|
11 | import org.apache.wicket.markup.html.basic.Label; |
---|
12 | import org.apache.wicket.markup.html.form.EnumChoiceRenderer; |
---|
13 | import org.apache.wicket.markup.repeater.Item; |
---|
14 | import org.apache.wicket.model.IModel; |
---|
15 | import org.apache.wicket.model.PropertyModel; |
---|
16 | import org.apache.wicket.model.StringResourceModel; |
---|
17 | |
---|
18 | import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; |
---|
19 | |
---|
20 | @SuppressWarnings("serial") |
---|
21 | final class ColumnState extends FilteredAbstractColumn<VirtualCollection> { |
---|
22 | private final static List<VirtualCollection.State> STATE_VALUES = |
---|
23 | Arrays.asList(VirtualCollection.State.PRIVATE, |
---|
24 | VirtualCollection.State.PUBLIC, |
---|
25 | VirtualCollection.State.PUBLIC_PENDING, |
---|
26 | VirtualCollection.State.DELETED); |
---|
27 | private transient final VirtualCollectionTable table; |
---|
28 | |
---|
29 | ColumnState(VirtualCollectionTable table) { |
---|
30 | super(new StringResourceModel("column.state", table, null), "state"); |
---|
31 | this.table = table; |
---|
32 | } |
---|
33 | |
---|
34 | @Override |
---|
35 | public Component getFilter(String componentId, FilterForm<?> form) { |
---|
36 | final FilterState state = |
---|
37 | (FilterState) form.getStateLocator().getFilterState(); |
---|
38 | final IModel<VirtualCollection.State> model = |
---|
39 | new PropertyModel<VirtualCollection.State>(state, "state"); |
---|
40 | return new ChoiceFilter<VirtualCollection.State>(componentId, model, |
---|
41 | form, STATE_VALUES, |
---|
42 | new EnumChoiceRenderer<VirtualCollection.State>(table), false); |
---|
43 | } |
---|
44 | |
---|
45 | @Override |
---|
46 | public void populateItem( |
---|
47 | Item<ICellPopulator<VirtualCollection>> item, |
---|
48 | String componentId, IModel<VirtualCollection> model) { |
---|
49 | final VirtualCollection.State value = model.getObject().getState(); |
---|
50 | final String key = |
---|
51 | value.getDeclaringClass().getSimpleName() + "." + value.name(); |
---|
52 | item.add(new Label(componentId, |
---|
53 | new StringResourceModel(key, table, null))); |
---|
54 | } |
---|
55 | |
---|
56 | @Override |
---|
57 | public String getCssClass() { |
---|
58 | return "state"; |
---|
59 | } |
---|
60 | |
---|
61 | } // class ColumnState |
---|