source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/FacetsPanel.java @ 4661

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

Package structure: separated solr services from other services and moved all panels into new wicket.panels package

File size: 3.1 KB
Line 
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 */
17package eu.clarin.cmdi.vlo.wicket.panels;
18
19import eu.clarin.cmdi.vlo.pojo.ExpansionState;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.wicket.model.FacetExpansionStateModel;
22import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
23import java.util.HashMap;
24import java.util.List;
25import java.util.Map;
26import org.apache.solr.client.solrj.response.FacetField;
27import org.apache.wicket.ajax.AjaxRequestTarget;
28import org.apache.wicket.markup.html.list.ListItem;
29import org.apache.wicket.markup.html.list.ListView;
30import org.apache.wicket.markup.html.panel.Panel;
31import org.apache.wicket.model.IModel;
32import 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 */
42public 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}
Note: See TracBrowser for help on using the repository browser.