/
ChooseFocusTypeAndRelationDialogPanel.java
165 lines (129 loc) · 5.33 KB
/
ChooseFocusTypeAndRelationDialogPanel.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
package com.evolveum.midpoint.web.component.dialog;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.model.util.ListModel;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.form.DropDownFormGroup;
import com.evolveum.midpoint.web.component.input.ListMultipleChoicePanel;
import com.evolveum.midpoint.web.component.input.QNameObjectTypeChoiceRenderer;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
public class ChooseFocusTypeAndRelationDialogPanel extends BasePanel implements Popupable{
private static final String ID_OBJECT_TYPE = "type";
private static final String ID_RELATION = "relation";
private static final String ID_BUTTON_OK = "ok";
private static final String ID_CANCEL_OK = "cancel";
private static final String ID_WARNING_MESSAGE = "warningMessage";
private IModel<String> messageModel = null;
public ChooseFocusTypeAndRelationDialogPanel(String id) {
this(id, null);
}
public ChooseFocusTypeAndRelationDialogPanel(String id, IModel<String> messageModel) {
super(id);
this.messageModel = messageModel;
}
@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
}
private void initLayout(){
DropDownFormGroup<QName> type = new DropDownFormGroup<QName>(ID_OBJECT_TYPE, Model.of(getDefaultObjectType()), Model.ofList(getSupportedObjectTypes()),
new QNameObjectTypeChoiceRenderer(), createStringResource("chooseFocusTypeAndRelationDialogPanel.type"),
"chooseFocusTypeAndRelationDialogPanel.tooltip.type", true, "col-md-4", "col-md-8", true);
type.getInput().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
type.setOutputMarkupId(true);
type.add(new VisibleBehaviour(() -> isFocusTypeSelectorVisible()));
add(type);
IModel<Map<String, String>> options = new Model(null);
Map<String, String> optionsMap = new HashMap<>();
// optionsMap.put("nonSelectedText", createStringResource("LoggingConfigPanel.appenders.Inherit").getString());
options.setObject(optionsMap);
ListMultipleChoicePanel<QName> relation = new ListMultipleChoicePanel<QName>(ID_RELATION, new ListModel<>(),
new ListModel<QName>(getSupportedRelations()), new QNameObjectTypeChoiceRenderer(), options);
relation.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
relation.setOutputMarkupId(true);
add(relation);
Label label = new Label(ID_WARNING_MESSAGE, messageModel);
label.add(new VisibleBehaviour(() -> messageModel != null && messageModel.getObject() != null));
add(label);
AjaxButton confirmButton = new AjaxButton(ID_BUTTON_OK, createStringResource("Button.ok")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
DropDownFormGroup<QName> type = (DropDownFormGroup<QName>) getParent().get(ID_OBJECT_TYPE);
QName typeChosen = type.getModelObject();
ListMultipleChoicePanel<QName> relation = (ListMultipleChoicePanel<QName>) getParent().get(ID_RELATION);
Collection<QName> relationChosen = relation.getModelObject();
ChooseFocusTypeAndRelationDialogPanel.this.okPerformed(typeChosen, relationChosen, target);
getPageBase().hideMainPopup(target);
}
};
add(confirmButton);
AjaxButton cancelButton = new AjaxButton(ID_CANCEL_OK,
createStringResource("Button.cancel")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
getPageBase().hideMainPopup(target);
}
};
add(cancelButton);
}
protected void okPerformed(QName type, Collection<QName> relation, AjaxRequestTarget target) {
// TODO Auto-generated method stub
}
protected List<QName> getSupportedObjectTypes() {
return WebComponentUtil.createFocusTypeList(true);
}
protected QName getDefaultObjectType() {
List<QName> supportedObjectTypes = getSupportedObjectTypes();
if (CollectionUtils.isEmpty(supportedObjectTypes)) {
return FocusType.COMPLEX_TYPE;
}
return supportedObjectTypes.iterator().next();
}
protected List<QName> getSupportedRelations() {
return WebComponentUtil.getAllRelations(getPageBase());
}
protected boolean isFocusTypeSelectorVisible() {
return true;
}
@Override
public int getWidth() {
return 400;
}
@Override
public int getHeight() {
return 300;
}
@Override
public String getWidthUnit(){
return "px";
}
@Override
public String getHeightUnit(){
return "px";
}
@Override
public StringResourceModel getTitle() {
return new StringResourceModel("ChooseFocusTypeDialogPanel.chooseType");
}
@Override
public Component getComponent() {
return this;
}
}