diff options
author | Steven Spungin | 2014-05-31 12:36:27 +0000 |
---|---|---|
committer | Steven Spungin | 2014-06-04 05:23:04 +0000 |
commit | 6245db0be435684b8463894bc03dbbfde2310f63 (patch) | |
tree | 077863b850fb33ffb70c7e2ae17c6e250947b9aa | |
parent | 7a07f32697742edaea671480dc968bb8eb55fa79 (diff) | |
download | org.eclipse.e4.tools-6245db0be435684b8463894bc03dbbfde2310f63.tar.gz org.eclipse.e4.tools-6245db0be435684b8463894bc03dbbfde2310f63.tar.xz org.eclipse.e4.tools-6245db0be435684b8463894bc03dbbfde2310f63.zip |
Bug 436283 - [target platform search] The job window should have "run in
background" option
Bug 436281 - Combine the FilterEx with the
IClassContributionProvider.Filter class
Bug 436280 - PDE ContributionClass Provider should fire
ContributionResultHandler.moreResults at the end of the search
Change-Id: I2eadf60e4be68f09fd201edfe49fb3c79d8f6b2a
Signed-off-by: Steven Spungin <steven@spungin.tv>
8 files changed, 444 insertions, 300 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java index 5702b9e2..bde3a2a1 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java @@ -7,7 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Steven Spungin <steven@spungin.tv> - Bug 424730 + * Steven Spungin <steven@spungin.tv> - Bug 424730, Bug 436281, Bug 436280 ******************************************************************************/ package org.eclipse.e4.tools.emf.editor3x; @@ -21,7 +21,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.e4.tools.emf.ui.common.FilterEx; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider; import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope; import org.eclipse.jdt.core.IJavaProject; @@ -42,16 +41,12 @@ public class PDEClassContributionProvider implements IClassContributionProvider } @SuppressWarnings("restriction") - public void findContribution(final Filter filter, final ContributionResultHandler handler) { + public void findContribution(final Filter filter, final ContributionResultHandler handler) { boolean followReferences = true; - if (filter instanceof FilterEx) { - FilterEx filterEx = (FilterEx) filter; - if (filterEx.getSearchScope().contains(ResourceSearchScope.PROJECT) && - !filterEx.getSearchScope().contains(ResourceSearchScope.REFERENCES)) { - followReferences = false; - } - + if (filter.getSearchScope().contains(ResourceSearchScope.PROJECT) && !filter.getSearchScope().contains(ResourceSearchScope.REFERENCES)) { + followReferences = false; } + IJavaSearchScope scope = null; if (followReferences == false){ IJavaProject javaProject = JavaCore.create(filter.project); @@ -181,6 +176,7 @@ public class PDEClassContributionProvider implements IClassContributionProvider e.printStackTrace(); } + handler.moreResults(0, filter); } } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java deleted file mode 100644 index 4ff10efc..00000000 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 TwelveTone LLC 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: - * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625 - *******************************************************************************/ - -package org.eclipse.e4.tools.emf.ui.common; - -import java.util.EnumSet; -import java.util.List; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter; - -/** - * An extension to the Filter class, allowing for bundles, packages, and - * locations to be specified. - * - * @author Steven Spungin - * - */ -public class FilterEx extends Filter { - - private List<String> bundles; - private List<String> packages; - private List<String> locations; - private EnumSet<ResourceSearchScope> searchScope = EnumSet.noneOf(ResourceSearchScope.class); - private boolean includeNonBundles; - private IProgressMonitor progressMonitor; - - public FilterEx(IProject project, String regNamePattern) { - super(project, regNamePattern); - } - - /** - * Sets the bundles to filter on - * - * @param filterBundles - */ - public void setBundles(List<String> filterBundles) { - bundles = filterBundles; - } - - public void setPackages(List<String> filterPackages) { - packages = filterPackages; - } - - public List<String> getBundles() { - return bundles; - } - - /** - * Sets the packages to filter on - * - * @return - */ - public List<String> getPackages() { - return packages; - } - - public List<String> getLocations() { - return locations; - } - - /** - * Sets the installed project locations to filter on - * - * @param locations - */ - public void setLocations(List<String> locations) { - this.locations = locations; - } - - public EnumSet<ResourceSearchScope> getSearchScope() { - return searchScope; - } - - /** - * Sets the scope for the search. - * - * @param searchScope - */ - public void setSearchScope(EnumSet<ResourceSearchScope> searchScope) { - this.searchScope = searchScope; - } - - /** - * Include plain old java projects, resource projects, and others in - * searches. No manifest required. - * - * @param includeNonBundles - */ - public void setIncludeNonBundles(boolean includeNonBundles) { - this.includeNonBundles = includeNonBundles; - } - - public boolean isIncludeNonBundles() { - return includeNonBundles; - } - - public IProgressMonitor getProgressMonitor() { - return progressMonitor; - } - - public void setProgressMonitor(IProgressMonitor progressMonitor) { - this.progressMonitor = progressMonitor; - } - -} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java index a7fd6cdf..7ed891ff 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java @@ -7,11 +7,14 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Steven Spungin <steven@spungin.tv> - Bug 424730 + * Steven Spungin <steven@spungin.tv> - Bug 424730, Bug 436281 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.common; +import java.util.EnumSet; +import java.util.List; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; public interface IClassContributionProvider { public class ContributionData { @@ -44,14 +47,110 @@ public interface IClassContributionProvider { public int maxResults; public Object userData; + // These items were added for extended filter functionality + private List<String> bundles; + private List<String> packages; + private List<String> locations; + private EnumSet<ResourceSearchScope> searchScope = EnumSet.noneOf(ResourceSearchScope.class); + private boolean includeNonBundles; + private IProgressMonitor progressMonitor; + /** + * This member can be null. It provides a way for the provider to signal + * various state changes. + */ + private IProviderStatusCallback providerStatusCallback; + public Filter(IProject project, String namePattern) { this.project = project; this.namePattern = namePattern; } + + /** + * Sets the bundles to filter on + * + * @param filterBundles + */ + public void setBundles(List<String> filterBundles) { + bundles = filterBundles; + } + + public void setPackages(List<String> filterPackages) { + packages = filterPackages; + } + + public List<String> getBundles() { + return bundles; + } + + /** + * Sets the packages to filter on + * + * @return + */ + public List<String> getPackages() { + return packages; + } + + public List<String> getLocations() { + return locations; + } + + /** + * Sets the installed project locations to filter on + * + * @param locations + */ + public void setLocations(List<String> locations) { + this.locations = locations; + } + + public EnumSet<ResourceSearchScope> getSearchScope() { + return searchScope; + } + + /** + * Sets the scope for the search. + * + * @param searchScope + */ + public void setSearchScope(EnumSet<ResourceSearchScope> searchScope) { + this.searchScope = searchScope; + } + + /** + * Include plain old java projects, resource projects, and others in + * searches. No manifest required. + * + * @param includeNonBundles + */ + public void setIncludeNonBundles(boolean includeNonBundles) { + this.includeNonBundles = includeNonBundles; + } + + public boolean isIncludeNonBundles() { + return includeNonBundles; + } + + public IProgressMonitor getProgressMonitor() { + return progressMonitor; + } + + public void setProgressMonitor(IProgressMonitor progressMonitor) { + this.progressMonitor = progressMonitor; + } + + public IProviderStatusCallback getProviderStatusCallback() { + return providerStatusCallback; + } + + public void setProviderStatusCallback(IProviderStatusCallback providerStatusCallback) { + this.providerStatusCallback = providerStatusCallback; + } + } public interface ContributionResultHandler { - // hints for flags paramter + // hints for flags parameter /** * There are more results to display, but the amount is not known */ diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IProviderStatusCallback.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IProviderStatusCallback.java new file mode 100644 index 00000000..9128c86d --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IProviderStatusCallback.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 436283 + *******************************************************************************/ +package org.eclipse.e4.tools.emf.ui.common; + +/** + * A callback used for a provider to notify a client of status changes + * + * @author Steven Spungin + * + */ +public interface IProviderStatusCallback { + void onStatusChanged(ProviderStatus status); +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ProviderStatus.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ProviderStatus.java new file mode 100644 index 00000000..e882b7aa --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ProviderStatus.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 436283 + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.common; + +/** + * Provider status used in IProviderStatusCallback + * + * @author Steven Spungin + * + */ +public enum ProviderStatus { + INITIALIZING, READY, CANCELLED +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java index 6aa99a24..20ec2d01 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java @@ -8,7 +8,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Steven Spungin <steven@spungin.tv> - Bug 404136, 424730 + * Steven Spungin <steven@spungin.tv> - Bug 404136, Bug 424730, Bug 436281 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs; @@ -29,8 +29,8 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.runtime.CoreException; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.tools.emf.ui.common.FilterEx; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData; +import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter; import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope; import org.eclipse.e4.tools.emf.ui.internal.Messages; import org.eclipse.e4.tools.emf.ui.internal.StringMatcher; @@ -303,7 +303,7 @@ public abstract class AbstractIconDialogWithScopeAndFilter extends FilteredContr clearImages(); callback = new IconMatchCallback((IObservableList) getViewer().getInput()); - FilterEx filter = new FilterEx(project, getFilterTextBox().getText()); + Filter filter = new Filter(project, getFilterTextBox().getText()); filter.setSearchScope(getSearchScopes()); filter.setBundles(getFilterBundles()); filter.setLocations(getFilterLocations()); @@ -374,10 +374,10 @@ public abstract class AbstractIconDialogWithScopeAndFilter extends FilteredContr private final StringMatcher matcherGif; private final StringMatcher matcherJpg; private final StringMatcher matcherPng; - private FilterEx filter; + private Filter filter; private boolean includeNonBundles; - public SearchThread(IconMatchCallback callback, FilterEx filter) { + public SearchThread(IconMatchCallback callback, Filter filter) { this.matcherGif = new StringMatcher("*" + filter.namePattern + "*.gif", true, false); //$NON-NLS-1$//$NON-NLS-2$ this.matcherJpg = new StringMatcher("*" + filter.namePattern + "*.jpg", true, false); //$NON-NLS-1$//$NON-NLS-2$ this.matcherPng = new StringMatcher("*" + filter.namePattern + "*.png", true, false); //$NON-NLS-1$//$NON-NLS-2$ diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java index 5b894dcc..37664453 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625 + * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625, Bug 436281 *******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs; @@ -34,16 +34,18 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.tools.emf.ui.common.FilterEx; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionResultHandler; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter; +import org.eclipse.e4.tools.emf.ui.common.IProviderStatusCallback; +import org.eclipse.e4.tools.emf.ui.common.ProviderStatus; import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope; import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithScopeAndFilter.Entry; import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E; import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialog; import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformClassContributionCollector; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformIconContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.NonReferencedResourceDialog; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; @@ -122,6 +124,10 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { protected BundleImageCache imageCache; protected Job currentSearchThread; private ContributionResultHandlerImpl currentResultHandler; + protected ProviderStatus providerStatus; + protected int hint; + protected int maxResults; + protected boolean searching; abstract protected ClassContributionCollector getCollector(); @@ -135,6 +141,38 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { abstract protected String getShellTitle(); + private void updateStatusMessage() { + String message = ""; //$NON-NLS-1$ + if (searching) { + message += "Searching...\n"; + } + // dlg.setStatus("More than " + filter.maxResults + + // " items were found and have not been displayed"); + if (hint != 0) { + if (hint == ContributionResultHandler.MORE_CANCELED) { + message += "The search was cancelled. Not all results may have been displayed.\n"; + } else { + message += "More than " + maxResults + " items were found. Not all results have been displayed.\n"; + } + } + + if (getCollector() instanceof TargetPlatformContributionCollector) { + if (providerStatus != null) { + switch (providerStatus) { + case READY: + break; + case INITIALIZING: + message += "The provider is initializing. Results will refresh when complete."; + break; + case CANCELLED: + message += "The provider was cancelled while initializing. Results may be incomplete."; + break; + } + } + } + setMessage(message); + } + private class ContributionResultHandlerImpl implements ContributionResultHandler { private boolean cancled = false; private IObservableList list; @@ -164,17 +202,9 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { @Override public void run() { FilteredContributionDialog dlg = (FilteredContributionDialog) filter.userData; - // dlg.setStatus("More than " + filter.maxResults + - // " items were found and have not been displayed"); - if (hint != 0) { - if (hint == ContributionResultHandler.MORE_CANCELED) { - dlg.setMessage("The search was cancelled. Not all results may have been displayed."); - } else { - dlg.setMessage("More than " + filter.maxResults + " items were found. Not all results have been displayed."); - } - } else { - dlg.setMessage(""); - } + dlg.hint = hint; + dlg.maxResults = filter.maxResults; + dlg.updateStatusMessage(); } }); } @@ -317,11 +347,12 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { if (doSearch() == true) { return; } - setMessage("Searching..."); + searching = true; + updateStatusMessage(); currentSearchThread = new Job("Contribution Search") { - FilterEx filter; + Filter filter; @Override protected IStatus run(IProgressMonitor monitor) { @@ -332,11 +363,11 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { @Override public void run() { if (searchScopes.contains(ResourceSearchScope.PROJECT)) { - filter = new FilterEx(context.get(IProject.class), textBox.getText()); + filter = new Filter(context.get(IProject.class), textBox.getText()); } else { - // filter = new FilterEx(null, + // filter = new Filter(null, // textBox.getText()); - filter = new FilterEx(context.get(IProject.class), textBox.getText()); + filter = new Filter(context.get(IProject.class), textBox.getText()); } } }); @@ -348,9 +379,39 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { filter.setSearchScope(searchScopes); filter.setIncludeNonBundles(includeNonBundles); filter.setProgressMonitor(monitor); + filter.setProviderStatusCallback(new IProviderStatusCallback() { + + @Override + public void onStatusChanged(final ProviderStatus status) { + FilteredContributionDialog.this.providerStatus = status; + getShell().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + updateStatusMessage(); + switch (status) { + case READY: + refreshSearch(); + break; + case CANCELLED: + case INITIALIZING: + break; + } + } + }); + } + }); collector.findContributions(filter, currentResultHandler); currentSearchThread = null; monitor.done(); + searching = false; + getShell().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + updateStatusMessage(); + } + }); return Status.OK_STATUS; } @@ -939,8 +1000,9 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { if (bJoin) { try { currentSearchThread.join(); - currentSearchThread = null; } catch (InterruptedException e) { + } finally { + currentSearchThread = null; } } else { currentSearchThread = null; diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java index f4d8c5ba..4e03ae51 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625, Bug 436133, Bug 436132 + * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625, Bug 436133, Bug 436132, Bug 436283, Bug 436281 *******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator; @@ -38,11 +38,15 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; -import org.eclipse.e4.tools.emf.ui.common.FilterEx; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData; import org.eclipse.e4.tools.emf.ui.common.IModelElementProvider; +import org.eclipse.e4.tools.emf.ui.common.IProviderStatusCallback; +import org.eclipse.e4.tools.emf.ui.common.ProviderStatus; import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope; import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FilteredContributionDialog; @@ -54,7 +58,10 @@ import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.internal.core.PDECore; import org.eclipse.pde.internal.core.TargetPlatformHelper; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -64,7 +71,7 @@ import org.w3c.dom.NodeList; /** * A contribution collector encompassing the current target platform.<br /> - * Uses FilterEx for bundle, package, and location filtering.<br /> + * Uses filter for bundle, package, and location filtering.<br /> * This implementation finds resources based on file names, not by parsing file * contents. * @@ -106,7 +113,7 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut Pattern patternName = Pattern.compile(filter.namePattern, Pattern.CASE_INSENSITIVE); - reloadCache(false); + reloadCache(false, filter.getProviderStatusCallback()); int maxResults = filter.maxResults; if (maxResults == 0) { @@ -121,65 +128,62 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut if (stopFiltering) { break; } - // Check for FilterEx filters - if (filter instanceof FilterEx) { - FilterEx filterEx = (FilterEx) filter; - IProgressMonitor monitor = filterEx.getProgressMonitor(); - if (monitor != null) { - if (monitor.isCanceled()) { - stopFiltering = true; - break; - } else { - monitor.subTask("Searching " + e.installLocation); - } + IProgressMonitor monitor = filter.getProgressMonitor(); + if (monitor != null) { + if (monitor.isCanceled()) { + stopFiltering = true; + break; + } else { + monitor.subTask("Searching " + e.installLocation); } + } - if (E.notEmpty(filterEx.getBundles())) { - if (!filterEx.getBundles().contains(e.bundleSymName)) { - continue; - } + if (E.notEmpty(filter.getBundles())) { + if (!filter.getBundles().contains(e.bundleSymName)) { + continue; } - if (E.notEmpty(filterEx.getPackages())) { - if (!filterEx.getPackages().contains(e.pakage)) { - continue; + } + if (E.notEmpty(filter.getPackages())) { + if (!filter.getPackages().contains(e.pakage)) { + continue; + } + } + if (E.notEmpty(filter.getLocations())) { + boolean locationFound = false; + for (String location : filter.getLocations()) { + if (e.installLocation.startsWith(location)) { + locationFound = true; + break; } } - if (E.notEmpty(filterEx.getLocations())) { - boolean locationFound = false; - for (String location : filterEx.getLocations()) { - if (e.installLocation.startsWith(location)) { - locationFound = true; + if (!locationFound) { + continue; + } + } + if (filter.isIncludeNonBundles() == false) { + if (e.bundleSymName == null) { + continue; + } + } + if (filter.getSearchScope().contains(ResourceSearchScope.WORKSPACE)) { + if (filter.project != null) { + IWorkspace workspace = filter.project.getWorkspace(); + boolean fnd = false; + for (IProject project : workspace.getRoot().getProjects()) { + // String path = + // project.getLocationURI().getPath(); + String path = project.getName(); + if (e.installLocation.contains(path)) { + fnd = true; break; } } - if (!locationFound) { + if (!fnd) { continue; } } - if (filterEx.isIncludeNonBundles() == false) { - if (e.bundleSymName == null) { - continue; - } - } - if (filterEx.getSearchScope().contains(ResourceSearchScope.WORKSPACE)) { - if (filter.project != null) { - IWorkspace workspace = filter.project.getWorkspace(); - boolean fnd = false; - for (IProject project : workspace.getRoot().getProjects()) { - // String path = - // project.getLocationURI().getPath(); - String path = project.getName(); - if (e.installLocation.contains(path)) { - fnd = true; - break; - } - } - if (!fnd) { - continue; - } - } - } } + Matcher m = patternName.matcher(e.name); if (m.find()) { found++; @@ -241,7 +245,7 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut * @return A copy of the bundle IDs in the cache. */ public Collection<String> getBundleIds() { - reloadCache(false); + reloadCache(false, null); return new ArrayList<String>(cacheBundleId); } @@ -250,7 +254,7 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut * @return A copy of the bundle IDs in the cache. */ public Collection<String> getPackages() { - reloadCache(false); + reloadCache(false, null); return new ArrayList<String>(cachePackage); } @@ -259,7 +263,7 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut * @return A copy of the bundle IDs in the cache. */ public Collection<String> getLocations() { - reloadCache(false); + reloadCache(false, null); return new ArrayList<String>(cacheLocation); } @@ -269,17 +273,139 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut * * @param force * true to force reload the cache + * @param providerStatusCallback */ - private void reloadCache(boolean force) { + private void reloadCache(boolean force, final IProviderStatusCallback providerStatusCallback) { if (cacheEntry.isEmpty() || force) { + if (providerStatusCallback != null) { + providerStatusCallback.onStatusChanged(ProviderStatus.INITIALIZING); + } cacheEntry.clear(); cacheBundleId.clear(); cachePackage.clear(); cacheLocation.clear(); outputDirectories.clear(); + final Job job = new Job("Build Target Platform Index") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + // load workspace projects + IProject[] projects = PDECore.getWorkspace().getRoot().getProjects(); + IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); + int total = projects.length + models.length; + monitor.beginTask(Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", total); //$NON-NLS-1$ + + for (final IProject pj : projects) { + if (monitor.isCanceled()) { + break; + } + String rootDirectory = pj.getLocation().toOSString(); + monitor.subTask(rootDirectory); + monitor.worked(1); + TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory)); + } + + // load target platform bundles + for (IPluginModelBase pluginModelBase : models) { + monitor.subTask(pluginModelBase.getPluginBase().getId()); + monitor.worked(1); + if (monitor.isCanceled()) { + break; + } + + IPluginBase pluginBase = pluginModelBase.getPluginBase(); + if (pluginBase == null) { + // bundle = getBundle(new File()) + continue; + } + URL url; + try { + String installLocation = pluginModelBase.getInstallLocation(); + if (installLocation.endsWith(".jar")) { //$NON-NLS-1$ + url = new URL("file://" + installLocation); //$NON-NLS-1$ + ZipInputStream zis = new ZipInputStream(url.openStream()); + while (true) { + ZipEntry entry = zis.getNextEntry(); + if (entry == null) { + break; + } else { + String name2 = entry.getName(); + if (shouldIgnore(name2)) { + continue; + } + Matcher m = patternFile.matcher(name2); + if (m.matches()) { + Entry e = new Entry(); + e.installLocation = installLocation; + cacheLocation.add(installLocation); + e.name = m.group(2); + e.path = m.group(1); + if (e.path != null) { + e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ + if (e.pakage.startsWith(".")) { //$NON-NLS-1$ + e.pakage = e.pakage.substring(1); + } + if (e.pakage.endsWith(".")) { //$NON-NLS-1$ + e.pakage = e.pakage.substring(0, e.pakage.length() - 1); + } + } else { + e.pakage = ""; //$NON-NLS-1$ + } + cachePackage.add(e.pakage); + + e.bundleSymName = pluginBase.getId(); + if (e.path == null) { + e.path = ""; //$NON-NLS-1$ + } + cacheEntry.add(e); + cacheBundleId.add(pluginBase.getId()); + + // + // System.out.println(group + // + " -> " + // + + // m.group(2)); + } + } + } + } else { + // not a jar file + String bundle = getBundle(new File(installLocation)); + if (bundle != null) { + visit(monitor, bundle, installLocation, new File(installLocation)); + } + } + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + monitor.done(); + if (monitor.isCanceled()) { + if (providerStatusCallback != null) { + providerStatusCallback.onStatusChanged(ProviderStatus.CANCELLED); + } + return Status.CANCEL_STATUS; + } else { + if (providerStatusCallback != null) { + providerStatusCallback.onStatusChanged(ProviderStatus.READY); + } + return Status.OK_STATUS; + } + } + }; + job.schedule(); + + // User Job will not display dialog if called from a modal dialog, + // so we wrap a plain ol' job in a ProgressMonitorDialog Display.getDefault().syncExec(new Runnable() { + boolean runInBackground = false; + @Override public void run() { ProgressMonitorDialog dlg = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) { @@ -294,106 +420,38 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut return ret; } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + Button button = createButton(parent, 101, "Run In Background", false); + // TODO JA + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + runInBackground = true; + } + }); + super.createButtonsForButtonBar(parent); + + // Do not use arrow cursor until calling super + // TODO ProgressMonitorDialog should encapsulate + // arrowCurson + button.setCursor(arrowCursor); + } + + @Override + protected void cancelPressed() { + job.cancel(); + } }; try { dlg.run(true, true, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - - // load workspace projects - IProject[] projects = PDECore.getWorkspace().getRoot().getProjects(); - IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); - int total = projects.length + models.length; - monitor.beginTask(Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", total); //$NON-NLS-1$ - - for (final IProject pj : projects) { - if (monitor.isCanceled()) { - break; - } - String rootDirectory = pj.getLocation().toOSString(); - monitor.subTask(rootDirectory); - monitor.worked(1); - TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory)); - } - - // load target platform bundles - for (IPluginModelBase pluginModelBase : models) { - monitor.subTask(pluginModelBase.getPluginBase().getId()); - monitor.worked(1); - if (monitor.isCanceled()) { - break; - } - - IPluginBase pluginBase = pluginModelBase.getPluginBase(); - if (pluginBase == null) { - // bundle = getBundle(new File()) - continue; - } - URL url; - try { - String installLocation = pluginModelBase.getInstallLocation(); - if (installLocation.endsWith(".jar")) { //$NON-NLS-1$ - url = new URL("file://" + installLocation); //$NON-NLS-1$ - ZipInputStream zis = new ZipInputStream(url.openStream()); - while (true) { - ZipEntry entry = zis.getNextEntry(); - if (entry == null) { - break; - } else { - String name2 = entry.getName(); - if (shouldIgnore(name2)) { - continue; - } - Matcher m = patternFile.matcher(name2); - if (m.matches()) { - Entry e = new Entry(); - e.installLocation = installLocation; - cacheLocation.add(installLocation); - e.name = m.group(2); - e.path = m.group(1); - if (e.path != null) { - e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ - if (e.pakage.startsWith(".")) { //$NON-NLS-1$ - e.pakage = e.pakage.substring(1); - } - if (e.pakage.endsWith(".")) { //$NON-NLS-1$ - e.pakage = e.pakage.substring(0, e.pakage.length() - 1); - } - } else { - e.pakage = ""; //$NON-NLS-1$ - } - cachePackage.add(e.pakage); - - e.bundleSymName = pluginBase.getId(); - if (e.path == null) { - e.path = ""; //$NON-NLS-1$ - } - cacheEntry.add(e); - cacheBundleId.add(pluginBase.getId()); - - // - // System.out.println(group - // + " -> " - // + - // m.group(2)); - } - } - } - } else { - // not a jar file - String bundle = getBundle(new File(installLocation)); - if (bundle != null) { - visit(monitor, bundle, installLocation, new File(installLocation)); - } - } - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + monitor.beginTask("Waiting for target platform indexing to complete", IProgressMonitor.UNKNOWN); + while (job.getState() == job.RUNNING && !runInBackground) { + Thread.sleep(100); } monitor.done(); } @@ -406,8 +464,8 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut e1.printStackTrace(); } } - }); + }); } } |