/
PrismContainerHeaderPanel.java
70 lines (46 loc) · 1.93 KB
/
PrismContainerHeaderPanel.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
package com.evolveum.midpoint.web.component.prism;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.model.IModel;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
public class PrismContainerHeaderPanel<C extends Containerable> extends PrismHeaderPanel<ContainerWrapper<C>>{
private static final long serialVersionUID = 1L;
private static final String ID_ADD_BUTTON = "addButton";
public PrismContainerHeaderPanel(String id, IModel<ContainerWrapper<C>> model) {
super(id, model);
}
@Override
protected void initButtons() {
add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isContainerMultivalue();
}
});
AjaxLink addButton = new AjaxLink(ID_ADD_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
addValue(target);
}
};
add(addButton);
}
private void addValue(AjaxRequestTarget target) {
ContainerWrapperFactory cwf = new ContainerWrapperFactory(getPageBase());
ContainerWrapper<C> containerWrapper = getModelObject();
ContainerValueWrapper<C> newContainerValue = cwf.createContainerValueWrapper(containerWrapper, containerWrapper.getItem().createNewValue(), containerWrapper.getObjectStatus(), ValueStatus.ADDED, containerWrapper.getPath());
newContainerValue.setShowEmpty(true, false);
getModelObject().addValue(newContainerValue);
onButtonClick(target);
}
private boolean isContainerMultivalue(){
return getModelObject().isVisible() && getModelObject().getItemDefinition().isMultiValue();
}
@Override
public String getLabel() {
return getModelObject() != null ? getModelObject().getDisplayName() : "";
}
}