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.util.ArrayList;
22  import java.util.List;
23  import org.apache.commons.lang3.StringUtils;
24  import org.apache.syncope.client.console.commons.KeywordSearchEvent;
25  import org.apache.syncope.client.console.rest.SchemaRestClient;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
27  import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion;
28  import org.apache.syncope.common.lib.types.SchemaType;
29  import org.apache.wicket.PageReference;
30  import org.apache.wicket.ajax.AjaxRequestTarget;
31  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
32  import org.apache.wicket.event.Broadcast;
33  import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
34  import org.apache.wicket.extensions.markup.html.tabs.ITab;
35  import org.apache.wicket.markup.html.WebMarkupContainer;
36  import org.apache.wicket.markup.html.form.Form;
37  import org.apache.wicket.markup.html.panel.Panel;
38  import org.apache.wicket.model.Model;
39  import org.apache.wicket.spring.injection.annot.SpringBean;
40  
41  public class SchemasPanel extends Panel {
42  
43      private static final long serialVersionUID = -1140213992451232279L;
44  
45      @SpringBean
46      protected SchemaRestClient schemaRestClient;
47  
48      protected final PageReference pageRef;
49  
50      public SchemasPanel(final String id, final PageReference pageRef) {
51          super(id);
52  
53          this.pageRef = pageRef;
54  
55          Model<String> keywordModel = new Model<>(StringUtils.EMPTY);
56  
57          WebMarkupContainer searchBoxContainer = new WebMarkupContainer("searchBox");
58          add(searchBoxContainer);
59  
60          Form<?> form = new Form<>("form");
61          searchBoxContainer.add(form);
62  
63          AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", keywordModel, true);
64          form.add(filter.hideLabel().setOutputMarkupId(true).setRenderBodyOnly(true));
65  
66          AjaxButton search = new AjaxButton("search") {
67  
68              private static final long serialVersionUID = 8390605330558248736L;
69  
70              @Override
71              protected void onSubmit(final AjaxRequestTarget target) {
72                  send(SchemasPanel.this, Broadcast.DEPTH, new KeywordSearchEvent(target, keywordModel.getObject()));
73              }
74          };
75          search.setOutputMarkupId(true);
76          form.add(search);
77          form.setDefaultButton(search);
78  
79          Accordion accordion = new Accordion("accordionPanel", buildTabList());
80          accordion.setOutputMarkupId(true);
81          add(accordion);
82      }
83  
84      protected List<ITab> buildTabList() {
85          List<ITab> tabs = new ArrayList<>();
86  
87          for (final SchemaType schemaType : SchemaType.values()) {
88              tabs.add(new AbstractTab(new Model<>(schemaType.name())) {
89  
90                  private static final long serialVersionUID = 1037272333056449378L;
91  
92                  @Override
93                  public Panel getPanel(final String panelId) {
94                      return new SchemaTypePanel(panelId, schemaRestClient, schemaType, pageRef);
95                  }
96              });
97          }
98  
99          return tabs;
100     }
101 }