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

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

created specialised model for SolrDocument? fields

File size: 2.7 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.FacetConstants;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.service.SolrDocumentService;
22import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
23import eu.clarin.cmdi.vlo.wicket.provider.SolrDocumentProvider;
24import org.apache.solr.common.SolrDocument;
25import org.apache.wicket.markup.html.basic.Label;
26import org.apache.wicket.markup.html.panel.Panel;
27import org.apache.wicket.markup.repeater.Item;
28import org.apache.wicket.markup.repeater.data.DataView;
29import org.apache.wicket.markup.repeater.data.IDataProvider;
30import org.apache.wicket.model.AbstractReadOnlyModel;
31import org.apache.wicket.model.IModel;
32import org.apache.wicket.spring.injection.annot.SpringBean;
33
34/**
35 * Panel that has a data view on the current search results
36 *
37 * @author twagoo
38 */
39public class SearchResultsPanel extends Panel {
40
41    @SpringBean
42    private SolrDocumentService documentService;
43    private final IDataProvider<SolrDocument> solrDocumentProvider;
44
45    public SearchResultsPanel(String id, IModel<QueryFacetsSelection> model) {
46        super(id, model);
47        solrDocumentProvider = new SolrDocumentProvider(documentService, model);
48        add(new Label("resultCount", new AbstractReadOnlyModel<Long>() {
49
50            @Override
51            public Long getObject() {
52                return solrDocumentProvider.size();
53            }
54        }));
55
56        add(new DataView<SolrDocument>("resultItem", solrDocumentProvider, 10) {
57
58            @Override
59            protected void populateItem(Item<SolrDocument> item) {
60                //TODO: Wrap in model to deal with null values
61                item.add(new Label("title", new SolrFieldModel(item.getModel(), FacetConstants.FIELD_NAME)));
62                item.add(new Label("description", new SolrFieldModel(item.getModel(), FacetConstants.FIELD_DESCRIPTION)));
63                //TODO: get resource information
64            }
65        });
66
67        //TODO: Add pagination
68    }
69
70}
Note: See TracBrowser for help on using the repository browser.