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 | */ |
---|
17 | package eu.clarin.cmdi.vlo.wicket.components; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.FacetConstants; |
---|
20 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
21 | import eu.clarin.cmdi.vlo.service.SolrDocumentService; |
---|
22 | import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel; |
---|
23 | import eu.clarin.cmdi.vlo.wicket.provider.SolrDocumentProvider; |
---|
24 | import org.apache.solr.common.SolrDocument; |
---|
25 | import org.apache.wicket.markup.html.basic.Label; |
---|
26 | import org.apache.wicket.markup.html.panel.Panel; |
---|
27 | import org.apache.wicket.markup.repeater.Item; |
---|
28 | import org.apache.wicket.markup.repeater.data.DataView; |
---|
29 | import org.apache.wicket.markup.repeater.data.IDataProvider; |
---|
30 | import org.apache.wicket.model.AbstractReadOnlyModel; |
---|
31 | import org.apache.wicket.model.IModel; |
---|
32 | import 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 | */ |
---|
39 | public 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 | } |
---|