-
Notifications
You must be signed in to change notification settings - Fork 188
/
DisplayNamePanel.java
238 lines (201 loc) · 9.49 KB
/
DisplayNamePanel.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* Copyright (c) 2010-2017 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.gui.api.component;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
public class DisplayNamePanel<C extends Containerable> extends BasePanel<C> {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(DisplayNamePanel.class);
private final static String ID_TYPE_IMAGE = "typeImage";
private final static String ID_DISPLAY_NAME = "displayName";
private final static String ID_IDENTIFIER = "identifier";
private final static String ID_RELATION = "relation";
private final static String ID_KIND_INTENT = "kindIntent";
private final static String ID_DESCRIPTION = "description";
private final static String ID_DESCRIPTION_LABELS = "descriptionLabels";
private final static String ID_NAVIGATE_TO_OBJECT = "navigateToObject";
public DisplayNamePanel(String id, IModel<C> model) {
super(id, model);
}
@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
}
private void initLayout() {
WebMarkupContainer typeImage = new WebMarkupContainer(ID_TYPE_IMAGE);
typeImage.setOutputMarkupId(true);
typeImage.add(AttributeModifier.append("class", createImageModel()));
add(typeImage);
Label name = new Label(ID_DISPLAY_NAME, createHeaderModel());
name.setOutputMarkupId(true);
add(name);
Label identifier = new Label(ID_IDENTIFIER, createIdentifierModel());
identifier.setOutputMarkupId(true);
identifier.add(new VisibleBehaviour(() -> isIdentifierVisible()));
add(identifier);
AjaxButton navigateToObject = new AjaxButton(ID_NAVIGATE_TO_OBJECT) {
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
if (DisplayNamePanel.this.getModelObject() instanceof ObjectType) {
ObjectType o = (ObjectType) DisplayNamePanel.this.getModelObject();
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(o.getOid());
ort.setType(WebComponentUtil.classToQName(DisplayNamePanel.this.getPageBase().getPrismContext(), o.getClass()));
WebComponentUtil.dispatchToObjectDetailsPage(ort, DisplayNamePanel.this, false);
}
}
};
navigateToObject.add(new VisibleBehaviour(() -> DisplayNamePanel.this.getModelObject() instanceof ObjectType &&
WebComponentUtil.getObjectDetailsPage(((ObjectType) DisplayNamePanel.this.getModelObject()).getClass()) != null));
navigateToObject.setOutputMarkupId(true);
add(navigateToObject);
Label relation = new Label(ID_RELATION, Model.of(getRelationLabel()));
relation.setOutputMarkupId(true);
relation.add(new VisibleBehaviour(() -> isRelationVisible()));
add(relation);
IModel<String> kindIntentLabelModel = getKindIntentLabelModel();
Label kindIntent = new Label(ID_KIND_INTENT, kindIntentLabelModel);
kindIntent.setOutputMarkupId(true);
kindIntent.add(new VisibleBehaviour(() -> isKindIntentVisible(kindIntentLabelModel)));
add(kindIntent);
ListView<String> descriptionLabels = new ListView<String>(ID_DESCRIPTION_LABELS, getDescriptionLabelsModel()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<String> item) {
item.add(new Label(ID_DESCRIPTION, item.getModel()));
}
};
add(descriptionLabels);
// add(new Label(ID_DESCRIPTION, getDescriptionLabelsModel()));
// add(new Label(ID_PENDING_OPERATION, getPendingOperationLabelModel()));
}
private boolean isObjectPolicyConfigurationType() {
if (QNameUtil.match(ObjectPolicyConfigurationType.COMPLEX_TYPE, getModelObject().asPrismContainerValue().getComplexTypeDefinition().getTypeName())) {
return true;
}
return false;
}
protected String createImageModel() {
if (getModelObject() == null) {
return "";
}
if (ConstructionType.class.isAssignableFrom(getModelObject().getClass())) {
return WebComponentUtil.createDefaultColoredIcon(ResourceType.COMPLEX_TYPE);
}
return WebComponentUtil.createDefaultColoredIcon(getModelObject().asPrismContainerValue().getComplexTypeDefinition().getTypeName());
}
private IModel<String> createHeaderModel() {
// TODO: align with DisplayNameModel
if (getModelObject() == null) {
return Model.of("");
}
if (ObjectType.class.isAssignableFrom(getModelObject().getClass())) {
return Model.of(WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_DISPLAY_NAME));
}
if (isObjectPolicyConfigurationType()) {
QName typeValue = WebComponentUtil.getValue(getModel().getObject().asPrismContainerValue(), ObjectPolicyConfigurationType.F_TYPE, QName.class);
ObjectReferenceType objectTemplate = ((ObjectPolicyConfigurationType) getModel().getObject()).getObjectTemplateRef();
if (objectTemplate == null || objectTemplate.getTargetName() == null) {
return Model.of("");
}
String objectTemplateNameValue = objectTemplate.getTargetName().toString();
StringBuilder sb = new StringBuilder();
if (typeValue != null) {
sb.append(typeValue.getLocalPart()).append(" - ");
}
sb.append(objectTemplateNameValue);
return Model.of(sb.toString());
}
PrismProperty<PolyString> name = getModelObject().asPrismContainerValue().findProperty(ObjectType.F_NAME);
if (name == null || name.isEmpty()) {
return Model.of("");
}
return Model.of(WebComponentUtil.getTranslatedPolyString(name.getRealValue()));
}
private IModel<String> createIdentifierModel() {
if (getModelObject() == null) {
return Model.of("");
}
if (AbstractRoleType.class.isAssignableFrom(getModelObject().getClass())) {
return Model.of(WebComponentUtil.getEffectiveName((ObjectType) getModelObject(), AbstractRoleType.F_IDENTIFIER));
}
return Model.of("");
}
private boolean isIdentifierVisible() {
if (getModelObject() == null) {
return false;
}
if (AbstractRoleType.class.isAssignableFrom(getModelObject().getClass())) {
return getModelObject().asPrismContainerValue().findProperty(AbstractRoleType.F_IDENTIFIER) != null;
}
return false;
}
// TODO: maybe move relation methods to subclass if we want this panel to be really reusable
private boolean isRelationVisible() {
return !WebComponentUtil.isDefaultRelation(getRelation());
}
private boolean isKindIntentVisible(IModel<String> kindIntentLabelModel) {
return kindIntentLabelModel != null && StringUtils.isNotEmpty(kindIntentLabelModel.getObject());
}
private String getRelationLabel() {
QName relation = getRelation();
if (relation == null) {
return "";
}
// TODO: localization?
return relation.getLocalPart();
}
protected IModel<String> getKindIntentLabelModel() {
// To be overridden in subclasses
return Model.of("");
}
protected IModel<String> getDescriptionLabelModel() {
if (getModel().getObject() != null && getModel().getObject().asPrismContainerValue().contains(ObjectType.F_DESCRIPTION)) {
return new PropertyModel<String>(getModel(), ObjectType.F_DESCRIPTION.getLocalPart());
}
return null;
}
protected IModel<List<String>> getDescriptionLabelsModel() {
List<String> descriptionLabels = new ArrayList<String>();
IModel<String> des = getDescriptionLabelModel();
if (des != null) {
descriptionLabels.add(des.getObject());
}
return new IModel<List<String>>() {
@Override
public List<String> getObject() {
return descriptionLabels;
}
};
}
protected QName getRelation() {
// To be overridden in subclasses
return null;
}
}