1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.renderer.impl;
17
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Layout;
20 import org.seasar.framework.beans.BeanDesc;
21 import org.seasar.framework.beans.PropertyDesc;
22 import org.seasar.framework.beans.factory.BeanDescFactory;
23 import org.seasar.uruma.component.CommonAttributes;
24 import org.seasar.uruma.component.LayoutInfo;
25 import org.seasar.uruma.component.UIComponent;
26 import org.seasar.uruma.component.UICompositeComponent;
27 import org.seasar.uruma.component.jface.CompositeComponent;
28 import org.seasar.uruma.renderer.layout.LayoutSupport;
29 import org.seasar.uruma.renderer.layout.LayoutSupportFactory;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public abstract class AbstractCompositeRenderer<COMPONENT_TYPE extends CompositeComponent, COMPOSITE_TYPE extends Composite>
46 extends AbstractControlRenderer<COMPONENT_TYPE, COMPOSITE_TYPE> {
47
48
49
50
51
52
53
54
55
56
57
58
59 abstract protected void doRenderComposite(
60 COMPONENT_TYPE compositeComponent, COMPOSITE_TYPE composite);
61
62
63
64
65 @Override
66 protected void inherit(final COMPONENT_TYPE uiComponent) {
67 super.inherit(uiComponent);
68 inheritCommonAttributes(uiComponent);
69 }
70
71
72
73
74
75 @Override
76 protected final void doRenderControl(
77 final COMPONENT_TYPE compositeComponent,
78 final COMPOSITE_TYPE control) {
79 setLayout(compositeComponent, control);
80
81 doRenderComposite(compositeComponent, control);
82 }
83
84
85
86
87
88
89
90
91
92
93
94 @SuppressWarnings("unchecked")
95 protected void setLayout(final COMPONENT_TYPE compositeComponent,
96 final COMPOSITE_TYPE control) {
97 LayoutInfo<?> layoutInfo = compositeComponent.getLayoutInfo();
98 if (layoutInfo != null) {
99 LayoutSupport layoutSupport = LayoutSupportFactory
100 .getLayoutSupport((Class<? extends LayoutInfo<?>>) layoutInfo
101 .getClass());
102 Layout layout = layoutSupport.createLayout(compositeComponent
103 .getLayoutInfo());
104 control.setLayout(layout);
105 }
106 }
107
108
109
110
111
112
113
114 protected void inheritCommonAttributes(
115 final COMPONENT_TYPE compositeComponent) {
116 UIComponent parent = compositeComponent.getParent();
117 if (parent == null) {
118 return;
119 }
120
121 if (!(parent instanceof UICompositeComponent)) {
122 return;
123 }
124
125 CommonAttributes parentAttributes = ((UICompositeComponent) parent)
126 .getCommonAttributes();
127 if (parentAttributes == null) {
128 return;
129 }
130
131 CommonAttributes commonAttributes = compositeComponent
132 .getCommonAttributes();
133 if (commonAttributes == null) {
134 compositeComponent.setCommonAttributes(parentAttributes);
135 } else {
136 BeanDesc desc = BeanDescFactory.getBeanDesc(commonAttributes
137 .getClass());
138 int size = desc.getPropertyDescSize();
139 for (int i = 0; i < size; i++) {
140 PropertyDesc pd = desc.getPropertyDesc(i);
141 if (pd.getValue(commonAttributes) == null) {
142 Object value = pd.getValue(parentAttributes);
143 pd.setValue(commonAttributes, value);
144 }
145 }
146 }
147 }
148 }