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 61145 Details for
Bug 177806
[Trim] Provide a way for a trim control to participate in commands/handler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Actual (mostly) working code v01
focusNoApi-v01.txt (text/plain), 17.84 KB, created by
Paul Webster
on 2007-03-16 14:07:14 EDT
(
hide
)
Description:
Actual (mostly) working code v01
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2007-03-16 14:07:14 EDT
Size:
17.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/Workbench.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java,v >retrieving revision 1.431 >diff -u -r1.431 Workbench.java >--- Eclipse UI/org/eclipse/ui/internal/Workbench.java 16 Mar 2007 14:37:51 -0000 1.431 >+++ Eclipse UI/org/eclipse/ui/internal/Workbench.java 16 Mar 2007 18:00:38 -0000 >@@ -140,6 +140,7 @@ > import org.eclipse.ui.internal.intro.IIntroRegistry; > import org.eclipse.ui.internal.intro.IntroDescriptor; > import org.eclipse.ui.internal.keys.BindingService; >+import org.eclipse.ui.internal.menus.FocusControlSourceProvider; > import org.eclipse.ui.internal.menus.WorkbenchMenuService; > import org.eclipse.ui.internal.misc.Policy; > import org.eclipse.ui.internal.misc.StatusUtil; >@@ -169,6 +170,7 @@ > import org.eclipse.ui.internal.util.Util; > import org.eclipse.ui.intro.IIntroManager; > import org.eclipse.ui.keys.IBindingService; >+import org.eclipse.ui.menus.IFocusService; > import org.eclipse.ui.menus.IMenuService; > import org.eclipse.ui.operations.IWorkbenchOperationSupport; > import org.eclipse.ui.progress.IProgressService; >@@ -1625,12 +1627,23 @@ > contextService.addSourceProvider(currentSelectionSourceProvider); > menuService.addSourceProvider(currentSelectionSourceProvider); > sourceProviderService.registerProvider(currentSelectionSourceProvider); >+ > actionSetSourceProvider = new ActionSetSourceProvider(); > evaluationService.addSourceProvider(actionSetSourceProvider); > handlerService[0].addSourceProvider(actionSetSourceProvider); > contextService.addSourceProvider(actionSetSourceProvider); > menuService.addSourceProvider(actionSetSourceProvider); > sourceProviderService.registerProvider(actionSetSourceProvider); >+ >+ FocusControlSourceProvider focusControl = new FocusControlSourceProvider(); >+ serviceLocator.registerService(IFocusService.class, focusControl); >+ evaluationService.addSourceProvider(focusControl); >+ handlerService[0].addSourceProvider(focusControl); >+ contextService.addSourceProvider(focusControl); >+ menuService.addSourceProvider(focusControl); >+ sourceProviderService.registerProvider(focusControl); >+ >+ > menuSourceProvider = new MenuSourceProvider(); > evaluationService.addSourceProvider(menuSourceProvider); > handlerService[0].addSourceProvider(menuSourceProvider); >Index: Eclipse UI/org/eclipse/ui/ISources.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/ISources.java,v >retrieving revision 1.11 >diff -u -r1.11 ISources.java >--- Eclipse UI/org/eclipse/ui/ISources.java 15 Mar 2007 13:09:39 -0000 1.11 >+++ Eclipse UI/org/eclipse/ui/ISources.java 16 Mar 2007 18:00:38 -0000 >@@ -46,10 +46,10 @@ > * <b>Note in 3.3:</b> > * </p> > * <p> >- * Currently, source variables are not extensible by user plugins, and >- * the number of bits available for resolving conflicts is limited. When >- * the variable sources become user extensible a new conflict resolution >- * mechanism will be implemented. >+ * Currently, source variables are not extensible by user plugins, and the >+ * number of bits available for resolving conflicts is limited. When the >+ * variable sources become user extensible a new conflict resolution mechanism >+ * will be implemented. > * </p> > * <p> > * This interface is not intended to be implemented or extended by clients. >@@ -92,12 +92,14 @@ > /** > * The variable name for the active contexts. This is for use with the > * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. >+ * > * @since 3.2 > */ > public static final String ACTIVE_CONTEXT_NAME = "activeContexts"; //$NON-NLS-1$ > > /** > * The priority given when the source includes a particular action set. >+ * > * @since 3.2 > */ > public static final int ACTIVE_ACTION_SETS = 1 << 8; >@@ -105,6 +107,7 @@ > /** > * The variable name for the active action sets. This is for use with the > * {@link ISourceProvider} and {@link IEvaluationContext}. >+ * > * @since 3.2 > */ > public static final String ACTIVE_ACTION_SETS_NAME = "activeActionSets"; //$NON-NLS-1$ >@@ -123,6 +126,7 @@ > /** > * The priority given when the source includes the currently active > * workbench window shell. >+ * > * @since 3.2 > */ > public static final int ACTIVE_WORKBENCH_WINDOW_SHELL = 1 << 12; >@@ -131,6 +135,7 @@ > * The variable name for the active workbench window shell. This is for use > * with the <code>ISourceProvider</code> and > * <code>IEvaluationContext</code>. >+ * > * @since 3.2 > */ > public static final String ACTIVE_WORKBENCH_WINDOW_SHELL_NAME = "activeWorkbenchWindowShell"; //$NON-NLS-1$ >@@ -146,15 +151,15 @@ > * the <code>ISourceProvider</code> and <code>IEvaluationContext</code>. > */ > public static final String ACTIVE_WORKBENCH_WINDOW_NAME = "activeWorkbenchWindow"; //$NON-NLS-1$ >- >+ > /** >- * The priority given when the source includes subordinate properties of the currently active >- * workbench window. >+ * The priority given when the source includes subordinate properties of the >+ * currently active workbench window. > * > * @since 3.3 > */ > public static final int ACTIVE_WORKBENCH_WINDOW_SUBORDINATE = 1 << 15; >- >+ > /** > * The variable name for the coolbar visibility state of the active > * workbench window. This is for use with the <code>ISourceProvider</code> >@@ -164,7 +169,7 @@ > */ > public static final String ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME = ACTIVE_WORKBENCH_WINDOW_NAME > + ".isCoolbarVisible"; //$NON-NLS-1$ >- >+ > /** > * The variable name for the perspective bar visibility state of the active > * workbench window. This is for use with the <code>ISourceProvider</code> >@@ -183,6 +188,7 @@ > /** > * The variable name for the active editor part. This is for use with the > * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. >+ * > * @since 3.2 > */ > public static final String ACTIVE_EDITOR_NAME = "activeEditor"; //$NON-NLS-1$ >@@ -249,12 +255,14 @@ > /** > * The variable name for the active selection. This is for use with the > * <code>ISourceProvider</code> and <code>IEvaluationContext</code>. >+ * > * @since 3.2 > */ > public static final String ACTIVE_CURRENT_SELECTION_NAME = "selection"; //$NON-NLS-1$ > > /** > * The priority given when the source includes the current menu. >+ * > * @since 3.2 > */ > public static final int ACTIVE_MENU = 1 << 31; >@@ -262,23 +270,40 @@ > /** > * The variable name for the active menu. This is for use with the > * {@link ISourceProvider} and {@link IEvaluationContext}. >+ * > * @since 3.2 > */ > public static final String ACTIVE_MENU_NAME = "activeMenu"; //$NON-NLS-1$ >- >+ > /** > * The variable name for the <b>local</b> selection, available while a > * context menu is visible. > * > * @since 3.3 > */ >- public static final String ACTIVE_MENU_SELECTION_NAME = "activeMenuSelection"; //$NON-NLS-1$ >- >+ public static final String ACTIVE_MENU_SELECTION_NAME = "activeMenuSelection"; //$NON-NLS-1$ >+ > /** > * The variable name for the <b>local</b> editor input which is sometimes > * available while a context menu is visible. > * > * @since 3.3 > */ >- public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput"; //$NON-NLS-1$ >+ public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput"; //$NON-NLS-1$ >+ >+ /** >+ * The variable name for the active focus Control, which is sometimes >+ * available. >+ * >+ * @since 3.3 >+ */ >+ public static final String ACTIVE_FOCUS_CONTROL_NAME = "activeFocusControl"; //$NON-NLS-1$ >+ >+ /** >+ * The variable name for the active focus Control id, which is sometimes >+ * available. >+ * >+ * @since 3.3 >+ */ >+ public static final String ACTIVE_FOCUS_CONTROL_ID_NAME = "activeFocusControlId"; //$NON-NLS-1$ > } >Index: Eclipse UI/org/eclipse/ui/menus/IFocusService.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/menus/IFocusService.java >diff -N Eclipse UI/org/eclipse/ui/menus/IFocusService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/menus/IFocusService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.menus; >+ >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * Tracks focusGained and focusLost events for a Control registered with this >+ * service, and provides them as variables to the application evaluation context >+ * for evaluation be the various services. >+ * >+ * @since 3.3 >+ */ >+public interface IFocusService { >+ /** >+ * A Control for the service to track. We will remove ourselves as a >+ * listener on a dispose. >+ * >+ * @param control >+ * the control. Must not be <code>null</code>. >+ * @param id >+ * the unique ID for this control. Must not be <code>null</code>. >+ */ >+ public void addTrackerFor(Control control, String id); >+ >+ /** >+ * No longer track focus events for this control. Use this method when the >+ * control should no longer be tracked, but is not disposed. >+ * >+ * @param control >+ * the control registered with the service. Must not be >+ * <code>null</code>. >+ */ >+ public void removeTrackerFor(Control control); >+} >Index: Eclipse UI/org/eclipse/ui/internal/menus/FocusControlSourceProvider.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/menus/FocusControlSourceProvider.java >diff -N Eclipse UI/org/eclipse/ui/internal/menus/FocusControlSourceProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/menus/FocusControlSourceProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,149 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.menus; >+ >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.events.FocusListener; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Widget; >+import org.eclipse.ui.AbstractSourceProvider; >+import org.eclipse.ui.ISources; >+import org.eclipse.ui.menus.IFocusService; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class FocusControlSourceProvider extends AbstractSourceProvider >+ implements IFocusService { >+ >+ /** >+ * The names of the sources supported by this source provider. >+ */ >+ private static final String[] PROVIDED_SOURCE_NAMES = new String[] { >+ ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, ISources.ACTIVE_FOCUS_CONTROL_NAME }; >+ >+ Map controlToId = new HashMap(); >+ private FocusListener focusListener; >+ >+ private String currentId; >+ >+ private Control currentControl; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.menus.IFocusService#addTrackerFor(org.eclipse.swt.widgets.Control, >+ * java.lang.String) >+ */ >+ public void addTrackerFor(Control control, String id) { >+ if (control.isDisposed()) { >+ return; >+ } >+ controlToId.put(control, id); >+ control.addFocusListener(getFocusListener()); >+ } >+ >+ /** >+ * @return >+ */ >+ private FocusListener getFocusListener() { >+ if (focusListener == null) { >+ focusListener = new FocusListener() { >+ public void focusGained(FocusEvent e) { >+ focusIn(e.widget); >+ } >+ >+ public void focusLost(FocusEvent e) { >+ focusIn(null); >+ } >+ }; >+ } >+ return focusListener; >+ } >+ >+ /** >+ * @param widget >+ */ >+ private void focusIn(Widget widget) { >+ String id = (String) controlToId.get(widget); >+ if (currentId != id) { >+ if (id == null) { >+ currentId = null; >+ currentControl = null; >+ } else { >+ currentId = id; >+ currentControl = (Control) widget; >+ } >+ Map m = new HashMap(); >+ m.put(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, currentId); >+ m.put(ISources.ACTIVE_FOCUS_CONTROL_NAME, currentControl); >+ fireSourceChanged(ISources.ACTIVE_MENU, m); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.menus.IFocusService#removeTrackerFor(org.eclipse.swt.widgets.Control) >+ */ >+ public void removeTrackerFor(Control control) { >+ controlToId.remove(control); >+ if (control.isDisposed()) { >+ return; >+ } >+ control.removeFocusListener(getFocusListener()); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.ISourceProvider#dispose() >+ */ >+ public void dispose() { >+ Iterator i = controlToId.keySet().iterator(); >+ while (i.hasNext()) { >+ Control c = (Control) i.next(); >+ if (!c.isDisposed()) { >+ c.removeFocusListener(getFocusListener()); >+ } >+ } >+ controlToId.clear(); >+ controlToId = null; >+ focusListener = null; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.ISourceProvider#getCurrentState() >+ */ >+ public Map getCurrentState() { >+ Map m = new HashMap(); >+ m.put(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, currentId); >+ m.put(ISources.ACTIVE_FOCUS_CONTROL_NAME, currentControl); >+ return m; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames() >+ */ >+ public String[] getProvidedSourceNames() { >+ return PROVIDED_SOURCE_NAMES; >+ } >+} >#P org.eclipse.ui.tests >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/plugin.xml,v >retrieving revision 1.224 >diff -u -r1.224 plugin.xml >--- plugin.xml 14 Feb 2007 20:12:20 -0000 1.224 >+++ plugin.xml 16 Mar 2007 18:00:39 -0000 >@@ -3212,6 +3212,13 @@ > </command> > </menu> > </menuContribution> >+ <menuContribution >+ locationURI="toolbar:org.eclipse.ui.trim.status"> >+ <control >+ class="org.eclipse.ui.tests.api.workbenchpart.TextFocusWidget" >+ id="org.eclipse.ui.tests.focusText"> >+ </control> >+ </menuContribution> > </extension> > <extension > point="org.eclipse.ui.contexts"> >Index: Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/TextFocusWidget.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/TextFocusWidget.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/TextFocusWidget.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/TextFocusWidget.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,86 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.tests.api.workbenchpart; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Layout; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.menus.IFocusService; >+import org.eclipse.ui.menus.WorkbenchWindowControlContribution; >+ >+/** >+ * Basic widget wrapping an SWT Text Control. >+ * >+ * @since 3.3 >+ * >+ */ >+public class TextFocusWidget extends WorkbenchWindowControlContribution { >+ public TextFocusWidget() { >+ >+ } >+ >+ /** >+ * @param id >+ */ >+ protected TextFocusWidget(String id) { >+ super(id); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite) >+ */ >+ protected Control createControl(Composite parent) { >+ Composite textHolder = new Composite(parent, SWT.NONE); >+ textHolder.setLayout(new Layout() { >+ protected Point computeSize(Composite composite, int wHint, >+ int hHint, boolean flushCache) { >+ Text tw = (Text) composite.getChildren()[0]; >+ Point twSize = tw.computeSize(wHint, hHint, flushCache); >+ >+ // Forst it to be at least 100 pixels >+ if (twSize.x < 200) >+ twSize.x = 200; >+ >+ return twSize; >+ } >+ >+ protected void layout(Composite composite, boolean flushCache) { >+ Text tw = (Text) composite.getChildren()[0]; >+ Point twSize = tw.computeSize(SWT.DEFAULT, SWT.DEFAULT, >+ flushCache); >+ Rectangle bb = composite.getBounds(); >+ int yOffset = ((bb.height - twSize.y) / 2) + 1; >+ if (yOffset < 0) >+ yOffset = 0; >+ >+ // Set the tw's size to the composite's width and the default >+ // height (centered) >+ tw.setBounds(0, yOffset, bb.width, twSize.y); >+ } >+ }); >+ >+ Text tw = new Text(textHolder, SWT.BORDER); >+ tw.setText("Test Text Eric was here...XXXXXX"); >+ IFocusService fc = (IFocusService) getWorkbenchWindow().getService( >+ IFocusService.class); >+ fc.addTrackerFor(tw, getId()); >+ >+ textHolder.setSize(181, 22); >+ return textHolder; >+ } >+}
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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 177806
:
61144
|
61145
|
61155
|
61156
|
61159
|
61190
|
61272