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.wizards.resources;
20  
21  import java.io.Serializable;
22  import java.util.List;
23  import org.apache.syncope.client.console.pages.BasePage;
24  import org.apache.syncope.client.console.panels.TogglePanel;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
26  import org.apache.wicket.PageReference;
27  import org.apache.wicket.ajax.AjaxRequestTarget;
28  import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
29  import org.apache.wicket.markup.html.form.Form;
30  import org.apache.wicket.model.LoadableDetachableModel;
31  import org.apache.wicket.model.PropertyModel;
32  
33  public abstract class ObjectTypeTogglePanel extends TogglePanel<Serializable> {
34  
35      private static final long serialVersionUID = -1366846136630731264L;
36  
37      ObjectTypeTogglePanel(
38              final String id,
39              final ResourceProvision resourceProvision,
40              final LoadableDetachableModel<List<String>> anyTypes,
41              final PageReference pageRef) {
42  
43          super(id, pageRef);
44  
45          Form<?> form = new Form<>("objectTypeForm");
46          addInnerObject(form);
47  
48          PropertyModel<String> typeModel = new PropertyModel<>(resourceProvision, "anyType");
49  
50          form.add(new AjaxDropDownChoicePanel<>(
51                  "type", "type", typeModel, false).
52                  setNullValid(false).
53                  setChoices(anyTypes).
54                  setStyleSheet("form-control").
55                  hideLabel());
56  
57          form.add(new AjaxSubmitLink("changeit", form) {
58  
59              private static final long serialVersionUID = -7978723352517770644L;
60  
61              @Override
62              protected void onSubmit(final AjaxRequestTarget target) {
63                  ObjectTypeTogglePanel.this.onSubmit(typeModel.getObject(), target);
64                  target.add(form);
65                  toggle(target, false);
66  
67                  ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
68              }
69  
70              @Override
71              protected void onError(final AjaxRequestTarget target) {
72                  ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
73              }
74          });
75      }
76  
77      protected abstract void onSubmit(String type, AjaxRequestTarget target);
78  
79      public void setHeaderLabel(final AjaxRequestTarget target) {
80          setHeader(target, getString("type"));
81      }
82  }