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 55377 Details for
Bug 167010
[QuickAccess] Resources in Ctrl-E?
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.
[patch]
work in progress
patch-167010.txt (text/plain), 33.55 KB, created by
Boris Bokowski
on 2006-12-10 23:23:21 EST
(
hide
)
Description:
work in progress
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2006-12-10 23:23:21 EST
Size:
33.55 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.ide >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/META-INF/MANIFEST.MF,v >retrieving revision 1.26 >diff -u -r1.26 MANIFEST.MF >--- META-INF/MANIFEST.MF 1 Dec 2006 15:38:05 -0000 1.26 >+++ META-INF/MANIFEST.MF 11 Dec 2006 04:20:28 -0000 >@@ -53,7 +53,8 @@ > org.eclipse.update.core;bundle-version="[3.1.100,4.0.0)", > org.eclipse.update.ui;bundle-version="[3.1.100,4.0.0)", > org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.ui.forms >+ org.eclipse.ui.forms, >+ org.eclipse.core.databinding > Eclipse-LazyStart: true > Import-Package: com.ibm.icu.text > Bundle-RequiredExecutionEnvironment: J2SE-1.4 >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.xml,v >retrieving revision 1.163 >diff -u -r1.163 plugin.xml >--- plugin.xml 12 Sep 2006 20:09:45 -0000 1.163 >+++ plugin.xml 11 Dec 2006 04:20:28 -0000 >@@ -1019,5 +1019,11 @@ > value="0"/> > </markerAttributeGrouping> > </extension> >+ <extension >+ point="org.eclipse.ui.internalQuickAccessProvider"> >+ <provider >+ class="org.eclipse.ui.internal.ide.ResourceProvider"> >+ </provider> >+ </extension> > > </plugin> >Index: src/org/eclipse/ui/internal/ide/ResourceProvider.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/ResourceProvider.java >diff -N src/org/eclipse/ui/internal/ide/ResourceProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/ResourceProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,163 @@ >+package org.eclipse.ui.internal.ide; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IResourceProxy; >+import org.eclipse.core.resources.IResourceProxyVisitor; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.ide.IDE; >+import org.eclipse.ui.internal.incubator.AbstractElement; >+import org.eclipse.ui.internal.incubator.AbstractProvider; >+import org.eclipse.ui.internal.incubator.QuickAccessElement; >+import org.eclipse.ui.internal.incubator.IncrementalFilterSet.IStreamVisitor; >+import org.eclipse.ui.statushandling.StatusManager; >+ >+/** >+ * Provides the resources in the workspace >+ * >+ * @since 3.3 >+ * >+ */ >+public class ResourceProvider extends AbstractProvider { >+ >+ static IWorkspace workspace; >+ >+ /** >+ * >+ */ >+ public ResourceProvider() { >+ workspace = ResourcesPlugin.getWorkspace(); >+ } >+ >+ public AbstractElement getElementForId(String id) { >+ IResource resource = workspace.getRoot().findMember( >+ Path.fromPortableString(id)); >+ return resource == null ? null : new ResourceElement(this, resource >+ .getFullPath()); >+ } >+ >+ public AbstractElement[] getElements() { >+ final List result = new ArrayList(); >+ try { >+ workspace.getRoot().accept(new IResourceProxyVisitor() { >+ >+ public boolean visit(IResourceProxy proxy) { >+ if (proxy.getType() == IResource.FILE && !proxy.isDerived()) { >+ result.add(new ResourceElement(ResourceProvider.this, >+ proxy.requestFullPath())); >+ } >+ return true; >+ } >+ }, 0); >+ } catch (CoreException e) { >+ StatusManager >+ .getManager() >+ .handle( >+ StatusUtil >+ .newStatus( >+ IStatus.ERROR, >+ "NON-NLSed: Error while retrieving workspace resources", e), //$NON-NLS-1$ >+ StatusManager.LOG); >+ } >+ return (AbstractElement[]) result.toArray(new AbstractElement[result >+ .size()]); >+ } >+ >+ public String getId() { >+ return "org.eclipse.ui.ide.ResourceProvider"; //$NON-NLS-1$ >+ } >+ >+ public ImageDescriptor getImageDescriptor() { >+ return null; >+ } >+ >+ public String getName() { >+ return "NON-NLSed: Resources"; //$NON-NLS-1$ >+ } >+ >+ private static class ResourceElement extends AbstractElement { >+ >+ private final IPath path; >+ >+ ResourceElement(ResourceProvider provider, IPath path) { >+ super(provider); >+ this.path = path; >+ } >+ >+ public void execute() { >+ IResource resource = workspace.getRoot().findMember(path); >+ if (!resource.exists() || resource.getType() != IResource.FILE) >+ return; >+ IWorkbenchWindow window = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (window == null) >+ return; >+ IWorkbenchPage activePage = window.getActivePage(); >+ if (activePage == null) >+ return; >+ try { >+ IDE.openEditor(activePage, (IFile) resource); >+ } catch (PartInitException e) { >+ StatusManager.getManager().handle( >+ StatusUtil.newStatus(IStatus.ERROR, >+ "NON-NLSed: Error while opening editor", e), //$NON-NLS-1$ >+ StatusManager.SHOWANDLOG); >+ } >+ } >+ >+ public String getId() { >+ return path.toPortableString(); >+ } >+ >+ public ImageDescriptor getImageDescriptor() { >+ return null; >+ } >+ >+ public String getLabel() { >+ return path.lastSegment() + " - " + path.toString(); //$NON-NLS-1$ >+ } >+ >+ } >+ >+ public void accept(final IStreamVisitor visitor) { >+ try { >+ workspace.getRoot().accept(new IResourceProxyVisitor() { >+ >+ public boolean visit(IResourceProxy proxy) { >+ if (proxy.getType() == IResource.FILE && !proxy.isDerived()) { >+ final IResource resource = proxy.requestResource(); >+ return visitor.visit(new QuickAccessElement() { >+ public String getLabel() { >+ return resource.getName() + " - " + resource.getParent().getFullPath().toString(); //$NON-NLS-1$ >+ } >+ }); >+ } >+ return true; >+ } >+ }, 0); >+ } catch (CoreException e) { >+ StatusManager >+ .getManager() >+ .handle( >+ StatusUtil >+ .newStatus( >+ IStatus.ERROR, >+ "NON-NLSed: Error while retrieving workspace resources", e), //$NON-NLS-1$ >+ StatusManager.LOG); >+ } >+ }; >+ >+} >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/incubator/CtrlEAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/incubator/CtrlEAction.java,v >retrieving revision 1.15 >diff -u -r1.15 CtrlEAction.java >--- Eclipse UI/org/eclipse/ui/internal/incubator/CtrlEAction.java 4 Dec 2006 20:49:53 -0000 1.15 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/CtrlEAction.java 11 Dec 2006 04:20:30 -0000 >@@ -3,12 +3,17 @@ > import java.util.ArrayList; > import java.util.HashMap; > import java.util.LinkedList; >+import java.util.List; > import java.util.Map; > import java.util.StringTokenizer; > > import org.eclipse.core.commands.AbstractHandler; > import org.eclipse.core.commands.ExecutionEvent; > import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; > import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.resource.DeviceResourceException; > import org.eclipse.jface.resource.ImageDescriptor; >@@ -35,7 +40,9 @@ > import org.eclipse.ui.internal.IWorkbenchGraphicConstants; > import org.eclipse.ui.internal.WorkbenchImages; > import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.internal.misc.StatusUtil; > import org.eclipse.ui.internal.progress.ProgressManagerUtil; >+import org.eclipse.ui.statushandling.StatusManager; > > /** > * Experimental Action for search-based navigation to UI elements such as >@@ -71,11 +78,39 @@ > } > > if (providers == null) { >- providers = new AbstractProvider[] { new PreviousPicksProvider(), >- new EditorProvider(), new ViewProvider(), >- new PerspectiveProvider(), new CommandProvider(), >- new ActionProvider(), new WizardProvider(), >- new PreferenceProvider() }; >+ List providerList = new ArrayList(); >+ providerList.add(new PreviousPicksProvider()); >+ providerList.add(new EditorProvider()); >+ providerList.add(new ViewProvider()); >+ providerList.add(new PerspectiveProvider()); >+ // add contributed providers >+ IConfigurationElement[] elements = Platform.getExtensionRegistry() >+ .getConfigurationElementsFor( >+ "org.eclipse.ui.internalQuickAccessProvider"); //$NON-NLS-1$ >+ for (int i = 0; i < elements.length; i++) { >+ AbstractProvider provider; >+ try { >+ provider = (AbstractProvider) elements[i] >+ .createExecutableExtension("class"); //$NON-NLS-1$ >+ providerList.add(provider); >+ } catch (CoreException e) { >+ StatusManager >+ .getManager() >+ .handle( >+ StatusUtil >+ .newStatus( >+ IStatus.ERROR, >+ "NON-NLSed: Error with extension " + elements[i], e), //$NON-NLS-1$ >+ StatusManager.LOG); >+ } >+ } >+ >+ providerList.add(new CommandProvider()); >+ providerList.add(new ActionProvider()); >+ providerList.add(new WizardProvider()); >+ providerList.add(new PreferenceProvider()); >+ providers = (AbstractProvider[]) providerList >+ .toArray(new AbstractProvider[providerList.size()]); > > providerMap = new HashMap(); > for (int i = 0; i < providers.length; i++) { >@@ -171,7 +206,7 @@ > public String[] getMatchNames(Object element, Object parentElementOrNull) { > if (element instanceof AbstractProvider) { > AbstractProvider provider = (AbstractProvider) element; >- return (new String[]{provider.getName()}); >+ return (new String[] { provider.getName() }); > } else if (element instanceof AbstractElement) { > AbstractElement abstractElement = (AbstractElement) element; > String sortLabel = abstractElement.getSortLabel(); >@@ -181,21 +216,22 @@ > String combinedLabel = abstractProvider.getName() > + " " + abstractElement.getLabel(); //$NON-NLS-1$ > String combinedCamelCase = getCamelCase(combinedLabel); >- return (new String[] { sortLabel, camelCase, combinedLabel, combinedCamelCase }); >+ return (new String[] { sortLabel, camelCase, combinedLabel, >+ combinedCamelCase }); > } > return (new String[] { sortLabel, camelCase }); > } >- return (new String[]{""}); //$NON-NLS-1$ >+ return (new String[] { "" }); //$NON-NLS-1$ > } >- >+ > /** > * @return a string containing the first character of every word for >- * camel case checking. >+ * camel case checking. > */ > private String getCamelCase(String label) { > StringTokenizer tokenizer = new StringTokenizer(label); > StringBuffer camelCase = new StringBuffer(); >- while(tokenizer.hasMoreTokens()) { >+ while (tokenizer.hasMoreTokens()) { > String word = tokenizer.nextToken(); > camelCase.append(word.charAt(0)); > } >Index: Eclipse UI/org/eclipse/ui/internal/incubator/AbstractProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/incubator/AbstractProvider.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractProvider.java >--- Eclipse UI/org/eclipse/ui/internal/incubator/AbstractProvider.java 22 Nov 2006 21:43:12 -0000 1.1 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/AbstractProvider.java 11 Dec 2006 04:20:30 -0000 >@@ -12,12 +12,14 @@ > package org.eclipse.ui.internal.incubator; > > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.ui.internal.incubator.IncrementalFilterSet.IElementStream; >+import org.eclipse.ui.internal.incubator.IncrementalFilterSet.IStreamVisitor; > > /** > * @since 3.3 > * > */ >-public abstract class AbstractProvider { >+public abstract class AbstractProvider implements IElementStream { > > /** > * Returns the unique ID of this provider. >@@ -56,4 +58,12 @@ > * @return the element with the given ID, or null if not found. > */ > public abstract AbstractElement getElementForId(String id); >+ >+ public void accept(IStreamVisitor visitor) { >+ AbstractElement[] elements = getElements(); >+ for (int i = 0; i < elements.length; i++) { >+ if (!visitor.visit(elements[i])) >+ return; >+ } >+ } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/META-INF/MANIFEST.MF,v >retrieving revision 1.40 >diff -u -r1.40 MANIFEST.MF >--- META-INF/MANIFEST.MF 8 Nov 2006 22:06:59 -0000 1.40 >+++ META-INF/MANIFEST.MF 11 Dec 2006 04:20:30 -0000 >@@ -38,7 +38,7 @@ > org.eclipse.ui.internal.expressions;x-internal:=true, > org.eclipse.ui.internal.handlers;x-internal:=true, > org.eclipse.ui.internal.help;x-internal:=true, >- org.eclipse.ui.internal.incubator;x-friends:="org.eclipse.ui", >+ org.eclipse.ui.internal.incubator;x-friends:="org.eclipse.ui,org.eclipse.ui.ide", > org.eclipse.ui.internal.intro;x-internal:=true, > org.eclipse.ui.internal.keys;x-internal:=true, > org.eclipse.ui.internal.layout;x-friends:="org.eclipse.ui.presentations.r21,org.eclipse.ui.intro", >@@ -80,7 +80,9 @@ > org.eclipse.help;bundle-version="[3.2.0,4.0.0)", > org.eclipse.jface;bundle-version="[3.3.0,4.0.0)", > org.eclipse.swt;bundle-version="[3.3.0,4.0.0)", >- org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)" >+ org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.core.databinding, >+ org.eclipse.jface.databinding > Eclipse-LazyStart: true > Import-Package: com.ibm.icu.text, > javax.xml.parsers, >Index: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessHandler.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessHandler.java >diff -N Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,71 @@ >+/******************************************************************************* >+ * 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.internal.incubator; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.internal.misc.StatusUtil; >+import org.eclipse.ui.statushandling.StatusManager; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class QuickAccessHandler extends AbstractHandler { >+ >+ public Object execute(ExecutionEvent event) { >+ >+ IWorkbenchWindow window = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (window == null) { >+ return null; >+ } >+ >+ List providerList = new ArrayList(); >+ // add contributed providers >+ IConfigurationElement[] elements = Platform.getExtensionRegistry() >+ .getConfigurationElementsFor( >+ "org.eclipse.ui.internalQuickAccessProvider"); //$NON-NLS-1$ >+ for (int i = 0; i < elements.length; i++) { >+ AbstractProvider provider; >+ try { >+ provider = (AbstractProvider) elements[i] >+ .createExecutableExtension("class"); //$NON-NLS-1$ >+ providerList.add(provider); >+ } catch (CoreException e) { >+ StatusManager >+ .getManager() >+ .handle( >+ StatusUtil >+ .newStatus( >+ IStatus.ERROR, >+ "NON-NLSed: Error with extension " + elements[i], e), //$NON-NLS-1$ >+ StatusManager.LOG); >+ } >+ } >+ AbstractProvider provider = (AbstractProvider) providerList.get(0); >+ >+ new QuickAccessPopup(window.getShell(), provider).open(); >+ >+ return null; >+ } >+ >+} >Index: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessPopup.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessPopup.java >diff -N Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessPopup.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessPopup.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,149 @@ >+/******************************************************************************* >+ * 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.internal.incubator; >+ >+import org.eclipse.core.databinding.BindSpec; >+import org.eclipse.core.databinding.DataBindingContext; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.observable.value.IValueChangeListener; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.observable.value.WritableValue; >+import org.eclipse.core.databinding.util.IFilter; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider; >+import org.eclipse.jface.dialogs.PopupDialog; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.TableViewer; >+import org.eclipse.jface.viewers.ViewerComparator; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.internal.incubator.IncrementalFilterSet.IElementStream; >+import org.eclipse.ui.internal.incubator.IncrementalFilterSet.IStreamVisitor; >+ >+import com.ibm.icu.text.DecimalFormat; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class QuickAccessPopup extends PopupDialog { >+ >+ static final int FILTER_WAIT = 0; >+ static final int VISITOR_WAIT = 0; >+ >+ private Text text; >+ private TableViewer tableViewer; >+ private Composite composite; >+ private IncrementalFilterSet filteredContents; >+ protected String filterText = ""; //$NON-NLS-1$ >+ private final IElementStream elementStream; >+ >+ /** >+ * >+ * @param parent >+ */ >+ public QuickAccessPopup(Shell parent, IElementStream elementStream) { >+ super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, true, >+ true, null, null); >+ this.elementStream = elementStream; >+ } >+ >+ protected Control createDialogArea(Composite parent) { >+ composite = new Composite(parent, SWT.NONE); >+ composite.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ text = new Text(composite, SWT.NONE); >+ tableViewer = new TableViewer(composite); >+ bind(); >+ GridLayoutFactory.fillDefaults().generateLayout(composite); >+ return composite; >+ } >+ >+ /** >+ * >+ */ >+ private void bind() { >+ Realm swtRealm = SWTObservables.getRealm(getShell().getDisplay()); >+ final DataBindingContext dbc = new DataBindingContext(swtRealm); >+ composite.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ dbc.dispose(); >+ } >+ }); >+ tableViewer.setContentProvider(new ObservableSetContentProvider()); >+ tableViewer.setComparator(new ViewerComparator()); >+ tableViewer.setLabelProvider(new LabelProvider() { >+ public String getText(Object element) { >+ return ((QuickAccessElement)element).getLabel(); >+ } >+ }); >+ final WritableValue filterTextObservable = new WritableValue(swtRealm, >+ String.class); >+ dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), >+ filterTextObservable, new BindSpec().setUpdateTarget(false)); >+ filteredContents = new IncrementalFilterSet(getShell().getDisplay(), >+ elementStream, new IFilter() { >+ public boolean select(Object toTest) { >+ return ((QuickAccessElement) toTest).getLabel() >+ .indexOf(filterText) != -1; >+ } >+ }); >+ filterTextObservable.addValueChangeListener(new IValueChangeListener() { >+ public void handleValueChange(IObservableValue source, >+ ValueDiff diff) { >+ String oldFilterText = filterText; >+ filterText = (String) filterTextObservable.getValue(); >+ if (filterText.startsWith(oldFilterText)) { >+ filteredContents.requestFilter(); >+ } else if (filterText.length() == 0) { >+ filteredContents.requestClear(); >+ } else { >+ filteredContents.requestRecalculation(); >+ } >+ } >+ }); >+ tableViewer.setInput(filteredContents); >+ } >+ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ final DecimalFormat decimalFormat = new DecimalFormat("0000"); //$NON-NLS-1$ >+ QuickAccessPopup popup = new QuickAccessPopup(null, >+ new IElementStream() { >+ public void accept(IStreamVisitor visitor) { >+ for (int i = 0; i < 10000; i++) { >+ final Integer val = new Integer(i); >+ visitor.visit(new QuickAccessElement() { >+ public String getLabel() { >+ return decimalFormat.format(val); >+ } >+ }); >+ } >+ } >+ }); >+ popup.setBlockOnOpen(true); >+ popup.open(); >+ while (popup.getShell() != null && !popup.getShell().isDisposed()) { >+ if (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+} >Index: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessElement.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessElement.java >diff -N Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessElement.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/QuickAccessElement.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * 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.internal.incubator; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class QuickAccessElement { >+ >+ /** >+ * @return >+ */ >+ public abstract String getLabel(); >+ >+ public boolean equals(Object o) { >+ if (o.getClass()!=this.getClass())return false; >+ return ((QuickAccessElement)o).getLabel().equals(getLabel()); >+ } >+ >+ public int hashCode() { >+ return getLabel().hashCode(); >+ } >+ >+} >Index: Eclipse UI/org/eclipse/ui/internal/incubator/IncrementalFilterSet.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/incubator/IncrementalFilterSet.java >diff -N Eclipse UI/org/eclipse/ui/internal/incubator/IncrementalFilterSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/incubator/IncrementalFilterSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,318 @@ >+/******************************************************************************* >+ * 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.internal.incubator; >+ >+import java.util.Collections; >+import java.util.HashSet; >+import java.util.LinkedList; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.set.ObservableSet; >+import org.eclipse.core.databinding.util.IFilter; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.swt.widgets.Display; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class IncrementalFilterSet extends ObservableSet { >+ >+ /** >+ * >+ */ >+ private static final int MAX_WORK = 100; >+ >+ public static interface IElementStream { >+ public void accept(IStreamVisitor visitor); >+ } >+ >+ public static interface IStreamVisitor { >+ public boolean visit(Object element); >+ } >+ >+ protected static final boolean DEBUG = true; >+ >+ private IFilter filter; >+ >+ private static Object CLEAR_ALL = new Object(); >+ private static Object MODE_ADD = new Object(); >+ private static Object MODE_REMOVE = new Object(); >+ /** >+ * CLEAR_ALL element in this list represents a clear all operation, MODE_ADD >+ * changes the mode so that from now on, other elements represent an add >+ * operation with that element, and MODE_REMOVE changes the mode so that >+ * from now on, other elements represent a remove operation of that element >+ */ >+ private LinkedList workQueue = new LinkedList(); >+ // the workQueue writer's current state >+ boolean writerAdding = true; >+ // the workQueue reader's current state >+ boolean readerAdding = true; >+ >+ private static Object REQUEST_RECALCULATE = new Object(); >+ private static Object REQUEST_FILTER = new Object(); >+ private static Object REQUEST_CLEAR = new Object(); >+ private LinkedList requestQueue = new LinkedList(); >+ boolean consistent = false; >+ >+ private Job filterJob = new Job("Filtering") { //$NON-NLS-1$ >+ Object request; >+ >+ protected IStatus run(IProgressMonitor monitor) { >+ try { >+ request = dequeue(requestQueue); >+ while (request != null) { >+ if (request == REQUEST_CLEAR) { >+ if (DEBUG) { >+ System.out.println("clearing"); //$NON-NLS-1$ >+ } >+ request = null; >+ enqueueWorkQueueClearAll(); >+ consistent = false; >+ scheduleWorker(); >+ } else if (consistent && request == REQUEST_FILTER) { >+ if (DEBUG) { >+ System.out >+ .println("filtering, wrappedSet.size=" + wrappedSet.size()); //$NON-NLS-1$ >+ } >+ int filtered = 0; >+ request = null; >+ boolean removing; >+ synchronized (workQueue) { >+ removing = workQueue.isEmpty(); >+ } >+ if (!removing) { >+ enqueueWorkQueueClearAll(); >+ scheduleWorker(); >+ } >+ Object[] elements = wrappedSet >+ .toArray(new Object[wrappedSet.size()]); >+ for (int i = 0; request == null && i < elements.length; i++) { >+ Object element = elements[i]; >+ if (!filter.select(element)) { >+ if (removing) { >+ if (writerAdding) { >+ enqueue(workQueue, MODE_REMOVE); >+ writerAdding = false; >+ } >+ enqueue(workQueue, element); >+ scheduleWorker(); >+ filtered++; >+ } >+ } else { >+ if (!removing) { >+ if (!writerAdding) { >+ enqueue(workQueue, MODE_ADD); >+ writerAdding = true; >+ } >+ enqueue(workQueue, element); >+ scheduleWorker(); >+ filtered++; >+ } >+ } >+ request = dequeue(requestQueue); >+ } >+ if (DEBUG) { >+ System.out >+ .println("filtered: " + (removing ? "removed " : "added ") + filtered + " elements"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ >+ } >+ } else if (request == REQUEST_RECALCULATE >+ || (request == REQUEST_FILTER && !consistent)) { >+ if (DEBUG) { >+ System.out.println("recalculating"); //$NON-NLS-1$ >+ } >+ request = null; >+ enqueueWorkQueueClearAll(); >+ consistent = false; >+ scheduleWorker(); >+ stream.accept(new IStreamVisitor() { >+ public boolean visit(Object element) { >+ if (request == null) { >+ if (filter.select(element)) { >+ if (!writerAdding) { >+ enqueue(workQueue, MODE_ADD); >+ writerAdding = true; >+ } >+ enqueue(workQueue, element); >+ scheduleWorker(); >+ } >+ request = dequeue(requestQueue); >+ } >+ return request == null; >+ } >+ }); >+ if (request == null) { >+ consistent = true; >+ } >+ } else { >+ throw new RuntimeException("unhandled case"); //$NON-NLS-1$ >+ } >+ if (request == null) { >+ request = dequeue(requestQueue); >+ } >+ } >+ } catch (Exception ex) { >+ ex.printStackTrace(); >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ >+ private Runnable worker; >+ >+ private Display display; >+ >+ private final IElementStream stream; >+ >+ private void enqueue(LinkedList queue, Object element) { >+ synchronized (queue) { >+ queue.addLast(element); >+ } >+ } >+ >+ /** >+ * non-blocking - returns null if no element in queue >+ * >+ * @param queue >+ * TODO >+ */ >+ Object dequeue(LinkedList queue) { >+ synchronized (queue) { >+ return queue.isEmpty() ? null : queue.removeFirst(); >+ } >+ } >+ >+ /** >+ */ >+ protected IncrementalFilterSet(Display display, IElementStream stream, >+ IFilter filter) { >+ super(SWTObservables.getRealm(display), new HashSet(), Object.class); >+ this.display = display; >+ this.stream = stream; >+ this.filter = filter; >+ } >+ >+ /** >+ * May be called from any thread. Non-blocking. >+ * >+ * @param stream >+ * @throws InterruptedException >+ */ >+ public void requestFilter() { >+ enqueue(requestQueue, REQUEST_FILTER); >+ filterJob.schedule(); >+ } >+ >+ public void requestRecalculation() { >+ enqueue(requestQueue, REQUEST_RECALCULATE); >+ filterJob.schedule(); >+ } >+ >+ /** >+ * >+ */ >+ protected void scheduleWorker() { >+ if (worker == null) { >+ worker = new Runnable() { >+ public void run() { >+ Object work; >+ Set additions = new HashSet(); >+ Set removals = new HashSet(); >+ int worked = 0; >+ while (++worked < MAX_WORK >+ && (work = dequeue(workQueue)) != null) { >+ if (work == CLEAR_ALL) { >+ fireSetChange(Diffs.createSetDiff( >+ Collections.EMPTY_SET, wrappedSet)); >+ wrappedSet = new HashSet(); >+ additions=new HashSet(); >+ removals=new HashSet(); >+ worked = MAX_WORK; >+ } else if (work == MODE_ADD) { >+ readerAdding = true; >+ if (removals.size() > 0) { >+ processRemovals(removals); >+ worked = MAX_WORK; >+ } >+ } else if (work == MODE_REMOVE) { >+ readerAdding = false; >+ if (additions.size() > 0) { >+ processAdditions(additions); >+ worked = MAX_WORK; >+ } >+ } else if (readerAdding) { >+ additions.add(work); >+ } else { >+ removals.add(work); >+ } >+ } >+ processRemovals(removals); >+ processAdditions(additions); >+ synchronized (workQueue) { >+ if (!workQueue.isEmpty()) { >+ scheduleWorker(); >+ } >+ } >+ } >+ >+ private void processAdditions(Set additions) { >+ if (!additions.isEmpty()) { >+ if (DEBUG) { >+ System.out.println("processing " + additions.size() //$NON-NLS-1$ >+ + " additions"); //$NON-NLS-1$ >+ } >+ wrappedSet.addAll(additions); >+ fireSetChange(Diffs.createSetDiff(additions, >+ Collections.EMPTY_SET)); >+ additions = new HashSet(); >+ } >+ } >+ >+ private void processRemovals(Set removals) { >+ if (!removals.isEmpty()) { >+ if (DEBUG) { >+ System.out.println("processing " + removals.size() //$NON-NLS-1$ >+ + " removals"); //$NON-NLS-1$ >+ } >+ wrappedSet.removeAll(removals); >+ fireSetChange(Diffs.createSetDiff( >+ Collections.EMPTY_SET, removals)); >+ removals = new HashSet(); >+ } >+ } >+ }; >+ } >+ display.asyncExec(worker); >+ } >+ >+ /** >+ * >+ */ >+ public void requestClear() { >+ enqueue(requestQueue, REQUEST_CLEAR); >+ filterJob.schedule(); >+ } >+ >+ private void enqueueWorkQueueClearAll() { >+ // enqueue clear all operation >+ synchronized (workQueue) { >+ workQueue.clear(); >+ workQueue.addLast(CLEAR_ALL); >+ } >+ } >+}
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 167010
:
55173
| 55377