/
TriStateFormGroup.java
143 lines (122 loc) · 6.22 KB
/
TriStateFormGroup.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
/*
* Copyright (c) 2018 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.gui.impl.component.form;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.web.component.input.TriStateComboPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
/**
* @author lazyman
* @author skublik
*/
public class TriStateFormGroup extends BasePanel<Boolean> {
private static final long serialVersionUID = 1L;
private static final String ID_VALUE = "value";
private static final String ID_VALUE_WRAPPER = "valueWrapper";
private static final String ID_LABEL_CONTAINER = "labelContainer";
private static final String ID_LABEL = "label";
private static final String ID_TOOLTIP = "tooltip";
private static final String ID_REQUIRED = "required";
private static final String ID_FEEDBACK = "feedback";
private static final String ID_PROPERTY_LABEL = "propertyLabel";
private static final String ID_ROW = "row";
public TriStateFormGroup(String id, IModel<Boolean> value, IModel<String> label, String labelCssClass, String textCssClass, boolean required, boolean isSimilarAsPropertyPanel) {
this(id, value, label, null, false, labelCssClass, textCssClass, required, isSimilarAsPropertyPanel);
}
public TriStateFormGroup(String id, IModel<Boolean> value, IModel<String> label, String labelCssClass, String textCssClass, boolean required) {
this(id, value, label, null, false, labelCssClass, textCssClass, required, false);
}
public TriStateFormGroup(String id, IModel<Boolean> value, IModel<String> label, String tooltipKey,
boolean isTooltipInModal, String labelCssClass, String textCssClass, boolean required) {
this(id, value, label, null, false, labelCssClass, textCssClass, required, false);
}
public TriStateFormGroup(String id, IModel<Boolean> value, IModel<String> label, String tooltipKey,
boolean isTooltipInModal, String labelCssClass, String textCssClass, boolean required, boolean isSimilarAsPropertyPanel) {
super(id, value);
initLayout(label, tooltipKey, isTooltipInModal, labelCssClass, textCssClass, required, isSimilarAsPropertyPanel);
}
private void initLayout(IModel<String> label, final String tooltipKey, boolean isTooltipInModal, String labelCssClass, String textCssClass,
boolean required, boolean isSimilarAsPropertyPanel) {
WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
add(labelContainer);
Label l = new Label(ID_LABEL, label);
if (StringUtils.isNotEmpty(labelCssClass)) {
labelContainer.add(AttributeAppender.prepend("class", labelCssClass));
}
if(isSimilarAsPropertyPanel) {
labelContainer.add(AttributeAppender.prepend("class", " col-xs-2 prism-property-label "));
} else {
labelContainer.add(AttributeAppender.prepend("class", " control-label "));
}
labelContainer.add(l);
Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
tooltipLabel.add(new AttributeAppender("data-original-title", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return getString(tooltipKey);
}
}));
tooltipLabel.add(new InfoTooltipBehavior(isTooltipInModal));
tooltipLabel.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible() {
return tooltipKey != null;
}
});
tooltipLabel.setOutputMarkupId(true);
tooltipLabel.setOutputMarkupPlaceholderTag(true);
labelContainer.add(tooltipLabel);
WebMarkupContainer requiredContainer = new WebMarkupContainer(ID_REQUIRED);
requiredContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return required;
}
});
labelContainer.add(requiredContainer);
WebMarkupContainer propertyLabel = new WebMarkupContainer(ID_PROPERTY_LABEL);
WebMarkupContainer rowLabel = new WebMarkupContainer(ID_ROW);
WebMarkupContainer valueWrapper = new WebMarkupContainer(ID_VALUE_WRAPPER);
if (StringUtils.isNotEmpty(textCssClass)) {
valueWrapper.add(AttributeAppender.prepend("class", textCssClass));
}
if(isSimilarAsPropertyPanel) {
propertyLabel.add(AttributeAppender.prepend("class", " col-md-10 prism-property-value "));
rowLabel.add(AttributeAppender.prepend("class", " row "));
}
propertyLabel.add(rowLabel);
rowLabel.add(valueWrapper);
add(propertyLabel);
TriStateComboPanel triStateCombo = new TriStateComboPanel(ID_VALUE, getModel());;
valueWrapper.add(triStateCombo);
FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(triStateCombo.getBaseFormComponent()));
feedback.setOutputMarkupId(true);
valueWrapper.add(feedback);
}
public TriStateComboPanel getValue(){
return (TriStateComboPanel) get(createComponentPath(ID_PROPERTY_LABEL, ID_ROW, ID_VALUE_WRAPPER, ID_VALUE));
}
}