1 11 package org.eclipse.ui.internal.commands.ws; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Method ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.swt.graphics.Point; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.ui.commands.ExecutionException; 22 23 31 public class SelectAllHandler extends WidgetMethodHandler { 32 33 36 private static final Class [] METHOD_PARAMETERS = { Point.class }; 37 38 41 public Object execute(Map parameterValuesByName) throws ExecutionException { 42 final Method methodToExecute = getMethodToExecute(); 43 if (methodToExecute != null) { 44 try { 45 final Control focusControl = Display.getCurrent() 46 .getFocusControl(); 47 final int numParams = methodToExecute.getParameterTypes().length; 48 49 if (numParams == 0) { 50 methodToExecute.invoke(focusControl, null); 52 53 } else if (numParams == 1) { 54 final Method textLimitAccessor = focusControl.getClass() 56 .getMethod("getTextLimit", NO_PARAMETERS); final Integer textLimit = (Integer ) textLimitAccessor 58 .invoke(focusControl, null); 59 final Object [] parameters = { new Point(0, textLimit 60 .intValue()) }; 61 methodToExecute.invoke(focusControl, parameters); 62 63 } else { 64 68 throw new ExecutionException( 69 "Too many parameters on select all", new Exception ()); 71 } 72 73 } catch (IllegalAccessException e) { 74 76 } catch (InvocationTargetException e) { 77 throw new ExecutionException( 78 "An exception occurred while executing " + getMethodToExecute(), e.getTargetException()); 80 81 } catch (NoSuchMethodException e) { 82 84 } 85 } 86 87 return null; 88 } 89 90 95 protected Method getMethodToExecute() { 96 Method method = super.getMethodToExecute(); 97 98 if (method == null) { 100 final Control focusControl = Display.getCurrent().getFocusControl(); 101 try { 102 method = focusControl.getClass().getMethod("setSelection", METHOD_PARAMETERS); 104 } catch (NoSuchMethodException e) { 105 } 107 } 108 109 return method; 110 } 111 112 116 public void setInitializationData(IConfigurationElement config, 117 String propertyName, Object data) { 118 methodName = "selectAll"; } 121 } | Popular Tags |