1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp.binding;
17
18 import java.lang.reflect.Method;
19
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.ISelectionListener;
23 import org.eclipse.ui.IWorkbenchPart;
24 import org.seasar.uruma.binding.method.MethodBinding;
25 import org.seasar.uruma.binding.method.MethodCallback;
26 import org.seasar.uruma.binding.method.SingleParamTypeMethodBinding;
27 import org.seasar.uruma.binding.value.ValueBindingSupport;
28 import org.seasar.uruma.binding.widget.WidgetBinder;
29 import org.seasar.uruma.context.PartContext;
30 import org.seasar.uruma.context.WindowContext;
31 import org.seasar.uruma.core.UrumaMessageCodes;
32 import org.seasar.uruma.log.UrumaLogger;
33 import org.seasar.uruma.util.AssertionUtil;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public class GenericSelectionListener implements ISelectionListener,
58 MethodCallback {
59 private static final UrumaLogger logger = UrumaLogger
60 .getLogger(GenericSelectionListener.class);
61
62 private PartContext context;
63
64 private SingleParamTypeMethodBinding methodBinding;
65
66
67
68
69
70
71
72
73
74 public GenericSelectionListener(final PartContext context,
75 final SingleParamTypeMethodBinding methodBinding) {
76 AssertionUtil.assertNotNull("context", context);
77 AssertionUtil.assertNotNull("methodBinding", methodBinding);
78
79 this.context = context;
80 this.methodBinding = methodBinding;
81 this.methodBinding.setCallback(this);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public void selectionChanged(final IWorkbenchPart part,
103 final ISelection selection) {
104 try {
105 if (selection instanceof IStructuredSelection) {
106 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
107 Object[] selectedModels = structuredSelection.toArray();
108 if (selectedModels.length > 0) {
109
110 WidgetBinder
111 .bindWidgets(methodBinding.getTarget(), context);
112
113 ValueBindingSupport.importSelection(context);
114 ValueBindingSupport.importValue(context);
115
116 methodBinding.invoke(selectedModels);
117 }
118 }
119 } catch (Throwable ex) {
120 logger.log(UrumaMessageCodes.EXCEPTION_OCCURED_INVOKING_METHOD,
121 methodBinding.toString());
122 logger.log(ex);
123 }
124 }
125
126
127
128
129
130 public Object callback(final MethodBinding binding, final Object[] args,
131 final Object returnValue) {
132 ValueBindingSupport.exportValue(context);
133 ValueBindingSupport.exportSelection(context);
134 return returnValue;
135 }
136 }