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.wicket.markup.html.form;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.apache.wicket.markup.html.list.ListItem;
25 import org.apache.wicket.markup.html.list.ListView;
26 import org.apache.wicket.markup.html.panel.Panel;
27 import org.apache.wicket.model.IModel;
28
29
30
31
32
33
34 public final class ActionsPanel<T extends Serializable> extends Panel {
35
36 private static final long serialVersionUID = 322966537010107771L;
37
38 private final List<Action<T>> actions = new ArrayList<>();
39
40 private IModel<T> model;
41
42 public ActionsPanel(final String componentId, final IModel<T> model) {
43 super(componentId, model);
44 setOutputMarkupId(true);
45 this.model = model;
46
47 add(new ListView<>("actionRepeater", actions) {
48
49 private static final long serialVersionUID = -9180479401817023838L;
50
51 @Override
52 protected void populateItem(final ListItem<Action<T>> item) {
53 item.add(new ActionPanel<>(ActionsPanel.this.model, item.getModelObject()));
54 }
55
56 }.setRenderBodyOnly(true));
57 }
58
59 public Action<T> add(
60 final ActionLink<T> link,
61 final ActionLink.ActionType type,
62 final String entitlements) {
63
64 return add(link, type, entitlements, false);
65 }
66
67 public Action<T> add(
68 final ActionLink<T> link,
69 final ActionLink.ActionType type,
70 final String entitlements,
71 final boolean onConfirm) {
72
73 Action<T> action = new Action<>(link, type);
74 action.setEntitlements(entitlements);
75 action.setOnConfirm(onConfirm);
76 actions.add(action);
77 return action;
78 }
79
80 public Action<T> add(final Action<T> action) {
81 actions.add(action);
82 return action;
83 }
84
85 public Action<T> add(final int index, final Action<T> action) {
86 actions.add(index, action);
87 return action;
88 }
89
90 public Action<T> set(final int index, final Action<T> action) {
91 actions.set(index, action);
92 return action;
93 }
94
95 public List<Action<T>> getActions() {
96 return actions;
97 }
98
99 public ActionsPanel<T> clone(final String componentId, final IModel<T> model) {
100 ActionsPanel<T> panel = new ActionsPanel<>(componentId, model);
101 panel.actions.addAll(actions);
102 return panel;
103 }
104
105
106
107
108
109
110
111
112 public ActionsPanel<T> cloneWithLabels(final String componentId, final IModel<T> model) {
113 ActionsPanel<T> panel = new ActionsPanel<>(componentId, model);
114 actions.forEach(action -> panel.actions.add(action.showLabel()));
115 return panel;
116 }
117
118 public boolean isEmpty() {
119 return this.actions.isEmpty();
120 }
121 }