1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.panels.search;
20
21 import java.io.Serializable;
22 import java.util.Collection;
23 import java.util.List;
24 import org.apache.syncope.client.console.SyncopeWebApplication;
25 import org.apache.syncope.client.console.panels.AnyDirectoryPanel;
26 import org.apache.syncope.client.console.rest.AbstractAnyRestClient;
27 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
28 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink.ActionType;
29 import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
30 import org.apache.syncope.common.lib.to.AnyTO;
31 import org.apache.syncope.common.lib.to.AnyTypeClassTO;
32 import org.apache.syncope.common.lib.types.AnyEntitlement;
33 import org.apache.wicket.PageReference;
34 import org.apache.wicket.ajax.AjaxRequestTarget;
35 import org.apache.wicket.event.Broadcast;
36 import org.apache.wicket.model.IModel;
37
38 public abstract class AnySelectionDirectoryPanel<A extends AnyTO, E extends AbstractAnyRestClient<A>>
39 extends AnyDirectoryPanel<A, E> {
40
41 private static final long serialVersionUID = -1100228004207271272L;
42
43 protected AnySelectionDirectoryPanel(
44 final String id,
45 final AnyDirectoryPanel.Builder<A, E> builder,
46 final boolean wizardInModal) {
47
48 super(id, builder, wizardInModal);
49
50 SyncopeWebApplication.get().getAnyDirectoryPanelAdditionalActionsProvider().hide();
51 }
52
53 @Override
54 public ActionsPanel<A> getActions(final IModel<A> model) {
55 final ActionsPanel<A> panel = super.getActions(model);
56
57 panel.add(new ActionLink<>() {
58
59 private static final long serialVersionUID = -7978723352517770644L;
60
61 @Override
62 public void onClick(final AjaxRequestTarget target, final A ignore) {
63 send(AnySelectionDirectoryPanel.this,
64 Broadcast.BUBBLE, new ItemSelection<>(target, model.getObject()));
65 }
66 }, ActionType.SELECT, AnyEntitlement.READ.getFor(type));
67
68 return panel;
69 }
70
71 @Override
72 protected Collection<ActionType> getBatches() {
73 return List.of();
74 }
75
76 public abstract static class Builder<A extends AnyTO, E extends AbstractAnyRestClient<A>>
77 extends AnyDirectoryPanel.Builder<A, E> {
78
79 private static final long serialVersionUID = 5460024856989891156L;
80
81 public Builder(
82 final List<AnyTypeClassTO> anyTypeClassTOs,
83 final E restClient,
84 final String type,
85 final PageReference pageRef) {
86
87 super(anyTypeClassTOs, restClient, type, pageRef);
88 this.filtered = true;
89 this.checkBoxEnabled = false;
90 }
91 }
92
93 public static class ItemSelection<T extends AnyTO> implements Serializable {
94
95 private static final long serialVersionUID = 1242677935378149180L;
96
97 private final AjaxRequestTarget target;
98
99 private final T usr;
100
101 public ItemSelection(final AjaxRequestTarget target, final T usr) {
102 this.target = target;
103 this.usr = usr;
104 }
105
106 public AjaxRequestTarget getTarget() {
107 return target;
108 }
109
110 public T getSelection() {
111 return usr;
112 }
113 }
114 }