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;
20
21 import java.io.Serializable;
22 import java.util.Collection;
23 import java.util.List;
24 import org.apache.syncope.client.console.commons.ActionTableCheckGroup;
25 import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.AjaxFallbackDataTable;
26 import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.CheckGroupColumn;
27 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
28 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
29 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink.ActionType;
30 import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
31 import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormChoiceComponentUpdatingBehavior;
32 import org.apache.wicket.AttributeModifier;
33 import org.apache.wicket.ajax.AjaxRequestTarget;
34 import org.apache.wicket.ajax.markup.html.form.AjaxButton;
35 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
36 import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
37 import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
38 import org.apache.wicket.markup.html.WebMarkupContainer;
39 import org.apache.wicket.markup.html.form.Form;
40 import org.apache.wicket.model.ResourceModel;
41
42 public class ActionDataTablePanel<T extends Serializable, S> extends DataTablePanel<T, S> {
43
44 private static final long serialVersionUID = -8826989026203543957L;
45
46 private static final String CANCEL = "cancel";
47
48 private final Form<T> batchForm;
49
50 private final ActionsPanel<Serializable> actionPanel;
51
52 public ActionDataTablePanel(
53 final String id,
54 final List<IColumn<T, S>> columns,
55 final ISortableDataProvider<T, S> dataProvider,
56 final int rowsPerPage) {
57
58 super(id);
59
60 batchForm = new Form<>("groupForm");
61 add(batchForm);
62
63 group = new ActionTableCheckGroup<>("checkgroup", model) {
64
65 private static final long serialVersionUID = -8667764190925075389L;
66
67 @Override
68 public boolean isCheckable(final T element) {
69 return isElementEnabled(element);
70 }
71 };
72 group.add(new IndicatorAjaxFormChoiceComponentUpdatingBehavior() {
73
74 private static final long serialVersionUID = -151291731388673682L;
75
76 @Override
77 protected void onUpdate(final AjaxRequestTarget target) {
78
79 }
80 });
81 batchForm.add(group);
82
83 columns.add(0, new CheckGroupColumn<>(group));
84 dataTable = new AjaxFallbackDataTable<>("dataTable", columns, dataProvider, rowsPerPage, this);
85 group.add(dataTable);
86
87 final WebMarkupContainer actionPanelContainer = new WebMarkupContainer("actionPanelContainer");
88 batchForm.add(actionPanelContainer);
89
90 actionPanel = new ActionsPanel<>("actions", null);
91 actionPanelContainer.add(actionPanel);
92
93 if (dataTable.getRowCount() == 0) {
94 actionPanelContainer.add(new AttributeModifier("style", "display: none"));
95 }
96
97 batchForm.add(new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {
98
99 private static final long serialVersionUID = -2341391430136818025L;
100
101 @Override
102 protected void onSubmit(final AjaxRequestTarget target) {
103
104 }
105 }.setVisible(false).setEnabled(false));
106 }
107
108 public void addAction(final ActionLink<Serializable> action, final ActionType type, final String entitlements) {
109 actionPanel.add(action, type, entitlements);
110 }
111
112 public void addCancelButton(final BaseModal<?> modal) {
113 AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {
114
115 private static final long serialVersionUID = -4804368561204623354L;
116
117 @Override
118 protected void onSubmit(final AjaxRequestTarget target) {
119 modal.close(target);
120 }
121 };
122
123 cancel.setDefaultFormProcessing(false);
124 batchForm.addOrReplace(cancel);
125 }
126
127 public Collection<T> getModelObject() {
128 return group.getModelObject();
129 }
130
131 public boolean isElementEnabled(final T element) {
132 return true;
133 }
134 }