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.ajax.AjaxRequestTarget; |
---|
7 | import org.apache.wicket.ajax.markup.html.form.AjaxButton; |
---|
8 | import org.apache.wicket.extensions.markup.html.form.DateTextField; |
---|
9 | import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; |
---|
10 | import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.IFilterStateLocator; |
---|
11 | import org.apache.wicket.markup.html.WebMarkupContainer; |
---|
12 | import org.apache.wicket.markup.html.form.DropDownChoice; |
---|
13 | import org.apache.wicket.markup.html.form.EnumChoiceRenderer; |
---|
14 | import org.apache.wicket.markup.html.form.Form; |
---|
15 | import org.apache.wicket.markup.html.form.TextField; |
---|
16 | import org.apache.wicket.markup.html.panel.FeedbackPanel; |
---|
17 | import org.apache.wicket.markup.html.panel.Panel; |
---|
18 | import org.apache.wicket.model.CompoundPropertyModel; |
---|
19 | import org.apache.wicket.model.IModel; |
---|
20 | import org.apache.wicket.model.ResourceModel; |
---|
21 | import org.apache.wicket.validation.validator.StringValidator; |
---|
22 | |
---|
23 | import eu.clarin.cmdi.virtualcollectionregistry.QueryOptions; |
---|
24 | import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; |
---|
25 | |
---|
26 | @SuppressWarnings("serial") |
---|
27 | public class FilterForm extends Panel { |
---|
28 | private static final List<FilterState.SearchMode> MODE_VALUES = |
---|
29 | Arrays.asList(FilterState.SearchMode.values()); |
---|
30 | private static final List<VirtualCollection.State> STATE_VALUES = |
---|
31 | Arrays.asList(VirtualCollection.State.PUBLIC, |
---|
32 | VirtualCollection.State.PRIVATE, |
---|
33 | VirtualCollection.State.DELETED, |
---|
34 | VirtualCollection.State.PUBLIC_PENDING); |
---|
35 | private static final List<VirtualCollection.Type> TYPE_VALUES = |
---|
36 | Arrays.asList(VirtualCollection.Type.values()); |
---|
37 | private static final List<QueryOptions.Relation> CREATED_RELATIONS = |
---|
38 | Arrays.asList(QueryOptions.Relation.LT, |
---|
39 | QueryOptions.Relation.LE, |
---|
40 | QueryOptions.Relation.EQ, |
---|
41 | QueryOptions.Relation.GE, |
---|
42 | QueryOptions.Relation.GT); |
---|
43 | |
---|
44 | public FilterForm(String id, IFilterStateLocator<FilterState> locator, |
---|
45 | final DataTable<VirtualCollection> table, boolean privateMode) { |
---|
46 | super(id); |
---|
47 | setRenderBodyOnly(true); |
---|
48 | |
---|
49 | final IModel<FilterState> model = |
---|
50 | new CompoundPropertyModel<FilterState>(locator.getFilterState()); |
---|
51 | final Form<FilterState> form = new Form<FilterState>("form", model); |
---|
52 | form.setOutputMarkupId(true); |
---|
53 | |
---|
54 | final EnumChoiceRenderer<FilterState.SearchMode> searchModeRenderer = |
---|
55 | new EnumChoiceRenderer<FilterState.SearchMode>(this); |
---|
56 | form.add(new DropDownChoice<FilterState.SearchMode>("nameMode", |
---|
57 | MODE_VALUES, searchModeRenderer)); |
---|
58 | form.add(new TextField<String>("name") |
---|
59 | .add(new StringValidator.MaximumLengthValidator(255))); |
---|
60 | form.add(new DropDownChoice<FilterState.SearchMode>("descriptionMode", |
---|
61 | MODE_VALUES, searchModeRenderer)); |
---|
62 | form.add(new TextField<String>("description") |
---|
63 | .add(new StringValidator.MaximumLengthValidator(255))); |
---|
64 | final WebMarkupContainer state = new WebMarkupContainer("state"); |
---|
65 | state.add(new DropDownChoice<VirtualCollection.State>("state", |
---|
66 | STATE_VALUES, |
---|
67 | new EnumChoiceRenderer<VirtualCollection.State>(this))); |
---|
68 | state.setVisible(privateMode); |
---|
69 | form.add(state); |
---|
70 | form.add(new DropDownChoice<VirtualCollection.Type>("type", |
---|
71 | TYPE_VALUES, |
---|
72 | new EnumChoiceRenderer<VirtualCollection.Type>(this))); |
---|
73 | final DropDownChoice<QueryOptions.Relation> createdRelationChoice = |
---|
74 | new DropDownChoice<QueryOptions.Relation>("createdRelation", |
---|
75 | CREATED_RELATIONS, |
---|
76 | new EnumChoiceRenderer<QueryOptions.Relation>(this)); |
---|
77 | createdRelationChoice.setEscapeModelStrings(false); |
---|
78 | form.add(createdRelationChoice); |
---|
79 | form.add(new DateTextField("created", "yyyy-MM-dd")); |
---|
80 | |
---|
81 | final AjaxButton goButton = new AjaxButton("filter", |
---|
82 | new ResourceModel("button.filter")) { |
---|
83 | @Override |
---|
84 | protected void onSubmit(AjaxRequestTarget target, Form<?> form) { |
---|
85 | target.addComponent(form); |
---|
86 | target.addComponent(table); |
---|
87 | } |
---|
88 | |
---|
89 | @Override |
---|
90 | protected void onError(AjaxRequestTarget target, Form<?> form) { |
---|
91 | super.onError(target, form); |
---|
92 | target.addComponent(form); |
---|
93 | } |
---|
94 | }; |
---|
95 | form.add(goButton); |
---|
96 | final AjaxButton clearButton = new AjaxButton("clear", |
---|
97 | new ResourceModel("button.clear")) { |
---|
98 | @Override |
---|
99 | protected void onSubmit(AjaxRequestTarget target, Form<?> form) { |
---|
100 | @SuppressWarnings("unchecked") |
---|
101 | final FilterState state = |
---|
102 | ((Form<FilterState>) form).getModelObject(); |
---|
103 | state.clear(); |
---|
104 | target.addComponent(form); |
---|
105 | target.addComponent(table); |
---|
106 | } |
---|
107 | |
---|
108 | @Override |
---|
109 | protected void onError(AjaxRequestTarget target, Form<?> form) { |
---|
110 | super.onError(target, form); |
---|
111 | target.addComponent(form); |
---|
112 | } |
---|
113 | }; |
---|
114 | form.add(clearButton); |
---|
115 | add(form); |
---|
116 | } |
---|
117 | |
---|
118 | } // class FilterForm |
---|