/
MultiButtonTable.java
169 lines (146 loc) · 6.8 KB
/
MultiButtonTable.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
package com.evolveum.midpoint.web.component.data;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.assignment.*;
import com.evolveum.midpoint.web.page.admin.roles.PageRole;
import com.evolveum.midpoint.web.page.self.PageAssignmentDetails;
import com.evolveum.midpoint.web.session.SessionStorage;
import com.evolveum.midpoint.web.session.UsersStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import java.util.ArrayList;
import java.util.List;
/**
* Created honchar.
*/
public class MultiButtonTable extends BasePanel<List<AssignmentEditorDto>> {
private static final String ID_ROW = "row";
private static final String ID_CELL = "cell";
private static final String ID_BUTTON_TYPE_ICON = "typeIcon";
private static final String ID_BUTTON_LABEL = "buttonLabel";
private static final String ID_BUTTON_PLUS_ICON = "plusIcon";
private static final String ID_BUTTON = "assignmentButton";
private int itemsCount = 0;
private int itemsPerRow = 0;
private boolean plusIconClicked = false;
public MultiButtonTable (String id){
super(id);
}
public MultiButtonTable (String id, int itemsPerRow, IModel<List<AssignmentEditorDto>> model){
super(id, model);
this.itemsPerRow = itemsPerRow;
initLayout();
}
private void initLayout(){
itemsCount = getModel() != null ? (getModel().getObject() != null ? getModel().getObject().size() : 0) : 0;
RepeatingView rows = new RepeatingView(ID_ROW);
rows.setOutputMarkupId(true);
if (itemsCount > 0){
int index = 0;
List<AssignmentEditorDto> assignmentsList = getModelObject();
for (int rowNumber = 0; rowNumber <= itemsCount / itemsPerRow; rowNumber++){
WebMarkupContainer rowContainer = new WebMarkupContainer(rows.newChildId());
rows.add(rowContainer);
RepeatingView columns = new RepeatingView(ID_CELL);
columns.setOutputMarkupId(true);
rowContainer.add(columns);
for (int colNumber = 0; colNumber < itemsPerRow; colNumber++){
WebMarkupContainer colContainer = new WebMarkupContainer(columns.newChildId());
columns.add(colContainer);
populateCell(colContainer, assignmentsList.get(index));
index++;
if (index >= assignmentsList.size()){
break;
}
}
}
}
add(rows);
}
protected void populateCell(WebMarkupContainer cellContainer, final AssignmentEditorDto assignment){
AjaxLink assignmentButton = new AjaxLink(ID_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
if (!plusIconClicked) {
IModel<AssignmentEditorDto> assignmentModel = new IModel<AssignmentEditorDto>() {
@Override
public AssignmentEditorDto getObject() {
assignment.setMinimized(false);
assignment.setSimpleView(true);
return assignment;
}
@Override
public void setObject(AssignmentEditorDto assignmentEditorDto) {
}
@Override
public void detach() {
}
};
setResponsePage(new PageAssignmentDetails(assignmentModel));
} else {
plusIconClicked = false;
}
}
};
Label plusLabel = new Label(ID_BUTTON_PLUS_ICON, "+");
// plusLabel.add(new AttributeAppender("title", getPageBase().createStringResource("MultiButtonPanel.plusIconTitle")));
plusLabel.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
addAssignmentPerformed(assignment, target);
}
});
assignmentButton.add(plusLabel);
WebMarkupContainer icon = new WebMarkupContainer(ID_BUTTON_TYPE_ICON);
icon.add(new AttributeAppender("class", getIconClass(assignment.getType())));
assignmentButton.add(icon);
Label nameLabel = new Label(ID_BUTTON_LABEL, assignment.getName());
// nameLabel.add(new AjaxEventBehavior("click") {
// private static final long serialVersionUID = 1L;
// @Override
// protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
//
// }
// });
assignmentButton.add(nameLabel);
cellContainer.add(assignmentButton);
}
protected void assignmentDetailsPerformed(AjaxRequestTarget target){
}
private String getIconClass(AssignmentEditorDtoType type){
if (AssignmentEditorDtoType.ROLE.equals(type)){
return "fa fa-street-view object-role-color";
}else if (AssignmentEditorDtoType.SERVICE.equals(type)){
return "fa fa-cloud object-service-color";
}else if (AssignmentEditorDtoType.ORG_UNIT.equals(type)){
return "fa fa-building object-org-color";
} else {
return "";
}
}
private void addAssignmentPerformed(AssignmentEditorDto assignment, AjaxRequestTarget target){
plusIconClicked = true;
UsersStorage storage = getPageBase().getSessionStorage().getUsers();
if (storage.getAssignmentShoppingCart() == null){
storage.setAssignmentShoppingCart(new ArrayList<AssignmentEditorDto>());
}
List<AssignmentEditorDto> assignmentsToAdd = storage.getAssignmentShoppingCart();
assignmentsToAdd.add(assignment);
storage.setAssignmentShoppingCart(assignmentsToAdd);
AssignmentCatalogPanel parent = (AssignmentCatalogPanel)MultiButtonTable.this.getParent();
parent.reloadCartButton(target);
}
}