|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.handlers; |
| 12 |
|
| 13 |
import java.lang.reflect.Method; |
| 14 |
|
| 15 |
import org.eclipse.core.commands.ExecutionEvent; |
| 16 |
|
| 17 |
import org.eclipse.swt.SWT; |
| 18 |
import org.eclipse.swt.widgets.Control; |
| 19 |
import org.eclipse.swt.widgets.Display; |
| 20 |
import org.eclipse.swt.widgets.Shell; |
| 21 |
|
| 22 |
/** |
| 23 |
* This handler is an adaptation of the widget method handler that implements |
| 24 |
* page traversal via {@link SWT#TRAVERSE_PAGE_NEXT} and |
| 25 |
* {@link SWT#TRAVERSE_PAGE_PREVIOUS} events. |
| 26 |
* |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
public class TraversePageHandler extends WidgetMethodHandler { |
| 30 |
|
| 31 |
/** |
| 32 |
* The parameters for traverse(int). |
| 33 |
*/ |
| 34 |
private static final Class[] METHOD_PARAMETERS = { int.class }; |
| 35 |
|
| 36 |
public final Object execute(final ExecutionEvent event) { |
| 37 |
Control focusControl = Display.getCurrent().getFocusControl(); |
| 38 |
if (focusControl != null) { |
| 39 |
int traversal= "next".equals(methodName) ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; //$NON-NLS-1$ |
| 40 |
Control control = focusControl; |
| 41 |
do { |
| 42 |
if (control.traverse (traversal)) |
| 43 |
return null; |
| 44 |
if (control instanceof Shell) |
| 45 |
return null; |
| 46 |
control = control.getParent(); |
| 47 |
} while (control != null); |
| 48 |
} |
| 49 |
|
| 50 |
return null; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Looks up the traverse(int) method on the given focus control. |
| 55 |
* |
| 56 |
* @return The method on the focus control; <code>null</code> if none. |
| 57 |
*/ |
| 58 |
protected Method getMethodToExecute() { |
| 59 |
final Control focusControl = Display.getCurrent().getFocusControl(); |
| 60 |
if (focusControl != null) { |
| 61 |
try { |
| 62 |
return focusControl.getClass().getMethod("traverse", //$NON-NLS-1$ |
| 63 |
METHOD_PARAMETERS); |
| 64 |
} catch (NoSuchMethodException e) { |
| 65 |
// Do nothing. |
| 66 |
} |
| 67 |
} |
| 68 |
return null; |
| 69 |
} |
| 70 |
|
| 71 |
} |