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.pages;
20  
21  import java.io.Serializable;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.client.console.panels.ResourceDirectoryPanel;
24  import org.apache.syncope.client.console.rest.ConnectorRestClient;
25  import org.apache.syncope.client.console.rest.ResourceRestClient;
26  import org.apache.syncope.client.console.wizards.WizardMgtPanel;
27  import org.apache.syncope.client.console.wizards.resources.ResourceWizardBuilder;
28  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
29  import org.apache.syncope.common.lib.to.ResourceTO;
30  import org.apache.wicket.PageReference;
31  import org.apache.wicket.ajax.AjaxRequestTarget;
32  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
33  import org.apache.wicket.event.Broadcast;
34  import org.apache.wicket.markup.html.WebMarkupContainer;
35  import org.apache.wicket.markup.html.form.Form;
36  import org.apache.wicket.markup.html.panel.Panel;
37  import org.apache.wicket.model.Model;
38  import org.apache.wicket.spring.injection.annot.SpringBean;
39  
40  public class Resources extends Panel {
41  
42      private static final long serialVersionUID = 7240865652350993779L;
43  
44      @SpringBean
45      protected ResourceRestClient resourceRestClient;
46  
47      @SpringBean
48      protected ConnectorRestClient connectorRestClient;
49  
50      public Resources(final String id, final PageReference pageRef) {
51          super(id);
52  
53          Model<String> keywordModel = new Model<>(StringUtils.EMPTY);
54  
55          WebMarkupContainer searchBoxContainer = new WebMarkupContainer("searchBox");
56          add(searchBoxContainer);
57  
58          Form<?> form = new Form<>("form");
59          searchBoxContainer.add(form);
60  
61          AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", keywordModel, true);
62          form.add(filter.hideLabel().setOutputMarkupId(true));
63  
64          AjaxButton search = new AjaxButton("search") {
65  
66              private static final long serialVersionUID = 8390605330558248736L;
67  
68              @Override
69              protected void onSubmit(final AjaxRequestTarget target) {
70                  send(Resources.this, Broadcast.DEPTH,
71                          new ResourceDirectoryPanel.ResourceSearchEvent(target, keywordModel.getObject()));
72              }
73          };
74          search.setOutputMarkupId(true);
75          form.add(search);
76          form.setDefaultButton(search);
77  
78          WizardMgtPanel<Serializable> resourceDirectoryPanel = new ResourceDirectoryPanel.Builder(
79                  resourceRestClient, pageRef).addNewItemPanelBuilder(new ResourceWizardBuilder(
80                  new ResourceTO(), resourceRestClient, connectorRestClient, pageRef), true).
81                  build("resourceDirectoryPanel");
82          add(resourceDirectoryPanel.setOutputMarkupId(true));
83      }
84  }