/
AbstractObjectTabPanel.java
157 lines (128 loc) · 5.28 KB
/
AbstractObjectTabPanel.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
/*
* Copyright (c) 2010-2016 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.objectdetails;
import javax.xml.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.prism.PrismPropertyPanel;
import com.evolveum.midpoint.web.model.PropertyWrapperFromObjectWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
/**
* @author semancik
*/
public abstract class AbstractObjectTabPanel<O extends ObjectType> extends Panel {
private static final long serialVersionUID = 1L;
protected static final String ID_MAIN_FORM = "mainForm";
private static final Trace LOGGER = TraceManager.getTrace(AbstractObjectTabPanel.class);
private LoadableModel<ObjectWrapper<O>> objectWrapperModel;
private PageBase pageBase;
private Form mainForm;
public AbstractObjectTabPanel(String id, Form mainForm, LoadableModel<ObjectWrapper<O>> objectWrapperModel, PageBase pageBase) {
super(id);
this.objectWrapperModel = objectWrapperModel;
this.mainForm = mainForm;
this.pageBase = pageBase;
}
public LoadableModel<ObjectWrapper<O>> getObjectWrapperModel() {
return objectWrapperModel;
}
public ObjectWrapper<O> getObjectWrapper() {
return objectWrapperModel.getObject();
}
protected PrismContext getPrismContext() {
return pageBase.getPrismContext();
}
protected PageParameters getPageParameters() {
return pageBase.getPageParameters();
}
public PageBase getPageBase() {
return pageBase;
}
public Form getMainForm() {
return mainForm;
}
public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return PageBase.createStringResourceStatic(this, resourceKey, objects);
// return new StringResourceModel(resourceKey, this, null, resourceKey, objects);
}
public String getString(String resourceKey, Object... objects) {
return createStringResource(resourceKey, objects).getString();
}
protected String createComponentPath(String... components) {
return StringUtils.join(components, ":");
}
protected void showResult(OperationResult result) {
pageBase.showResult(result);
}
protected void showResult(OperationResult result, boolean showSuccess) {
pageBase.showResult(result, false);
}
protected WebMarkupContainer getFeedbackPanel() {
return pageBase.getFeedbackPanel();
}
public Object findParam(String param, String oid, OperationResult result) {
Object object = null;
for (OperationResult subResult : result.getSubresults()) {
if (subResult != null && subResult.getParams() != null) {
if (subResult.getParams().get(param) != null
&& subResult.getParams().get(OperationResult.PARAM_OID) != null
&& subResult.getParams().get(OperationResult.PARAM_OID).equals(oid)) {
return subResult.getParams().get(param);
}
object = findParam(param, oid, subResult);
}
}
return object;
}
protected void showModalWindow(String id, AjaxRequestTarget target) {
ModalWindow window = (ModalWindow) get(id);
window.show(target);
target.add(getFeedbackPanel());
}
protected void showModalWindow(Component body, IModel<String> title, AjaxRequestTarget target) {
getPageBase().setMainPopupContent(body);
getPageBase().setMainPopupTitle(title);
getPageBase().showMainPopup(target);
target.add(getFeedbackPanel());
}
protected void addPrismPropertyPanel(MarkupContainer parentComponent, String id, QName propertyName) {
addPrismPropertyPanel(parentComponent, id, new ItemPath(propertyName));
}
protected void addPrismPropertyPanel(MarkupContainer parentComponent, String id, ItemPath propertyPath) {
parentComponent.add(
new PrismPropertyPanel(id,
new PropertyWrapperFromObjectWrapperModel<PolyString,O>(getObjectWrapperModel(), propertyPath),
mainForm, pageBase));
}
}