View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.panels;
20  
21  import java.io.Serializable;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
24  import org.apache.wicket.ajax.AjaxRequestTarget;
25  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
26  import org.apache.wicket.event.Broadcast;
27  import org.apache.wicket.markup.html.WebMarkupContainer;
28  import org.apache.wicket.markup.html.form.Form;
29  import org.apache.wicket.markup.html.panel.Panel;
30  import org.apache.wicket.model.Model;
31  
32  public class UserRequestsPanel extends Panel {
33  
34      private static final long serialVersionUID = -896040867024301443L;
35  
36      public UserRequestsPanel(final String id, final DirectoryPanel<?, ?, ?, ?> directoryPanel) {
37          super(id);
38  
39          Model<String> keywordModel = new Model<>(StringUtils.EMPTY);
40  
41          WebMarkupContainer searchBoxContainer = new WebMarkupContainer("searchBox");
42          add(searchBoxContainer);
43  
44          Form<?> form = new Form<>("form");
45          searchBoxContainer.add(form);
46  
47          AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", keywordModel, true);
48          form.add(filter.setPlaceholder("username / key").hideLabel().setOutputMarkupId(true));
49  
50          AjaxButton search = new AjaxButton("search") {
51  
52              private static final long serialVersionUID = 8390605330558248736L;
53  
54              @Override
55              protected void onSubmit(final AjaxRequestTarget target) {
56                  send(UserRequestsPanel.this, Broadcast.DEPTH,
57                          new UserRequestSearchEvent(target, keywordModel.getObject()));
58              }
59          };
60          search.setOutputMarkupId(true);
61          form.add(search);
62          form.setDefaultButton(search);
63  
64          add(directoryPanel);
65      }
66  
67      public static class UserRequestSearchEvent implements Serializable {
68  
69          private static final long serialVersionUID = 5063826346823013424L;
70  
71          private final transient AjaxRequestTarget target;
72  
73          private final String keyword;
74  
75          UserRequestSearchEvent(final AjaxRequestTarget target, final String keyword) {
76              this.target = target;
77              this.keyword = keyword;
78          }
79  
80          public AjaxRequestTarget getTarget() {
81              return target;
82          }
83  
84          public String getKeyword() {
85              return keyword;
86          }
87      }
88  }