Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 13123 Details for
Bug 63235
[KeyBindings] Cut/Copy/Paste/SelectAll don't work in Swing widgets in dialogs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
A version of WidgetMethodHandler based on comment 15 that appears to fix the problem
(text/plain), 6.45 KB, created by
David Green
on 2004-07-09 19:47:21 EDT
(
hide
)
Description:
A version of WidgetMethodHandler based on comment 15 that appears to fix the problem
Filename:
MIME Type:
Creator:
David Green
Created:
2004-07-09 19:47:21 EDT
Size:
6.45 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/cpl-v10.html > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >package org.eclipse.ui.internal.commands.ws; > >import java.lang.reflect.InvocationTargetException; >import java.lang.reflect.Method; >import java.util.Collections; >import java.util.HashMap; >import java.util.Map; > >import javax.swing.FocusManager; >import javax.swing.SwingUtilities; > >import org.eclipse.core.runtime.IConfigurationElement; >import org.eclipse.core.runtime.IExecutableExtension; >import org.eclipse.swt.SWT; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Control; >import org.eclipse.swt.widgets.Display; >import org.eclipse.ui.commands.AbstractHandler; >import org.eclipse.ui.commands.ExecutionException; > >/** > * Handles the cut command in both dialogs and windows. This handler is enabled > * if the focus control supports the "cut" method. > * > * @since 3.0 > */ >public class WidgetMethodHandler extends AbstractHandler implements > IExecutableExtension { > > /** > * The name of the attribute controlling the enabled state. > */ > private static final String ATTRIBUTE_ENABLED = "enabled"; //$NON-NLS-1$ > > /** > * The name of the attribute for the identifier. > */ > private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ > > /** > * The parameters to pass to the method this handler invokes. This handler > * always passes no parameters. > */ > protected static final Class[] NO_PARAMETERS = new Class[0]; > > /** > * The name of the method to be invoked by this handler. This value should > * never be <code>null</code>. > */ > protected String methodName; > > /* > * (non-Javadoc) > * > * @see org.eclipse.ui.commands.IHandler#execute(java.lang.Object) > */ > public Object execute(Map parameterValuesByName) throws ExecutionException { > final Method methodToExecute = getMethodToExecute(); > if (methodToExecute != null) { > try { > final Control focusControl = Display.getCurrent() > .getFocusControl(); > if ((focusControl instanceof Composite) > && ((((Composite) focusControl).getStyle() & SWT.EMBEDDED) != 0)) { > final FocusManager focusManager = FocusManager.getCurrentManager(); > final java.awt.Component focusComponent = focusManager.getFocusOwner(); > if (focusComponent != null) { > Runnable methodRunnable = new Runnable() { > public void run() { > try { > methodToExecute.invoke(focusComponent, null); > } catch (IllegalAccessException e) { > // The method is protected, so do nothing. > } catch (InvocationTargetException e) { > e.printStackTrace(); > } > } > }; > SwingUtilities.invokeLater(methodRunnable); > } > } else { > methodToExecute.invoke(focusControl, null); > } > } catch (IllegalAccessException e) { > // The method is protected, so do nothing. > } catch (InvocationTargetException e) { > throw new ExecutionException( > "An exception occurred while executing " //$NON-NLS-1$ > + getMethodToExecute(), e.getTargetException()); > } > } > > return null; > } > > public Map getAttributeValuesByName() { > Map attributeValuesByName = new HashMap(); > attributeValuesByName.put(ATTRIBUTE_ENABLED, > getMethodToExecute() == null ? Boolean.FALSE : Boolean.TRUE); > attributeValuesByName.put(ATTRIBUTE_ID, null); > return Collections.unmodifiableMap(attributeValuesByName); > } > > /** > * Looks up the method on the focus control. > * > * @return The method on the focus control; <code>null</code> if none. > */ > protected Method getMethodToExecute() { > final Control focusControl = Display.getCurrent().getFocusControl(); > Method method = null; > > if (focusControl != null) { > Class clazz = focusControl.getClass(); > while (clazz != null) { > try { > System.out.println("clazz = " + clazz.getName()); > method = clazz.getMethod(methodName, NO_PARAMETERS); > } catch (NoSuchMethodException e) { > clazz = clazz.getSuperclass(); > } > } > } > > if ((method == null) > && (focusControl instanceof Composite) > && ((((Composite) focusControl).getStyle() & SWT.EMBEDDED) != 0)) { > /* > * We couldn't find the appropriate method on the current focus > * control. It is possible that the current focus control is an > * embedded SWT composite, which could be containing some Swing > * components. If this is the case, then we should try to pass > * through to the underlying Swing component hierarchy. Insha'allah, > * this will work. > */ > final FocusManager focusManager = FocusManager.getCurrentManager(); > final java.awt.Component focusComponent = focusManager.getFocusOwner(); > Class clazz = focusComponent.getClass(); > > try { > method = clazz.getMethod(methodName, NO_PARAMETERS); > } catch (NoSuchMethodException e) { > clazz = clazz.getSuperclass(); > } > } > System.out.println("method = " + method); > > return method; > } > > /* > * (non-Javadoc) > * > * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, > * java.lang.String, java.lang.Object) > */ > public void setInitializationData(IConfigurationElement config, > String propertyName, Object data) { > // The data is really just a string (i.e., the method name). > methodName = data.toString(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 63235
:
12342
|
12344
|
13123
|
13124