01: package org.conform.wings.editor;
02:
03: import org.conform.PropertyMeta;
04: import org.wings.SComponent;
05: import org.wings.SCheckBox;
06:
07: public class DefaultEditorStyles {
08: public static void applyEditorAlignment(PropertyMeta propertyMeta,
09: SComponent component) {
10: String alignment = (String) propertyMeta
11: .getAttribute(PropertyMeta.ATTRIBUTE_ALIGNMENT);
12: String style = component.getStyle();
13:
14: boolean change = false;
15: boolean rightRequired = "right".equals(alignment);
16: boolean rightPresent = style.indexOf("right_align") == -1;
17: boolean addRight = rightRequired && !rightPresent;
18: boolean removeRight = !rightRequired && rightPresent;
19:
20: if (addRight) {
21: style = "right_align " + style;
22: change = true;
23: } else if (removeRight) {
24: style = style.replaceAll("right_align ", "");
25: change = true;
26: }
27:
28: boolean centerRequired = "center".equals(alignment);
29: boolean centerPresent = style.indexOf("center_align") == -1;
30: boolean addCenter = centerRequired && !centerPresent;
31: boolean removeCenter = !centerRequired && centerPresent;
32:
33: if (addCenter) {
34: style = "center_align " + style;
35: change = true;
36: } else if (removeCenter) {
37: style = style.replaceAll("center_align ", "");
38: change = true;
39: }
40:
41: if (change)
42: component.setStyle(style);
43: }
44:
45: public static void applyEditorState(PropertyMeta propertyMeta,
46: SComponent component, boolean erroneous) {
47: String style = component.getStyle();
48:
49: boolean readonly = !propertyMeta.isWritable();
50: boolean mandatory = propertyMeta.isMandatory()
51: && !(component instanceof SCheckBox);
52:
53: String requiredStyle = "formeditor_normal";
54: if (readonly)
55: requiredStyle = "formeditor_readonly";
56: else if (mandatory)
57: requiredStyle = "formeditor_mandatory";
58:
59: if (erroneous)
60: requiredStyle += "_erroneous";
61:
62: if (style.indexOf("formeditor_") == -1)
63: style = style + " " + requiredStyle;
64: else
65: style = style.replaceAll("formeditor_[_a-z]*",
66: requiredStyle);
67:
68: component.setStyle(style);
69: }
70:
71: public static void applyLabelState(PropertyMeta propertyMeta,
72: SComponent component) {
73: String style = component.getStyle();
74:
75: boolean readonly = !propertyMeta.isWritable();
76: boolean mandatory = propertyMeta.isMandatory();
77: boolean important = Boolean.TRUE.equals(propertyMeta
78: .getAttribute(PropertyMeta.ATTRIBUTE_IMPORTANT));
79:
80: String requiredStyle = "formlabel_normal";
81: if (readonly)
82: requiredStyle = "formlabel_readonly";
83: else if (mandatory)
84: requiredStyle = "formlabel_mandatory";
85:
86: if (important)
87: requiredStyle += "_important";
88:
89: if (style.indexOf("formlabel_") == -1)
90: style = requiredStyle + " " + style;
91: else
92: style = style
93: .replaceAll("formlabel_[_a-z]*", requiredStyle);
94:
95: component.setStyle(style);
96: }
97: }
|