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

Last change on this file since 4632 was 4632, checked in by Twan Goosen, 10 years ago

added field table for record by means of a data provider (of the new DocumentField? pojo interface, plus hybrid model/implementation) with filtering capabilities and a dataview that produces a table

File size: 2.4 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 com.google.common.collect.Lists;
20import eu.clarin.cmdi.vlo.pojo.DocumentField;
21import java.util.Collection;
22import java.util.List;
23import org.apache.solr.common.SolrDocument;
24import org.apache.wicket.model.AbstractReadOnlyModel;
25import org.apache.wicket.model.IModel;
26import org.apache.wicket.model.Model;
27
28/**
29 * Model for {@link DocumentField} that wraps a document model and a field name
30 *
31 * @author twagoo
32 * @param <T> type of the field
33 */
34public class DocumentFieldModel<T> extends AbstractReadOnlyModel<DocumentField<T>> implements DocumentField {
35   
36    private final IModel<String> fieldName;
37    private final IModel<Collection<T>> valueModel;
38
39    /**
40     * Uses the document model to create a {@link SolrFieldModel} to provide the
41     * field values
42     *
43     * @param documentModel model that provides the document
44     * @param fieldName name of the field to represent
45     */
46    public DocumentFieldModel(IModel<SolrDocument> documentModel, String fieldName) {
47        this(new SolrFieldModel<T>(documentModel, fieldName), Model.of(fieldName));
48    }
49   
50    public DocumentFieldModel(IModel<Collection<T>> valueModel, IModel<String> fieldName) {
51        this.fieldName = fieldName;
52        this.valueModel = valueModel;
53    }
54   
55    @Override
56    public DocumentField getObject() {
57        return this;
58    }
59   
60    @Override
61    public String getFieldName() {
62        return fieldName.getObject();
63    }
64   
65    @Override
66    public List<T> getValues() {
67        return Lists.newArrayList(valueModel.getObject());
68    }
69   
70    @Override
71    public String toString() {
72        return String.format("%s: %s", fieldName, valueModel);
73    }
74   
75}
Note: See TracBrowser for help on using the repository browser.