1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.ui.commons.markup.html.form;
20
21 import java.io.Serializable;
22 import java.util.List;
23 import org.apache.syncope.client.ui.commons.Constants;
24 import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
25 import org.apache.wicket.ajax.AjaxRequestTarget;
26 import org.apache.wicket.markup.html.form.ChoiceRenderer;
27 import org.apache.wicket.markup.html.form.DropDownChoice;
28 import org.apache.wicket.markup.html.form.IChoiceRenderer;
29 import org.apache.wicket.model.IModel;
30 import org.apache.wicket.model.ResourceModel;
31
32 public class AjaxDropDownChoicePanel<T extends Serializable> extends FieldPanel<T> implements Cloneable {
33
34 private static final long serialVersionUID = -4716376580659196095L;
35
36 public AjaxDropDownChoicePanel(final String id, final String name, final IModel<T> model) {
37 this(id, name, model, true);
38 }
39
40 public AjaxDropDownChoicePanel(
41 final String id, final String name, final IModel<T> model, final boolean enableOnBlur) {
42
43 super(id, name, model);
44
45 field = new DropDownChoice<>("dropDownChoiceField", model, List.of(), new ChoiceRenderer<>());
46 add(field.setLabel(new ResourceModel(name, name)).setOutputMarkupId(true));
47
48 if (enableOnBlur) {
49 field.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_BLUR) {
50
51 private static final long serialVersionUID = -1107858522700306810L;
52
53 @Override
54 protected void onUpdate(final AjaxRequestTarget target) {
55
56 }
57 }).add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
58
59 private static final long serialVersionUID = -1107858522700306810L;
60
61 @Override
62 protected void onUpdate(final AjaxRequestTarget target) {
63
64 }
65 });
66 }
67
68 setNullValid(true);
69 }
70
71 @Override
72 public FieldPanel<T> setRequired(final boolean required) {
73 setNullValid(!required);
74 return super.setRequired(required);
75 }
76
77 @SuppressWarnings("unchecked")
78 public AjaxDropDownChoicePanel<T> setChoiceRenderer(final IChoiceRenderer<T> renderer) {
79 DropDownChoice.class.cast(field).setChoiceRenderer(renderer);
80 return this;
81 }
82
83 @SuppressWarnings("unchecked")
84 public AjaxDropDownChoicePanel<T> setChoices(final List<T> choices) {
85 DropDownChoice.class.cast(field).setChoices(choices);
86 return this;
87 }
88
89 @SuppressWarnings("unchecked")
90 public AjaxDropDownChoicePanel<T> setChoices(final IModel<? extends List<? extends T>> choices) {
91 DropDownChoice.class.cast(field).setChoices(choices);
92 return this;
93 }
94
95 public final AjaxDropDownChoicePanel<T> setNullValid(final boolean validity) {
96 DropDownChoice.class.cast(field).setNullValid(validity);
97 return this;
98 }
99
100 @Override
101 @SuppressWarnings("unchecked")
102 public FieldPanel<T> clone() {
103 final AjaxDropDownChoicePanel<T> panel = (AjaxDropDownChoicePanel<T>) super.clone();
104 panel.setChoiceRenderer(DropDownChoice.class.cast(field).getChoiceRenderer());
105 panel.setChoices(DropDownChoice.class.cast(field).getChoices());
106 return panel;
107 }
108 }