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.status;
20  
21  import java.util.List;
22  import java.util.stream.Collectors;
23  import org.apache.syncope.client.console.commons.DirectoryDataProvider;
24  import org.apache.syncope.client.console.panels.DirectoryPanel;
25  import org.apache.syncope.client.console.panels.MultilevelPanel;
26  import org.apache.syncope.client.console.rest.AbstractAnyRestClient;
27  import org.apache.syncope.client.console.rest.AnyTypeRestClient;
28  import org.apache.syncope.client.ui.commons.Constants;
29  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
30  import org.apache.syncope.client.ui.commons.status.StatusBean;
31  import org.apache.syncope.common.lib.to.Provision;
32  import org.apache.syncope.common.lib.to.ResourceTO;
33  import org.apache.wicket.PageReference;
34  import org.apache.wicket.ajax.AjaxRequestTarget;
35  import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
36  import org.apache.wicket.model.Model;
37  
38  public class ResourceStatusModal extends StatusModal<ResourceTO> {
39  
40      private static final long serialVersionUID = 1066124171682570080L;
41  
42      private Model<String> typeModel = new Model<>();
43  
44      public ResourceStatusModal(
45              final PageReference pageRef,
46              final ResourceTO resource) {
47  
48          super(pageRef, resource, null, false);
49  
50          List<String> availableAnyTypes = resource.getProvisions().stream().
51                  map(Provision::getAnyType).
52                  sorted(AnyTypeRestClient.KEY_COMPARATOR).
53                  collect(Collectors.toList());
54  
55          AjaxDropDownChoicePanel<String> anyTypes =
56                  new AjaxDropDownChoicePanel<>("anyTypes", "anyTypes", typeModel, false);
57          anyTypes.setChoices(availableAnyTypes);
58          anyTypes.hideLabel();
59          add(anyTypes);
60  
61          anyTypes.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
62  
63              private static final long serialVersionUID = -1107858522700306810L;
64  
65              @Override
66              protected void onUpdate(final AjaxRequestTarget target) {
67                  ResourceStatusDirectoryPanel.class.cast(directoryPanel).
68                          updateResultTable(typeModel.getObject(), target);
69              }
70          });
71      }
72  
73      @Override
74      protected DirectoryPanel<
75          StatusBean, StatusBean, DirectoryDataProvider<StatusBean>, AbstractAnyRestClient<?>> getStatusDirectoryPanel(
76              final MultilevelPanel mlp,
77              final PageReference pageReference,
78              final ResourceTO entity,
79              final String itemKeyFieldName,
80              final boolean statusOnly) {
81  
82          return new ResourceStatusDirectoryPanel(mlp, pageReference, null, entity);
83      }
84  }