source: vlo/branches/vlo-3.3-oeaw/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/SearchFormPanel.java @ 6755

Last change on this file since 6755 was 6755, checked in by davor.ostojic@oeaw.ac.at, 9 years ago

merged with trunk 3.4

File size: 4.2 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 eu.clarin.cmdi.vlo.JavaScriptResources;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.service.solr.AutoCompleteService;
22import java.util.Iterator;
23import org.apache.wicket.Component;
24import org.apache.wicket.ajax.AjaxRequestTarget;
25import org.apache.wicket.ajax.attributes.AjaxCallListener;
26import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
27import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
28import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
29import org.apache.wicket.markup.head.CssHeaderItem;
30import org.apache.wicket.markup.head.IHeaderResponse;
31import org.apache.wicket.markup.head.JavaScriptHeaderItem;
32import org.apache.wicket.markup.html.form.Form;
33import org.apache.wicket.markup.html.panel.GenericPanel;
34import org.apache.wicket.model.IModel;
35import org.apache.wicket.model.PropertyModel;
36import org.apache.wicket.spring.injection.annot.SpringBean;
37
38/**
39 * Form for textual query on the faceted search page
40 *
41 * @author twagoo
42 */
43public abstract class SearchFormPanel extends GenericPanel<QueryFacetsSelection> {
44
45    @SpringBean
46    private AutoCompleteService autoCompleteDao;
47
48    //private final AjaxIndicatorAppender indicatorAppender = new AjaxIndicatorAppender();
49    public SearchFormPanel(String id, IModel<QueryFacetsSelection> model) {
50        super(id, model);
51
52        final Form<QueryFacetsSelection> form = new Form<>("search", model);
53
54        // Bind search field to 'query' property of model
55        form.add(new AutoCompleteTextField("query", new PropertyModel<String>(model, "query")) {
56
57            @Override
58            protected Iterator<String> getChoices(String input) {
59                return autoCompleteDao.getChoices(input);
60            }
61           
62        });
63
64        // Button allows partial updates but can fall back to a full (non-JS) refresh
65        form.add(new AjaxFallbackButton("searchSubmit", form) {
66
67            @Override
68            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
69                SearchFormPanel.this.onSubmit(target);
70            }
71
72            @Override
73            protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
74                super.updateAjaxAttributes(attributes);
75
76                // listener to start/stop indicating progress
77                AjaxCallListener listener = new AjaxCallListener() {
78
79                    @Override
80                    public CharSequence getBeforeHandler(Component component) {
81                        return ("startSearch();");
82                    }
83
84                    @Override
85                    public CharSequence getCompleteHandler(Component component) {
86                        return ("endSearch();");
87                    }
88
89                };
90                attributes.getAjaxCallListeners().add(listener);
91            }
92
93        }
94        );
95
96        add(form);
97    }
98   
99    protected abstract void onSubmit(AjaxRequestTarget target);
100
101    @Override
102    public void renderHead(IHeaderResponse response) {
103        // include script that activates the help button tooltip and JQuery UI on which it depends
104        response.render(CssHeaderItem.forReference(JavaScriptResources.getJQueryUICSS()));
105        response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getJQueryUIJS()));
106        response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getSyntaxHelpJS()));
107        response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getSearchFormJS()));
108    }
109}
Note: See TracBrowser for help on using the repository browser.