source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/AbstractFacetsPanel.java @ 4579

Last change on this file since 4579 was 4579, checked in by twagoo, 10 years ago

Added single facet panel for collection selection

File size: 2.9 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.components;
18
19import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
20import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
21import java.util.Collection;
22import java.util.HashSet;
23import org.apache.solr.client.solrj.response.FacetField;
24import org.apache.wicket.ajax.AjaxRequestTarget;
25import org.apache.wicket.markup.html.panel.Panel;
26import org.apache.wicket.model.IModel;
27
28/**
29 *
30 * @author twagoo
31 */
32public abstract class AbstractFacetsPanel extends Panel {
33
34    protected final IModel<QueryFacetsSelection> model;
35
36    public AbstractFacetsPanel(String id, IModel<QueryFacetsSelection> model) {
37        super(id, model);
38        this.model = model;
39    }
40
41    protected FacetValuesPanel createFacetValuesPanel(String id, final IModel<FacetField> facetFieldModel) {
42        return new FacetValuesPanel(id, facetFieldModel) {
43            @Override
44            public void onValuesSelected(String facet, Collection<String> value, AjaxRequestTarget target) {
45                // A value has been selected on this facet's panel,
46                // update the model!
47                model.getObject().selectValues(facet, value);
48                if (target != null) {
49                    // reload entire page for now
50                    target.add(getPage());
51                }
52            }
53        };
54    }
55
56    protected SelectedFacetPanel createSelectedFacetPanel(String id, String facetName) {
57        return new SelectedFacetPanel(id, new FacetSelectionModel(facetName, model)) {
58            @Override
59            public void onValuesUnselected(String facet, Collection<String> valuesRemoved, AjaxRequestTarget target) {
60                // Values have been removed, calculate remainder
61                final Collection<String> currentSelection = model.getObject().getSelectionValues(facet);
62                final Collection<String> newSelection = new HashSet<String>(currentSelection);
63                newSelection.removeAll(valuesRemoved);
64                // Update model
65                model.getObject().selectValues(facet, newSelection);
66                if (target != null) {
67                    // reload entire page for now
68                    target.add(getPage());
69                }
70            }
71        };
72    }
73
74}
Note: See TracBrowser for help on using the repository browser.