Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 63235
Collapse All | Expand All

(-)WidgetMethodHandler.java (-8 / +51 lines)
Lines 10-23 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.ui.internal.commands.ws;
11
package org.eclipse.ui.internal.commands.ws;
12
12
13
import java.awt.Component;
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import java.lang.reflect.Method;
15
import java.util.Collections;
16
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.HashMap;
17
import java.util.Map;
18
import java.util.Map;
18
19
20
import javax.swing.FocusManager;
21
19
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IExecutableExtension;
23
import org.eclipse.core.runtime.IExecutableExtension;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.ui.commands.AbstractHandler;
28
import org.eclipse.ui.commands.AbstractHandler;
Lines 65-71 Link Here
65
            try {
70
            try {
66
                final Control focusControl = Display.getCurrent()
71
                final Control focusControl = Display.getCurrent()
67
                        .getFocusControl();
72
                        .getFocusControl();
68
                methodToExecute.invoke(focusControl, null);
73
                if ((focusControl instanceof Composite)
74
                && ((((Composite) focusControl).getStyle() & SWT.EMBEDDED) != 0)) {
75
                    final FocusManager focusManager = FocusManager.getCurrentManager();
76
                    final Component focusComponent = focusManager.getFocusOwner();
77
                    methodToExecute.invoke(focusComponent, null);
78
                } else {
79
                    methodToExecute.invoke(focusControl, null);
80
                }
69
            } catch (IllegalAccessException e) {
81
            } catch (IllegalAccessException e) {
70
                // The method is protected, so do nothing.
82
                // The method is protected, so do nothing.
71
            } catch (InvocationTargetException e) {
83
            } catch (InvocationTargetException e) {
Lines 93-107 Link Here
93
     */
105
     */
94
    protected Method getMethodToExecute() {
106
    protected Method getMethodToExecute() {
95
        final Control focusControl = Display.getCurrent().getFocusControl();
107
        final Control focusControl = Display.getCurrent().getFocusControl();
96
        try {
108
        Method method = null;
97
            if (focusControl != null) {
109
98
                return focusControl.getClass().getMethod(methodName, NO_PARAMETERS);
110
        if (focusControl != null) {
111
            Class clazz = focusControl.getClass();
112
            while (clazz != null) {
113
                try {
114
                    System.out.println("clazz = " + clazz.getName());
115
                    method = clazz.getMethod(methodName, NO_PARAMETERS);
116
                } catch (NoSuchMethodException e) {
117
                    clazz = clazz.getSuperclass();
118
                }
99
            }
119
            }
100
        } catch (NoSuchMethodException e) {
101
            // Fall through....
102
        }
120
        }
103
        
121
104
        return null;
122
        if ((method == null)
123
                && (focusControl instanceof Composite)
124
                && ((((Composite) focusControl).getStyle() & SWT.EMBEDDED) != 0)) {
125
            /*
126
             * We couldn't find the appropriate method on the current focus
127
             * control. It is possible that the current focus control is an
128
             * embedded SWT composite, which could be containing some Swing
129
             * components. If this is the case, then we should try to pass
130
             * through to the underlying Swing component hierarchy. Insha'allah,
131
             * this will work.
132
             */
133
            final FocusManager focusManager = FocusManager.getCurrentManager();
134
            final Component focusComponent = focusManager.getFocusOwner();
135
            Class clazz = focusComponent.getClass();
136
            
137
            while (clazz != null) {
138
                try {
139
                    method = clazz.getMethod(methodName, NO_PARAMETERS);
140
                } catch (NoSuchMethodException e) {
141
                    clazz = clazz.getSuperclass();
142
                }
143
            }
144
        }
145
        System.out.println("method = " + method);
146
147
        return method;
105
    }
148
    }
106
149
107
    /*
150
    /*

Return to bug 63235