View Javadoc
1   /**
2    * Copyright 2014-2024 Bloomreach B.V. (<a href="http://www.bloomreach.com">http://www.bloomreach.com</a>)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.onehippo.forge.exdocpicker.impl.field;
17  
18  import java.io.Serializable;
19  
20  import org.apache.wicket.ajax.AjaxRequestTarget;
21  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
22  import org.apache.wicket.markup.html.form.TextField;
23  import org.apache.wicket.model.IModel;
24  import org.apache.wicket.model.PropertyModel;
25  import org.apache.wicket.model.StringResourceModel;
26  import org.onehippo.forge.exdocpicker.api.ExternalDocumentCollection;
27  import org.onehippo.forge.exdocpicker.api.ExternalDocumentServiceContext;
28  import org.onehippo.forge.exdocpicker.api.ExternalDocumentServiceFacade;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  public class TextSearchExternalDocumentFieldBrowserDialog extends ExternalDocumentFieldBrowserDialog {
33  
34      private static final long serialVersionUID = 1L;
35  
36      private static final Logger log = LoggerFactory.getLogger(TextSearchExternalDocumentFieldBrowserDialog.class);
37  
38      public TextSearchExternalDocumentFieldBrowserDialog(IModel<String> titleModel,
39                                                          final ExternalDocumentServiceContext extDocServiceContext,
40                                                          final ExternalDocumentServiceFacade<Serializable> exdocService,
41                                                          IModel<ExternalDocumentCollection<Serializable>> model) {
42          super(titleModel, extDocServiceContext, exdocService, model);
43  
44          final TextField<String> searchText = new TextField<>("search-input", new PropertyModel<String>(this, "searchQuery"));
45          searchText.setOutputMarkupId(true);
46          add(setFocus(searchText));
47  
48          //Search button
49          AjaxButton searchButton = new AjaxButton("search-button", new StringResourceModel("search.button", this, null)) {
50              private static final long serialVersionUID = 1L;
51  
52              @Override
53              protected void onSubmit(AjaxRequestTarget ajaxRequestTarget) {
54                  searchExternalDocumentsBySearchQuery();
55                  ajaxRequestTarget.add(TextSearchExternalDocumentFieldBrowserDialog.this);
56              }
57          };
58  
59          add(searchButton);
60      }
61  }
62