1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.uruma.binding.value; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.eclipse.swt.widgets.Button; |
22 | |
import org.eclipse.swt.widgets.Label; |
23 | |
import org.eclipse.swt.widgets.Spinner; |
24 | |
import org.eclipse.swt.widgets.Text; |
25 | |
import org.seasar.uruma.binding.value.binder.BrowserValueBinder; |
26 | |
import org.seasar.uruma.binding.value.binder.ComboViewerValueBinder; |
27 | |
import org.seasar.uruma.binding.value.binder.DateTimeValueBinder; |
28 | |
import org.seasar.uruma.binding.value.binder.GenericValueBinder; |
29 | |
import org.seasar.uruma.binding.value.binder.StatusLineManagerValueBinder; |
30 | |
import org.seasar.uruma.binding.value.binder.TableValueBinder; |
31 | |
import org.seasar.uruma.binding.value.binder.TableViewerValueBinder; |
32 | |
import org.seasar.uruma.binding.value.binder.TreeViewerValueBinder; |
33 | |
import org.seasar.uruma.core.UrumaMessageCodes; |
34 | |
import org.seasar.uruma.log.UrumaLogger; |
35 | |
import org.seasar.uruma.util.AssertionUtil; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class ValueBinderFactory implements UrumaMessageCodes { |
43 | 4 | private static final UrumaLogger logger = UrumaLogger |
44 | |
.getLogger(ValueBinderFactory.class); |
45 | |
|
46 | 4 | private static final Map<Class<?>, ValueBinder> binderMap = new HashMap<Class<?>, ValueBinder>(); |
47 | |
|
48 | |
static { |
49 | 4 | addValueBinder(new GenericValueBinder<Label>(Label.class, "text")); |
50 | 4 | addValueBinder(new GenericValueBinder<Text>(Text.class, "text")); |
51 | 4 | addValueBinder(new GenericValueBinder<Spinner>(Spinner.class, |
52 | |
"selection")); |
53 | 4 | addValueBinder(new GenericValueBinder<Button>(Button.class, "selection")); |
54 | 4 | addValueBinder(new ComboViewerValueBinder()); |
55 | 4 | addValueBinder(new TableViewerValueBinder()); |
56 | 4 | addValueBinder(new TableValueBinder()); |
57 | 4 | addValueBinder(new TreeViewerValueBinder()); |
58 | 4 | addValueBinder(new StatusLineManagerValueBinder()); |
59 | 4 | addValueBinder(new BrowserValueBinder()); |
60 | 4 | addValueBinder(new DateTimeValueBinder()); |
61 | 4 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public static ValueBinder getValueBinder(final Class<?> widgetClass) { |
72 | 44 | ValueBinder binder = binderMap.get(widgetClass); |
73 | 44 | if (binder == null) { |
74 | 4 | logger.log(VALUE_BINDER_NOT_FOUND, widgetClass.getName()); |
75 | |
} |
76 | 44 | return binder; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public static void addValueBinder(final ValueBinder valueBinder) { |
86 | 48 | AssertionUtil.assertNotNull("valueBinder", valueBinder); |
87 | 48 | Class<?> widgetClass = valueBinder.getWidgetType(); |
88 | 48 | AssertionUtil.assertNotNull("widgetClass", widgetClass); |
89 | |
|
90 | 48 | binderMap.put(widgetClass, valueBinder); |
91 | 48 | } |
92 | |
} |