-
Notifications
You must be signed in to change notification settings - Fork 188
/
WizardStep.java
160 lines (132 loc) · 5.36 KB
/
WizardStep.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
/*
* Copyright (c) 2010-2013 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;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.Definition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.wizard.IWizard;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* @author lazyman
*/
public class WizardStep extends org.apache.wicket.extensions.wizard.WizardStep {
private OperationResult result;
private PageBase pageBase;
public WizardStep(PageBase pageBase) {
this.pageBase = pageBase;
setTitleModel(new StringResourceModel("WizardStep.title", this, null, "WizardStep.title"));
}
@Override
public Component getHeader(String id, Component parent, IWizard wizard) {
return new Label(id, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return getTitle();
}
});
}
public PageBase getPageBase() {
return pageBase;
}
public String getString(String resourceKey, Object... objects) {
return createStringResource(resourceKey, objects).getString();
}
public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return new StringResourceModel(resourceKey, this, null, resourceKey, objects);
}
public StringResourceModel createStringResource(Enum e) {
return createStringResource(e, null);
}
public StringResourceModel createStringResource(Enum e, String prefix) {
return createStringResource(e, prefix, null);
}
public StringResourceModel createStringResource(Enum e, String prefix, String nullKey) {
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(prefix)) {
sb.append(prefix).append('.');
}
if (e == null) {
if (StringUtils.isNotEmpty(nullKey)) {
sb.append(nullKey);
} else {
sb = new StringBuilder();
}
} else {
sb.append(e.getDeclaringClass().getSimpleName()).append('.');
sb.append(e.name());
}
return createStringResource(sb.toString());
}
protected String createComponentPath(String... components) {
return StringUtils.join(components, ":");
}
protected List<QName> loadResourceObjectClassList(IModel<PrismObject<ResourceType>> model, Trace LOGGER, String message){
List<QName> list = new ArrayList<>();
try {
ResourceSchema schema = RefinedResourceSchema.getResourceSchema(model.getObject(), getPageBase().getPrismContext());
if(schema != null){
for(Definition def: schema.getDefinitions()){
list.add(def.getTypeName());
}
}
} catch (Exception e){
LoggingUtils.logException(LOGGER, message, e);
error(message + " " + e.getMessage());
}
return list;
}
protected IValidator<String> createObjectClassValidator(final IModel<List<QName>> model){
return new IValidator<String>() {
@Override
public void validate(IValidatable<String> validated) {
String value = validated.getValue();
List<QName> list = model.getObject();
List<String> stringList = new ArrayList<>();
for(QName q: list){
stringList.add(q.getLocalPart());
}
if(!stringList.contains(value)){
error(createStringResource("SchemaHandlingStep.message.validationError", value).getString());
AjaxRequestTarget target = getRequestCycle().find(AjaxRequestTarget.class);
target.add(getPageBase().getFeedbackPanel());
}
}
};
}
public OperationResult getResult() {
return result;
}
public void setResult(OperationResult result) {
this.result = result;
}
}