1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.binding.widget;
17
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.swt.widgets.Control;
20 import org.seasar.framework.beans.BeanDesc;
21 import org.seasar.framework.beans.PropertyDesc;
22 import org.seasar.uruma.context.PartContext;
23 import org.seasar.uruma.context.WidgetHandle;
24
25
26
27
28
29
30 public class WidgetBinder {
31 private WidgetBinder() {
32
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public static void bindWidgets(final Object target,
55 final PartContext context) {
56 BeanDesc beanDesc = context.getPartActionDesc().getBeanDesc();
57
58 int pdSize = beanDesc.getPropertyDescSize();
59 for (int i = 0; i < pdSize; i++) {
60 PropertyDesc pd = beanDesc.getPropertyDesc(i);
61 Class<?> propertyType = pd.getPropertyType();
62 String propertyName = pd.getPropertyName();
63 WidgetHandle handle = context.getWidgetHandle(propertyName);
64 if (handle != null) {
65 if (propertyType.isAssignableFrom(handle.getWidgetClass())) {
66 pd.setValue(target, handle.getWidget());
67 } else if (handle.instanceOf(Viewer.class)) {
68 Viewer viewer = handle.<Viewer> getCastWidget();
69 Control coltrol = viewer.getControl();
70 if (propertyType.isAssignableFrom(coltrol.getClass())) {
71 pd.setValue(target, coltrol);
72 }
73 }
74 }
75 }
76 }
77 }