/
SynchronizationActionEditorDialog.java
210 lines (175 loc) · 9.02 KB
/
SynchronizationActionEditorDialog.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
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.component.wizard.resource.component.synchronization;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.form.DropDownFormGroup;
import com.evolveum.midpoint.web.component.form.TextAreaFormGroup;
import com.evolveum.midpoint.web.component.form.TextFormGroup;
import com.evolveum.midpoint.web.component.wizard.resource.dto.SynchronizationActionTypeDto;
import com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard;
import com.evolveum.midpoint.xml.ns._public.common.common_3.BeforeAfterType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationActionType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import java.util.List;
/**
* @author shood
* */
public class SynchronizationActionEditorDialog extends ModalWindow{
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_NAME = "name";
private static final String ID_DESCRIPTION = "description";
private static final String ID_HANDLER_URI = "handlerUri";
private static final String ID_ORDER = "order";
private static final String ID_BUTTON_SAVE = "saveButton";
private static final String ID_BUTTON_CANCEL = "cancelButton";
private static final String ID_LABEL_SIZE = "col-md-4";
private static final String ID_INPUT_SIZE = "col-md-8";
private IModel<SynchronizationActionTypeDto> model;
private IModel<SynchronizationActionType> inputModel;
private boolean initialized;
public SynchronizationActionEditorDialog(String id, final IModel<SynchronizationActionType> action){
super(id);
inputModel = action;
model = new LoadableModel<SynchronizationActionTypeDto>(false) {
@Override
protected SynchronizationActionTypeDto load() {
if(action != null){
return new SynchronizationActionTypeDto(action.getObject());
} else {
return new SynchronizationActionTypeDto(null);
}
}
};
setOutputMarkupId(true);
setTitle(createStringResource("SynchronizationActionEditorDialog.label"));
showUnloadConfirmation(false);
setCssClassName(ModalWindow.CSS_CLASS_GRAY);
setCookieName(SynchronizationActionEditorDialog.class.getSimpleName() + ((int) (Math.random() * 100)));
setInitialWidth(600);
setInitialHeight(400);
setWidthUnit("px");
WebMarkupContainer content = new WebMarkupContainer(getContentId());
content.setOutputMarkupId(true);
setContent(content);
}
public void updateModel(AjaxRequestTarget target, SynchronizationActionType action){
model.setObject(new SynchronizationActionTypeDto(action));
inputModel = new Model<>(action);
target.add(getContent());
}
public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return PageBase.createStringResourceStatic(this, resourceKey, objects);
// return new StringResourceModel(resourceKey, this, null, resourceKey, objects);
}
@Override
protected void onBeforeRender(){
super.onBeforeRender();
if(initialized){
return;
}
initLayout((WebMarkupContainer) get(getContentId()));
initialized = true;
}
private void initLayout(WebMarkupContainer content){
Form form = new com.evolveum.midpoint.web.component.form.Form(ID_MAIN_FORM);
form.setOutputMarkupId(true);
content.add(form);
TextFormGroup name = new TextFormGroup(ID_NAME, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".name"),
createStringResource("SynchronizationActionEditorDialog.label.name"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
form.add(name);
TextAreaFormGroup description = new TextAreaFormGroup(ID_DESCRIPTION, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".description"),
createStringResource("SynchronizationActionEditorDialog.label.description"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
form.add(description);
DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions> handlerUri = new DropDownFormGroup<SynchronizationActionTypeDto.HandlerUriActions>(ID_HANDLER_URI,
new PropertyModel<>(model, SynchronizationActionTypeDto.F_HANDLER_URI),
WebComponentUtil.createReadonlyModelFromEnum(SynchronizationActionTypeDto.HandlerUriActions.class),
new EnumChoiceRenderer<>(this), createStringResource("SynchronizationActionEditorDialog.label.handlerUri"),
createStringResource("SynchronizationStep.action.tooltip.handlerUri",
WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard)getPage(), "midpoint.default.system.name")),
true, ID_LABEL_SIZE, ID_INPUT_SIZE, false, false){
@Override
protected DropDownChoice createDropDown(String id, IModel<List<SynchronizationActionTypeDto.HandlerUriActions>> choices,
IChoiceRenderer<SynchronizationActionTypeDto.HandlerUriActions> renderer, boolean required){
DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
choice.setNullValid(true);
return choice;
}
};
form.add(handlerUri);
DropDownFormGroup<BeforeAfterType> order = new DropDownFormGroup<BeforeAfterType>(ID_ORDER, new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT + ".order"),
WebComponentUtil.createReadonlyModelFromEnum(BeforeAfterType.class), new EnumChoiceRenderer<>(this),
createStringResource("SynchronizationActionEditorDialog.label.order"),
createStringResource("SynchronizationStep.action.tooltip.order",
WebComponentUtil.getMidpointCustomSystemName((PageResourceWizard)getPage(), "midpoint.default.system.name")),
true, ID_LABEL_SIZE, ID_INPUT_SIZE, false, false){
@Override
protected DropDownChoice createDropDown(String id, IModel<List<BeforeAfterType>> choices, IChoiceRenderer<BeforeAfterType> renderer, boolean required){
DropDownChoice choice = new DropDownChoice<>(id, getModel(), choices, renderer);
choice.setNullValid(true);
return choice;
}
};
form.add(order);
initButtons(form);
}
private void initButtons(Form form){
AjaxLink cancel = new AjaxLink(ID_BUTTON_CANCEL) {
@Override
public void onClick(AjaxRequestTarget target) {
cancelPerformed(target);
}
};
form.add(cancel);
AjaxSubmitLink save = new AjaxSubmitLink(ID_BUTTON_SAVE) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
savePerformed(target);
}
};
form.add(save);
}
private void cancelPerformed(AjaxRequestTarget target){
close(target);
}
protected void savePerformed(AjaxRequestTarget target){
if(inputModel != null){
inputModel.setObject(model.getObject().prepareDtoToSave());
} else {
model.getObject().prepareDtoToSave();
inputModel = new PropertyModel<>(model, SynchronizationActionTypeDto.F_ACTION_OBJECT);
}
((PageResourceWizard) getPage()).refreshIssues(target);
updateComponents(target);
close(target);
}
public void updateComponents(AjaxRequestTarget target){
//Override this if update of component(s) holding this modal window is needed
}
}