-
Notifications
You must be signed in to change notification settings - Fork 188
/
ItemPanel.java
152 lines (111 loc) · 4.7 KB
/
ItemPanel.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
/*
* 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.gui.impl.prism.panel;
import java.util.Collection;
import java.util.Collections;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemEditabilityHandler;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemVisibilityHandler;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.web.page.admin.server.RefreshableTabPanel;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.impl.component.data.column.AbstractItemWrapperColumnPanel;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
/**
* @author katka
*
*/
public abstract class ItemPanel<VW extends PrismValueWrapper<?>, IW extends ItemWrapper> extends BasePanel<IW> implements RefreshableTabPanel {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(ItemPanel.class);
private static final String DOT_CLASS = ItemPanel.class.getName() + "";
private static final String ID_VALUES = "values";
private ItemPanelSettings itemPanelSettings;
public ItemPanel(String id, IModel<IW> model, ItemPanelSettings itemPanelSettings) {
super(id, model);
this.itemPanelSettings = itemPanelSettings;
}
@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
setOutputMarkupId(true);
}
private void initLayout() {
//ugly hack TODO FIME - prism context is lost during serialization/deserialization.. find better way how to do it.
if (getModelObject() != null) {
getModelObject().revive(getPrismContext());
}
Component headerPanel = createHeaderPanel();
headerPanel.add(new VisibleBehaviour(() -> getHeaderVisibility()));
add(headerPanel);
ListView<VW> valuesPanel = createValuesPanel();
add(valuesPanel);
}
protected boolean getHeaderVisibility() {
if (!isHeaderVisible()) {
return false;
}
return getParent().findParent(AbstractItemWrapperColumnPanel.class) == null;
}
protected abstract Component createHeaderPanel();
protected ListView<VW> createValuesPanel() {
ListView<VW> values = new ListView<VW>(ID_VALUES, new PropertyModel<>(getModel(), "values")) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<VW> item) {
Component panel = createValuePanel(item);
panel.add(new VisibleBehaviour(() -> item.getModelObject().isVisible()));
}
};
return values;
}
protected void removeValue(VW valueToRemove, AjaxRequestTarget target) throws SchemaException {
LOGGER.debug("Removing value of {}", valueToRemove);
getModelObject().remove(valueToRemove, getPageBase());
target.add(ItemPanel.this);
}
// VALUE REGION
protected abstract Component createValuePanel(ListItem<VW> item);
protected abstract <PV extends PrismValue> PV createNewValue(IW itemWrapper);
public ItemVisibilityHandler getVisibilityHandler() {
if (itemPanelSettings == null) {
return null;
}
return itemPanelSettings.getVisibilityHandler();
}
public ItemEditabilityHandler getEditabilityHandler() {
if (itemPanelSettings == null) {
return null;
}
return itemPanelSettings.getEditabilityHandler();
}
protected boolean isHeaderVisible() {
if (itemPanelSettings == null) {
return true;
}
return itemPanelSettings.isHeaderVisible();
}
public ItemPanelSettings getSettings() {
return itemPanelSettings;
}
@Override
public Collection<Component> getComponentsToUpdate() {
return Collections.singleton(this);
}
}