source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetSelectionModel.java @ 4582

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

refactored construction of facet panels, both in facets panel and single collections facet panel

File size: 2.5 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.model;
18
19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import java.util.Collection;
22import java.util.Collections;
23import java.util.List;
24import java.util.concurrent.CopyOnWriteArrayList;
25import org.apache.solr.client.solrj.response.FacetField;
26import org.apache.wicket.model.AbstractReadOnlyModel;
27import org.apache.wicket.model.IModel;
28
29/**
30 * Model for FacetSelection that simply wraps a QueryFacetsSelection model and
31 * 'filters' for the specified facet
32 *
33 * @author twagoo
34 */
35public class FacetSelectionModel extends AbstractReadOnlyModel<FacetSelection> implements FacetSelection {
36
37    private final IModel<QueryFacetsSelection> selectionModel;
38    private final IModel<FacetField> facetFieldModel;
39
40    /**
41     *
42     * @param facetFieldModel
43     * @param selectionModel broad (multi-facet) selection model
44     */
45    public FacetSelectionModel(IModel<FacetField> facetFieldModel, IModel<QueryFacetsSelection> selectionModel) {
46        this.facetFieldModel = facetFieldModel;
47        this.selectionModel = selectionModel;
48    }
49
50    @Override
51    public FacetField getFacetField() {
52        return facetFieldModel.getObject();
53    }
54
55    @Override
56    public List<String> getFacetValues() {
57        final String facetName = getFacetField().getName();
58        final Collection<String> selectionValues = getSelection().getSelectionValues(facetName);
59        if (selectionValues == null) {
60            return Collections.emptyList();
61        } else {
62            return new CopyOnWriteArrayList<String>(selectionValues);
63        }
64    }
65
66    @Override
67    public QueryFacetsSelection getSelection() {
68        return selectionModel.getObject();
69    }
70
71    @Override
72    public FacetSelection getObject() {
73        return this;
74    }
75
76    @Override
77    public void detach() {
78        selectionModel.detach();
79    }
80
81}
Note: See TracBrowser for help on using the repository browser.