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 package info.magnolia.ui.workbench.column.definition;
35
36 import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
37
38 import info.magnolia.annotation.deprecation.MgnlDeprecated;
39 import info.magnolia.i18nsystem.I18nText;
40 import info.magnolia.ui.workbench.column.AbstractColumnFormatter;
41
42 import javax.inject.Inject;
43
44 import org.apache.commons.lang3.StringUtils;
45
46 import com.vaadin.v7.data.Property;
47 import com.vaadin.v7.ui.Table;
48
49
50
51
52
53 @MgnlDeprecated(since = "6.2.3", description = "No direct replacement.")
54 public class BooleanPropertyColumnDefinition extends AbstractColumnDefinition {
55
56 private DisplayMode displayMode = DisplayMode.ICON_ONLY;
57 private String falseIcon;
58 private String trueIcon = "icon-tick";
59 private String falseLabel;
60 private String trueLabel;
61
62 public BooleanPropertyColumnDefinition() {
63 setFormatterClass(BooleanPropertyColumnFormatter.class);
64 setDisplayInChooseDialog(false);
65 setWidth(46);
66 }
67
68 @Override
69 public Class<?> getType() {
70 return Boolean.class;
71 }
72
73
74
75
76 public static enum DisplayMode {
77
78
79 ICON_ONLY,
80
81
82 TEXT_ONLY,
83
84
85 ICON_AND_TEXT
86 }
87
88
89
90
91 public static class BooleanPropertyColumnFormatter extends AbstractColumnFormatter<BooleanPropertyColumnDefinition> {
92
93 @Inject
94 public BooleanPropertyColumnFormatter(BooleanPropertyColumnDefinition definition) {
95 super(definition);
96 }
97
98 @Override
99 public String generateCell(Table source, Object itemId, Object columnId) {
100 StringBuilder sb = new StringBuilder();
101
102
103 Property<?> property = source.getContainerProperty(itemId, columnId);
104 boolean value = false;
105 if (property == null) {
106
107 } else if (Boolean.class.isAssignableFrom(property.getType())) {
108 value = ((Boolean) property.getValue()).booleanValue();
109 } else if (String.class.isAssignableFrom(property.getType())) {
110 value = Boolean.parseBoolean((String) property.getValue());
111 }
112
113
114 if (definition.getDisplayMode() != DisplayMode.TEXT_ONLY) {
115 if (value && StringUtils.isNotBlank(definition.getTrueIcon())) {
116 sb.append("<span class=\"").append(escapeHtml4(definition.getTrueIcon())).append("\"></span>");
117 } else if (!value && StringUtils.isNotBlank(definition.getFalseIcon())) {
118 sb.append("<span class=\"").append(escapeHtml4(definition.getFalseIcon())).append("\"></span>");
119 }
120 }
121 if (definition.getDisplayMode() != DisplayMode.ICON_ONLY) {
122 if (value && StringUtils.isNotBlank(definition.getTrueLabel())) {
123 sb.append("<span>").append(escapeHtml4(definition.getTrueLabel())).append("</span>");
124 } else if (!value && StringUtils.isNotBlank(definition.getFalseLabel())) {
125 sb.append("<span>").append(escapeHtml4(definition.getFalseLabel())).append("</span>");
126 }
127 }
128
129 return StringUtils.isNotBlank(sb) ? sb.toString() : null;
130 }
131 }
132
133
134
135
136
137
138 public DisplayMode getDisplayMode() {
139 return displayMode;
140 }
141
142 public void setDisplayMode(DisplayMode displayMode) {
143 this.displayMode = displayMode;
144 }
145
146
147
148
149 public String getFalseIcon() {
150 return falseIcon;
151 }
152
153 public void setFalseIcon(String falseIcon) {
154 this.falseIcon = falseIcon;
155 }
156
157
158
159
160
161 public String getTrueIcon() {
162 return trueIcon;
163 }
164
165 public void setTrueIcon(String trueIcon) {
166 this.trueIcon = trueIcon;
167 }
168
169
170
171
172 @I18nText
173 public String getFalseLabel() {
174 return falseLabel;
175 }
176
177 public void setFalseLabel(String falseLabel) {
178 this.falseLabel = falseLabel;
179 }
180
181
182
183
184 @I18nText
185 public String getTrueLabel() {
186 return trueLabel;
187 }
188
189 public void setTrueLabel(String trueLabel) {
190 this.trueLabel = trueLabel;
191 }
192 }