/
AssignmentPopup.java
262 lines (217 loc) · 10.3 KB
/
AssignmentPopup.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package com.evolveum.midpoint.gui.api.component;
import com.evolveum.midpoint.gui.api.component.tabs.CountablePanelTab;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.Loop;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* Created by honchar.
*/
public class AssignmentPopup<O extends ObjectType> extends BasePanel implements Popupable{
private static final long serialVersionUID = 1L;
private static final String ID_TABS_PANEL = "tabsPanel";
private static final String ID_CANCEL_BUTTON = "cancelButton";
private static final String ID_ASSIGN_BUTTON = "assignButton";
private static final String ID_FORM = "form";
private FocusTypeAssignmentPopupTabPanel rolesTabPanel;
private FocusTypeAssignmentPopupTabPanel orgsTabPanel;
private FocusTypeAssignmentPopupTabPanel servicesTabPanel;
private FocusTypeAssignmentPopupTabPanel usersTabPanel;
private FocusTypeAssignmentPopupTabPanel resourcesTabPanel;
public AssignmentPopup(String id){
super(id);
}
@Override
protected void onInitialize(){
super.onInitialize();
Form form = new Form(ID_FORM);
form.setOutputMarkupId(true);
add(form);
List<ITab> tabs = createAssignmentTabs();
TabbedPanel<ITab> tabPanel = WebComponentUtil.createTabPanel(ID_TABS_PANEL, getPageBase(), tabs, null);
tabPanel.setOutputMarkupId(true);
form.add(tabPanel);
AjaxButton cancelButton = new AjaxButton(ID_CANCEL_BUTTON,
createStringResource("userBrowserDialog.button.cancelButton")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// TypedAssignablePanel.this.assignButtonClicked(target, new ArrayList<>());
}
};
cancelButton.setOutputMarkupId(true);
form.add(cancelButton);
AjaxButton addButton = new AjaxButton(ID_ASSIGN_BUTTON,
createStringResource("userBrowserDialog.button.addButton")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<AssignmentType> newAssignmentsList = new ArrayList<>();
if (rolesTabPanel != null){
List<O> selectedRoles = rolesTabPanel.getSelectedObjectsList();
QName relation = rolesTabPanel.getRelationValue();
selectedRoles.forEach(selectedRole -> {
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(selectedRole, relation);
AssignmentType newAssignment = new AssignmentType();
newAssignment.setTargetRef(ref);
newAssignmentsList.add(newAssignment);
});
}
if (orgsTabPanel != null){
List<O> selectedOrgs = orgsTabPanel.getSelectedObjectsList();
QName relation = orgsTabPanel.getRelationValue();
selectedOrgs.forEach(selectedOrg -> {
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(selectedOrg, relation);
AssignmentType newAssignment = new AssignmentType();
newAssignment.setTargetRef(ref);
newAssignmentsList.add(newAssignment);
});
}
if (servicesTabPanel != null){
List<O> selectedServices = servicesTabPanel.getSelectedObjectsList();
QName relation = servicesTabPanel.getRelationValue();
selectedServices.forEach(selectedService -> {
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(selectedService, relation);
AssignmentType newAssignment = new AssignmentType();
newAssignment.setTargetRef(ref);
newAssignmentsList.add(newAssignment);
});
}
addPerformed(target, newAssignmentsList);
}
};
addButton.setOutputMarkupId(true);
form.add(addButton);
}
private List<ITab> createAssignmentTabs() {
List<ITab> tabs = new ArrayList<>();
VisibleEnableBehaviour authorization = new VisibleEnableBehaviour(){
};
tabs.add(new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.ROLE"), authorization) {
private static final long serialVersionUID = 1L;
@Override
public WebMarkupContainer createPanel(String panelId) {
rolesTabPanel = new FocusTypeAssignmentPopupTabPanel(panelId, ObjectTypes.ROLE){
private static final long serialVersionUID = 1L;
@Override
protected void onSelectionPerformed(AjaxRequestTarget target){
tabLabelPanelUpdate(target);
}
};
return rolesTabPanel;
}
@Override
public String getCount() {
if (rolesTabPanel == null){
return "0";
}
return Integer.toString(rolesTabPanel.getObjectListPanel().getSelectedObjectsCount());
}
});
tabs.add(
new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.ORG"), authorization) {
private static final long serialVersionUID = 1L;
@Override
public WebMarkupContainer createPanel(String panelId) {
orgsTabPanel = new FocusTypeAssignmentPopupTabPanel(panelId, ObjectTypes.ORG){
private static final long serialVersionUID = 1L;
@Override
protected void onSelectionPerformed(AjaxRequestTarget target){
tabLabelPanelUpdate(target);
}
};
return orgsTabPanel;
}
@Override
public String getCount() {
if (orgsTabPanel == null){
return "0";
}
return Integer.toString(orgsTabPanel.getObjectListPanel().getSelectedObjectsCount());
}
});
tabs.add(
new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.SERVICE"), authorization) {
private static final long serialVersionUID = 1L;
@Override
public WebMarkupContainer createPanel(String panelId) {
servicesTabPanel = new FocusTypeAssignmentPopupTabPanel(panelId, ObjectTypes.SERVICE){
private static final long serialVersionUID = 1L;
@Override
protected void onSelectionPerformed(AjaxRequestTarget target){
tabLabelPanelUpdate(target);
}
};
return servicesTabPanel;
}
@Override
public String getCount() {
if (servicesTabPanel == null){
return "0";
}
return Integer.toString(servicesTabPanel.getObjectListPanel().getSelectedObjectsCount());
}
});
// tabs.add(
// new CountablePanelTab(getPageBase().createStringResource("ObjectTypes.RESOURCE"), authorization) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public WebMarkupContainer createPanel(String panelId) {
// return new FocusTypeAssignmentPopupTabPanel(panelId, ObjectTypes.RESOURCE);
// }
//
// @Override
// public String getCount() {
// return "0";
// }
// });
return tabs;
}
private TabbedPanel getTabbedPanel(){
return (TabbedPanel) get(ID_FORM).get(ID_TABS_PANEL);
}
private void tabLabelPanelUpdate(AjaxRequestTarget target){
// TabbedPanel tabbedPanel = getTabbedPanel();
// Loop tabs = tabbedPanel.getTabsPanel();
// tabs.forEach(tabPanel -> {
// target.add(tabPanel.get(tabbedPanel.getTabLinkPanelId()));
// });
target.add(getTabbedPanel());
}
protected void addPerformed(AjaxRequestTarget target, List newAssignmentsList) {
getPageBase().hideMainPopup(target);
}
public int getWidth(){
return 900;
}
public int getHeight(){
return 1200;
}
public StringResourceModel getTitle(){
return createStringResource("TypedAssignablePanel.selectObjects");
}
public Component getComponent(){
return this;
}
}