1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.vlo.wicket.panels; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.pojo.ExpansionState; |
---|
20 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
21 | import eu.clarin.cmdi.vlo.wicket.model.FacetExpansionStateModel; |
---|
22 | import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel; |
---|
23 | import java.util.HashMap; |
---|
24 | import java.util.List; |
---|
25 | import java.util.Map; |
---|
26 | import org.apache.solr.client.solrj.response.FacetField; |
---|
27 | import org.apache.wicket.ajax.AjaxRequestTarget; |
---|
28 | import org.apache.wicket.markup.html.list.ListItem; |
---|
29 | import org.apache.wicket.markup.html.list.ListView; |
---|
30 | import org.apache.wicket.markup.html.panel.Panel; |
---|
31 | import org.apache.wicket.model.IModel; |
---|
32 | import org.apache.wicket.model.util.MapModel; |
---|
33 | |
---|
34 | /** |
---|
35 | * A panel representing a group of facets. |
---|
36 | * |
---|
37 | * For each facet present in the provided list model, a {@link FacetPanel} is |
---|
38 | * added to the a list view. |
---|
39 | * |
---|
40 | * @author twagoo |
---|
41 | */ |
---|
42 | public abstract class FacetsPanel extends Panel { |
---|
43 | |
---|
44 | /** |
---|
45 | * |
---|
46 | * @param id component id |
---|
47 | * @param facetsModel model that provides the list of facets to show in this |
---|
48 | * panel |
---|
49 | * @param selectionModel model representing the current query/value |
---|
50 | * selection state |
---|
51 | */ |
---|
52 | public FacetsPanel(final String id, final IModel<List<FacetField>> facetsModel, final IModel<QueryFacetsSelection> selectionModel) { |
---|
53 | super(id); |
---|
54 | |
---|
55 | final Map<String, ExpansionState> expansionStateMap = new HashMap<String, ExpansionState>(); |
---|
56 | final MapModel<String, ExpansionState> expansionModel = new MapModel<String, ExpansionState>(expansionStateMap); |
---|
57 | |
---|
58 | final ListView<FacetField> facetsView = new ListView<FacetField>("facets", facetsModel) { |
---|
59 | |
---|
60 | @Override |
---|
61 | protected void populateItem(ListItem<FacetField> item) { |
---|
62 | item.add( |
---|
63 | new FacetPanel("facet", |
---|
64 | new FacetSelectionModel(item.getModel(), selectionModel), |
---|
65 | new FacetExpansionStateModel(item.getModel(), expansionModel)) { |
---|
66 | |
---|
67 | @Override |
---|
68 | protected void selectionChanged(AjaxRequestTarget target) { |
---|
69 | FacetsPanel.this.selectionChanged(target); |
---|
70 | } |
---|
71 | } |
---|
72 | ); |
---|
73 | } |
---|
74 | }; |
---|
75 | // facet list is not dynamic, so reuse items |
---|
76 | facetsView.setReuseItems(true); |
---|
77 | add(facetsView); |
---|
78 | } |
---|
79 | |
---|
80 | protected abstract void selectionChanged(AjaxRequestTarget target); |
---|
81 | } |
---|