source: vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/AdvancedSearchOptionsPanel.java @ 6657

Last change on this file since 6657 was 6657, checked in by Twan Goosen, 9 years ago

Merged changes from 3.3 branch (option to skip hierarchy processing) to trunk

File size: 4.1 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.panels.search;
18
19import com.google.common.collect.ImmutableSet;
20import eu.clarin.cmdi.vlo.FacetConstants;
21import eu.clarin.cmdi.vlo.config.VloConfig;
22import eu.clarin.cmdi.vlo.pojo.ExpansionState;
23import eu.clarin.cmdi.vlo.pojo.FacetSelection;
24import eu.clarin.cmdi.vlo.pojo.FacetSelectionType;
25import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
26import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
27import eu.clarin.cmdi.vlo.wicket.model.ToggleModel;
28import eu.clarin.cmdi.vlo.wicket.panels.ExpandablePanel;
29import java.util.Collection;
30import org.apache.wicket.MarkupContainer;
31import org.apache.wicket.ajax.AjaxRequestTarget;
32import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
33import org.apache.wicket.markup.html.WebMarkupContainer;
34import org.apache.wicket.markup.html.basic.Label;
35import org.apache.wicket.markup.html.form.CheckBox;
36import org.apache.wicket.markup.html.form.Form;
37import org.apache.wicket.model.IModel;
38import org.apache.wicket.spring.injection.annot.SpringBean;
39
40/**
41 * A panel showing advanced search options:
42 * <ul>
43 * <li>selection of records that support FCS</li>
44 * <li>selection of records that are based on either CMDI or OLAC</li>
45 * </ul>
46 *
47 * @author twagoo
48 */
49public abstract class AdvancedSearchOptionsPanel extends ExpandablePanel<QueryFacetsSelection> {
50
51    @SpringBean
52    private VloConfig config;
53   
54    /**
55     * The fields that this panel provides options for
56     */
57    public final static Collection<String> OPTIONS_FIELDS = ImmutableSet.of(
58            FacetConstants.FIELD_HAS_PART_COUNT,
59            FacetConstants.FIELD_SEARCH_SERVICE);
60
61    public AdvancedSearchOptionsPanel(String id, IModel<QueryFacetsSelection> model) {
62        super(id, model);
63        final Form options = new Form("options");
64
65        final CheckBox fcsCheck = createFieldNotEmptyOption("fcs", FacetConstants.FIELD_SEARCH_SERVICE);
66        options.add(fcsCheck);
67       
68        final MarkupContainer collectionsSection = new WebMarkupContainer("collectionsSection");
69        final CheckBox collectionCheck = createFieldNotEmptyOption("collection", FacetConstants.FIELD_HAS_PART_COUNT);
70        collectionsSection.add(collectionCheck);
71        collectionsSection.setVisible(config.isProcessHierarchies());
72        options.add(collectionsSection);
73       
74        add(options);
75    }
76
77    private CheckBox createFieldNotEmptyOption(String id, String fieldName) {
78        // create a model for the selection state of the facet
79        final IModel<FacetSelection> facetModel = new FacetSelectionModel(getModel(), fieldName);
80        // wrap in a toggle model that allows switching between a null selection and a 'not empty' selection
81        final ToggleModel<FacetSelection> toggleModel = new ToggleModel<>(facetModel, null, new FacetSelection(FacetSelectionType.NOT_EMPTY));
82
83        final CheckBox checkBox = new CheckBox(id, toggleModel);
84        checkBox.add(new OnChangeAjaxBehavior() {
85
86            @Override
87            protected void onUpdate(AjaxRequestTarget target) {
88                selectionChanged(target);
89            }
90        });
91        // should initially be epxanded if one of the options was selected
92        if (toggleModel.getObject()) {
93            getExpansionModel().setObject(ExpansionState.EXPANDED);
94        }
95        return checkBox;
96    }
97
98    @Override
99    protected Label createTitleLabel(String id) {
100        return new Label(id, "Search options");
101    }
102
103    protected abstract void selectionChanged(AjaxRequestTarget target);
104
105}
Note: See TracBrowser for help on using the repository browser.