source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/FacetValuesProvider.java @ 4500

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

using FacetField? as model class for facetpanel

File size: 2.3 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.service.impl;
18
19import eu.clarin.cmdi.vlo.service.FacetValuesService;
20import eu.clarin.cmdi.vlo.pojo.Facet;
21import eu.clarin.cmdi.vlo.pojo.FacetStatus;
22import eu.clarin.cmdi.vlo.pojo.FacetValue;
23import eu.clarin.cmdi.vlo.service.impl.FacetValuesProvider.FacetValuesSortProperty;
24import java.util.Iterator;
25import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
26import org.apache.wicket.model.IModel;
27import org.apache.wicket.model.Model;
28
29/**
30 *
31 * @author twagoo
32 */
33public class FacetValuesProvider extends SortableDataProvider<FacetValue, FacetValuesSortProperty> {
34
35    public enum FacetValuesSortProperty {
36
37        NAME,
38        COUNT
39    }
40    private final FacetValuesService fvService;
41    private final IModel<FacetStatus> status;
42    private final String filter;
43
44    public FacetValuesProvider(FacetValuesService fvService, IModel<FacetStatus> status, String filter) {
45        this.fvService = fvService;
46        this.status = status;
47        this.filter = filter;
48    }
49
50    @Override
51    public Iterator<? extends FacetValue> iterator(long first, long count) {
52        return fvService.getValues(
53                status.getObject().getSelection().getFacet(),
54                status.getObject().getContext(),
55                filter,
56                FacetValuesSortProperty.NAME).listIterator((int) first);
57    }
58
59    @Override
60    public long size() {
61        return fvService.getValueCount(
62                status.getObject().getSelection().getFacet(),
63                status.getObject().getContext(),
64                filter);
65    }
66
67    @Override
68    public IModel<FacetValue> model(FacetValue object) {
69        return new Model(object);
70    }
71}
Note: See TracBrowser for help on using the repository browser.