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.console.rest.AMSessionRestClient;
24  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
25  import org.apache.wicket.PageReference;
26  import org.apache.wicket.ajax.AjaxRequestTarget;
27  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
28  import org.apache.wicket.event.Broadcast;
29  import org.apache.wicket.markup.html.WebMarkupContainer;
30  import org.apache.wicket.markup.html.form.Form;
31  import org.apache.wicket.markup.html.panel.Panel;
32  import org.apache.wicket.model.Model;
33  
34  public class AMSessionPanel extends Panel {
35  
36      private static final long serialVersionUID = 30189416462011L;
37  
38      public AMSessionPanel(
39              final String id,
40              final AMSessionRestClient restClient,
41              final String listEntitlement,
42              final String deleteEntitlement,
43              final PageReference pageRef) {
44  
45          super(id);
46  
47          Model<String> keywordModel = new Model<>(StringUtils.EMPTY);
48  
49          WebMarkupContainer searchBoxContainer = new WebMarkupContainer("searchBox");
50          add(searchBoxContainer);
51  
52          AMSessionDirectoryPanel directoryPanel = new AMSessionDirectoryPanel(
53                  "directoryPanel", restClient, listEntitlement, deleteEntitlement, pageRef);
54          add(directoryPanel);
55  
56          Form<?> form = new Form<>("form");
57          searchBoxContainer.add(form);
58  
59          AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", keywordModel, true);
60          form.add(filter.hideLabel().setOutputMarkupId(true).setRenderBodyOnly(true));
61  
62          AjaxButton search = new AjaxButton("search") {
63  
64              private static final long serialVersionUID = 8390605330558248736L;
65  
66              @Override
67              protected void onSubmit(final AjaxRequestTarget target) {
68                  send(directoryPanel, Broadcast.EXACT, new AMSessionSearchEvent(target, keywordModel.getObject()));
69              }
70          };
71          search.setOutputMarkupId(true);
72          form.add(search);
73          form.setDefaultButton(search);
74      }
75  
76      public static class AMSessionSearchEvent implements Serializable {
77  
78          private static final long serialVersionUID = 5063826346823013424L;
79  
80          private final transient AjaxRequestTarget target;
81  
82          private final String keyword;
83  
84          AMSessionSearchEvent(final AjaxRequestTarget target, final String keyword) {
85              this.target = target;
86              this.keyword = keyword;
87          }
88  
89          public AjaxRequestTarget getTarget() {
90              return target;
91          }
92  
93          public String getKeyword() {
94              return keyword;
95          }
96      }
97  }