-
Notifications
You must be signed in to change notification settings - Fork 188
/
ExecuteChangeOptionsPanel.java
164 lines (142 loc) · 7.95 KB
/
ExecuteChangeOptionsPanel.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
/*
* Copyright (c) 2010-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.web.page.admin.users.component;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TracingProfileType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import java.util.List;
/**
* @author lazyman
*/
public class ExecuteChangeOptionsPanel extends BasePanel<ExecuteChangeOptionsDto> {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(ExecuteChangeOptionsPanel.class);
private static final String ID_FORCE = "force";
private static final String ID_FORCE_CONTAINER = "forceContainer";
private static final String ID_RECONCILE = "reconcile";
private static final String ID_RECONCILE_CONTAINER = "reconcileContainer";
private static final String ID_RECONCILE_AFFECTED = "reconcileAffected";
private static final String ID_RECONCILE_AFFECTED_CONTAINER = "reconcileAffectedContainer";
private static final String ID_EXECUTE_AFTER_ALL_APPROVALS = "executeAfterAllApprovals";
private static final String ID_EXECUTE_AFTER_ALL_APPROVALS_CONTAINER = "executeAfterAllApprovalsContainer";
private static final String ID_KEEP_DISPLAYING_RESULTS = "keepDisplayingResults";
private static final String ID_KEEP_DISPLAYING_RESULTS_CONTAINER = "keepDisplayingResultsContainer";
private static final String ID_TRACING = "tracing";
private static final String ID_TRACING_CONTAINER = "tracingContainer";
private static final String FORCE_LABEL = "ExecuteChangeOptionsPanel.label.force";
private static final String FORCE_HELP = "ExecuteChangeOptionsPanel.label.force.help";
private static final String RECONCILE_LABEL = "ExecuteChangeOptionsPanel.label.reconcile";
private static final String RECONCILE_HELP = "ExecuteChangeOptionsPanel.label.reconcile.help";
private static final String RECONCILE_AFFECTED_LABEL = "ExecuteChangeOptionsPanel.label.reconcileAffected";
private static final String RECONCILE_AFFECTED_HELP = "ExecuteChangeOptionsPanel.label.reconcileAffected.help";
private static final String EXECUTE_AFTER_ALL_APPROVALS_LABEL = "ExecuteChangeOptionsPanel.label.executeAfterAllApprovals";
private static final String EXECUTE_AFTER_ALL_APPROVALS_HELP = "ExecuteChangeOptionsPanel.label.executeAfterAllApprovals.help";
private static final String KEEP_DISPLAYING_RESULTS_LABEL = "ExecuteChangeOptionsPanel.label.keepDisplayingResults";
private static final String KEEP_DISPLAYING_RESULTS_HELP = "ExecuteChangeOptionsPanel.label.keepDisplayingResults.help";
private final boolean showReconcile;
private final boolean showReconcileAffected;
private final boolean showKeepDisplayingResults;
public ExecuteChangeOptionsPanel(String id, IModel<ExecuteChangeOptionsDto> model,
boolean showReconcile, boolean showReconcileAffected) {
super(id, model);
this.showReconcile = showReconcile;
this.showReconcileAffected = showReconcileAffected;
showKeepDisplayingResults = getWebApplicationConfiguration().isProgressReportingEnabled();
}
public ExecuteChangeOptionsPanel(String id, IModel<ExecuteChangeOptionsDto> model,
boolean showReconcile, boolean showReconcileAffected, boolean showKeepDisplayingResults) {
super(id, model);
this.showReconcile = showReconcile;
this.showReconcileAffected = showReconcileAffected;
this.showKeepDisplayingResults = showKeepDisplayingResults;
}
@Override
protected void onInitialize(){
super.onInitialize();
initLayout();
}
private void initLayout() {
createContainer(ID_FORCE_CONTAINER,
new PropertyModel<>(getModel(), ExecuteChangeOptionsDto.F_FORCE),
FORCE_LABEL,
FORCE_HELP,
true);
createContainer(ID_RECONCILE_CONTAINER,
new PropertyModel<>(getModel(), ExecuteChangeOptionsDto.F_RECONCILE),
RECONCILE_LABEL,
RECONCILE_HELP,
showReconcile);
createContainer(ID_RECONCILE_AFFECTED_CONTAINER,
new PropertyModel<>(getModel(), ExecuteChangeOptionsDto.F_RECONCILE_AFFECTED),
RECONCILE_AFFECTED_LABEL,
RECONCILE_AFFECTED_HELP,
showReconcileAffected);
createContainer(ID_EXECUTE_AFTER_ALL_APPROVALS_CONTAINER,
new PropertyModel<>(getModel(), ExecuteChangeOptionsDto.F_EXECUTE_AFTER_ALL_APPROVALS),
EXECUTE_AFTER_ALL_APPROVALS_LABEL,
EXECUTE_AFTER_ALL_APPROVALS_HELP,
true);
createContainer(ID_KEEP_DISPLAYING_RESULTS_CONTAINER,
new PropertyModel<>(getModel(), ExecuteChangeOptionsDto.F_KEEP_DISPLAYING_RESULTS),
KEEP_DISPLAYING_RESULTS_LABEL,
KEEP_DISPLAYING_RESULTS_HELP,
showKeepDisplayingResults);
boolean canRecordTrace;
try {
canRecordTrace = getPageBase().isAuthorized(ModelAuthorizationAction.RECORD_TRACE.getUrl());
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't check trace recording authorization", t);
canRecordTrace = false;
}
WebMarkupContainer tracingContainer = new WebMarkupContainer(ID_TRACING_CONTAINER);
tracingContainer.setVisible(canRecordTrace && WebModelServiceUtils.isEnableExperimentalFeature(getPageBase()));
add(tracingContainer);
DropDownChoice tracing = new DropDownChoice<>(ID_TRACING, PropertyModel.of(getModel(), ExecuteChangeOptionsDto.F_TRACING),
PropertyModel.of(getModel(), ExecuteChangeOptionsDto.F_TRACING_CHOICES), new IChoiceRenderer<TracingProfileType>() {
@Override
public Object getDisplayValue(TracingProfileType profile) {
if (profile == null) {
return "(none)";
} else if (profile.getDisplayName() != null) {
return profile.getDisplayName();
} else if (profile.getName() != null) {
return profile.getName();
} else {
return "(unnamed profile)";
}
}
@Override
public String getIdValue(TracingProfileType object, int index) {
return String.valueOf(index);
}
@Override
public TracingProfileType getObject(String id, IModel<? extends List<? extends TracingProfileType>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
});
tracing.setNullValid(true);
tracingContainer.add(tracing);
}
private void createContainer(String containerId, IModel<Boolean> checkboxModel, String labelKey, String helpKey, boolean show) {
CheckBoxPanel panel = new CheckBoxPanel(containerId, checkboxModel, null, createStringResource(labelKey),
createStringResource(helpKey, WebComponentUtil.getMidpointCustomSystemName(getPageBase(), "midPoint")));
panel.setVisible(show);
add(panel);
}
}