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.List;
22  import java.util.stream.Collectors;
23  import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
24  import org.apache.syncope.client.ui.commons.Constants;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
27  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
28  import org.apache.syncope.common.lib.to.AnyTypeClassTO;
29  import org.apache.syncope.common.lib.to.AnyTypeTO;
30  import org.apache.syncope.common.lib.types.AnyTypeKind;
31  import org.apache.wicket.markup.html.WebMarkupContainer;
32  import org.apache.wicket.markup.html.form.Form;
33  import org.apache.wicket.markup.html.panel.Panel;
34  import org.apache.wicket.model.CompoundPropertyModel;
35  import org.apache.wicket.model.PropertyModel;
36  import org.apache.wicket.model.util.ListModel;
37  import org.apache.wicket.spring.injection.annot.SpringBean;
38  
39  public class AnyTypeDetailsPanel extends Panel {
40  
41      private static final long serialVersionUID = 8131650329622035501L;
42  
43      @SpringBean
44      protected AnyTypeClassRestClient anyTypeClassRestClient;
45  
46      public AnyTypeDetailsPanel(final String id, final AnyTypeTO anyTypeTO) {
47          super(id);
48  
49          WebMarkupContainer container = new WebMarkupContainer("container");
50          container.setOutputMarkupId(true);
51          add(container);
52  
53          Form<AnyTypeTO> form = new Form<>("form");
54          form.setModel(new CompoundPropertyModel<>(anyTypeTO));
55          container.add(form);
56  
57          AjaxTextFieldPanel key = new AjaxTextFieldPanel(
58                  Constants.KEY_FIELD_NAME,
59                  getString(Constants.KEY_FIELD_NAME),
60                  new PropertyModel<>(anyTypeTO, Constants.KEY_FIELD_NAME));
61          key.addRequiredLabel();
62          key.setEnabled(key.getModelObject() == null || key.getModelObject().isEmpty());
63          form.add(key);
64  
65          AjaxDropDownChoicePanel<AnyTypeKind> kind = new AjaxDropDownChoicePanel<>(
66                  "kind", getString("kind"), new PropertyModel<>(anyTypeTO, "kind"));
67          kind.setChoices(List.of(AnyTypeKind.values()));
68          kind.setOutputMarkupId(true);
69          if (anyTypeTO.getKind() == null) {
70              kind.setModelObject(AnyTypeKind.ANY_OBJECT);
71          }
72          kind.setEnabled(false);
73          form.add(kind);
74  
75          form.add(new AjaxPalettePanel.Builder<String>().setAllowOrder(true).build("classes",
76                  new PropertyModel<>(anyTypeTO, "classes"),
77                  new ListModel<>(getAvailableAnyTypeClasses())).hideLabel().setOutputMarkupId(true));
78      }
79  
80      protected List<String> getAvailableAnyTypeClasses() {
81          return anyTypeClassRestClient.list().stream().map(AnyTypeClassTO::getKey).collect(Collectors.toList());
82      }
83  }