Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Spungin2014-05-23 16:25:09 +0000
committerSteven Spungin2014-05-23 19:24:22 +0000
commit3cb4e381064f5ae94584e24d5e0f016556d4dd07 (patch)
treebdf901a3b052f02d9833c2401dce6bee0e3d4650
parent2f909a22033aa2b6f839a94aa68970d4bfedf386 (diff)
downloadorg.eclipse.e4.tools-3cb4e381064f5ae94584e24d5e0f016556d4dd07.tar.gz
org.eclipse.e4.tools-3cb4e381064f5ae94584e24d5e0f016556d4dd07.tar.xz
org.eclipse.e4.tools-3cb4e381064f5ae94584e24d5e0f016556d4dd07.zip
Bug 435625 - [target platform search] Do search in background thread
Change-Id: If8676d05437fd2e3c93a7392291205e2ac211123 Signed-off-by: Steven Spungin <steven@spungin.tv>
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java12
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java167
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java227
3 files changed, 249 insertions, 157 deletions
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
index 765aca72..4ff10efc 100644
--- 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
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.common;
@@ -14,6 +14,7 @@ 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;
/**
@@ -30,6 +31,7 @@ public class FilterEx extends Filter {
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);
@@ -101,4 +103,12 @@ public class FilterEx extends Filter {
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/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 e31df874..6ce706ed 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, 424730
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
@@ -29,6 +29,10 @@ import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+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.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.common.FilterEx;
import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
@@ -116,6 +120,8 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog {
private Button btnIncludeNoneBundle;
private WritableList viewerList;
protected BundleImageCache imageCache;
+ protected Job currentSearchThread;
+ private ContributionResultHandlerImpl currentResultHandler;
abstract protected ClassContributionCollector getCollector();
@@ -129,7 +135,7 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog {
abstract protected String getShellTitle();
- private static class ContributionResultHandlerImpl implements ContributionResultHandler {
+ private class ContributionResultHandlerImpl implements ContributionResultHandler {
private boolean cancled = false;
private IObservableList list;
@@ -138,26 +144,46 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog {
}
@Override
- public void result(ContributionData data) {
+ public void result(final ContributionData data) {
if (!cancled) {
- list.add(data);
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ list.add(data);
+ }
+ });
}
}
@Override
- public void moreResults(int hint, Filter filter) {
- FilteredContributionDialog dlg = (FilteredContributionDialog) filter.userData;
- // dlg.setStatus("More than " + filter.maxResults +
- // " items were found and have not been displayed");
- if (hint != 0) {
- dlg.setMessage("More than " + filter.maxResults + " items were found. Not all results have been displayed.");
- } else {
- dlg.setMessage("");
+ public void moreResults(final int hint, final Filter filter) {
+ if (!cancled) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @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) {
+ dlg.setMessage("More than " + filter.maxResults + " items were found. Not all results have been displayed.");
+ } else {
+ dlg.setMessage("");
+ }
+ }
+ });
}
}
}
@Override
+ public boolean close() {
+ stopSearchThread(true);
+ return super.close();
+ }
+
+ @Override
protected Control createContents(Composite parent) {
Control ret = super.createContents(parent);
textBox.notifyListeners(SWT.Modify, new Event());
@@ -254,57 +280,80 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog {
collector = getCollector();
- textBox.addModifyListener(new ModifyListener() {
- private ContributionResultHandlerImpl currentResultHandler;
+ textBox.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.ARROW_DOWN) {
+ if (viewer.getTable().getItemCount() > 0) {
+ viewer.getTable().setFocus();
+ viewer.getTable().select(0);
+ }
+ }
+ }
+ });
+ viewer.getTable().addKeyListener(new KeyAdapter() {
@Override
- public void modifyText(ModifyEvent e) {
- if (currentResultHandler != null) {
- currentResultHandler.cancled = true;
+ public void keyPressed(KeyEvent e) {
+ super.keyPressed(e);
+ if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) {
+ textBox.setFocus();
}
- viewerList.clear();
+ }
+ });
+
+ textBox.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ stopSearchThread(true);
setMessage(""); //$NON-NLS-1$
+
+ viewerList.clear();
if (doSearch() == true) {
return;
}
+ setMessage("Searching...");
+
+ currentSearchThread = new Job("Contribution Search") {
+
+ FilterEx filter;
- currentResultHandler = new ContributionResultHandlerImpl(viewerList);
- FilterEx filter;
- if (searchScopes.contains(ResourceSearchScope.PROJECT)) {
- filter = new FilterEx(context.get(IProject.class), textBox.getText());
- } else {
- // filter = new FilterEx(null, textBox.getText());
- filter = new FilterEx(context.get(IProject.class), textBox.getText());
- }
- filter.maxResults = MAX_RESULTS;
- filter.userData = FilteredContributionDialog.this;
- filter.setBundles(filterBundles);
- filter.setPackages(filterPackages);
- filter.setLocations(filterLocations);
- filter.setSearchScope(searchScopes);
- filter.setIncludeNonBundles(includeNonBundles);
- collector.findContributions(filter, currentResultHandler);
- textBox.addKeyListener(new KeyAdapter() {
@Override
- public void keyPressed(KeyEvent e) {
- if (e.keyCode == SWT.ARROW_DOWN) {
- if (viewer.getTable().getItemCount() > 0) {
- viewer.getTable().setFocus();
- viewer.getTable().select(0);
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Contribution Search", IProgressMonitor.UNKNOWN);
+ currentResultHandler = new ContributionResultHandlerImpl(viewerList);
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if (searchScopes.contains(ResourceSearchScope.PROJECT)) {
+ filter = new FilterEx(context.get(IProject.class), textBox.getText());
+ } else {
+ // filter = new FilterEx(null,
+ // textBox.getText());
+ filter = new FilterEx(context.get(IProject.class), textBox.getText());
+ }
}
- }
+ });
+ filter.maxResults = MAX_RESULTS;
+ filter.userData = FilteredContributionDialog.this;
+ filter.setBundles(filterBundles);
+ filter.setPackages(filterPackages);
+ filter.setLocations(filterLocations);
+ filter.setSearchScope(searchScopes);
+ filter.setIncludeNonBundles(includeNonBundles);
+ filter.setProgressMonitor(monitor);
+ collector.findContributions(filter, currentResultHandler);
+ currentSearchThread = null;
+ monitor.done();
+ return Status.OK_STATUS;
}
- });
- viewer.getTable().addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- super.keyPressed(e);
- if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) {
- textBox.setFocus();
- }
- }
- });
+
+ };
+
+ currentSearchThread.schedule();
+
}
});
@@ -879,6 +928,22 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog {
return searchScopes;
}
+ public void stopSearchThread(boolean bJoin) {
+ if (currentSearchThread != null) {
+ currentResultHandler.cancled = true;
+ currentSearchThread.cancel();
+ if (bJoin) {
+ try {
+ currentSearchThread.join();
+ currentSearchThread = null;
+ } catch (InterruptedException e) {
+ }
+ } else {
+ currentSearchThread = null;
+ }
+ }
+ }
+
static public String getBundle(IFile file) {
if (file instanceof ContributionDataFile) {
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 1a5addaf..68a7b704 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
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730, Bug 435625
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
@@ -114,9 +114,19 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut
int found = 0;
boolean more = false;
for (Entry e : cacheEntry) {
+
// Check for FilterEx filters
if (filter instanceof FilterEx) {
FilterEx filterEx = (FilterEx) filter;
+ IProgressMonitor monitor = filterEx.getProgressMonitor();
+ if (monitor != null) {
+ if (monitor.isCanceled()) {
+ break;
+ } else {
+ monitor.subTask("Searching " + e.installLocation);
+ }
+ }
+
if (E.notEmpty(filterEx.getBundles())) {
if (!filterEx.getBundles().contains(e.bundleSymName)) {
continue;
@@ -208,7 +218,7 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut
ip = ip.addTrailingSeparator().makeRelative();
ip = ip.append(e.name);
String className = ip.toOSString().replace('/', '.');
- ContributionData data = new ContributionData(e.bundleSymName, className, "Java", e.installLocation); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ContributionData data = new ContributionData(e.bundleSymName, className, "Java", e.installLocation); //$NON-NLS-1$
data.installLocation = e.installLocation;
data.resourceRelativePath = e.relativePath;
return data;
@@ -256,124 +266,131 @@ public abstract class TargetPlatformContributionCollector extends ClassContribut
cacheLocation.clear();
outputDirectories.clear();
- ProgressMonitorDialog dlg = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) {
+ Display.getDefault().syncExec(new Runnable() {
@Override
- protected Control createContents(Composite parent) {
- // TODO odd this is not a bean.
- Composite ret = (Composite) super.createContents(parent);
- Label label = new Label(ret, SWT.NONE);
- label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
- label.setText(Messages.TargetPlatformContributionCollector_pleaseWait);
-
- return ret;
- }
- };
- try {
- dlg.run(true, true, new IRunnableWithProgress() {
+ public void run() {
+ ProgressMonitorDialog dlg = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) {
+
+ @Override
+ protected Control createContents(Composite parent) {
+ // TODO odd this is not a bean.
+ Composite ret = (Composite) super.createContents(parent);
+ Label label = new Label(ret, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
+ label.setText(Messages.TargetPlatformContributionCollector_pleaseWait);
+
+ return ret;
+ }
+ };
+ try {
+ dlg.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ @Override
+ public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- // load workspace projects
- for (final IProject pj : PDECore.getWorkspace().getRoot().getProjects()) {
- if (monitor.isCanceled()) {
- break;
- }
- String rootDirectory = pj.getLocation().toOSString();
- TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory));
- }
+ // load workspace projects
+ for (final IProject pj : PDECore.getWorkspace().getRoot().getProjects()) {
+ if (monitor.isCanceled()) {
+ break;
+ }
+ String rootDirectory = pj.getLocation().toOSString();
+ TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory));
+ }
- // load target platform bundles
- IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
- monitor.beginTask(Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", models.length); //$NON-NLS-2$
- for (IPluginModelBase pluginModelBase : models) {
- monitor.subTask(pluginModelBase.getPluginBase().getId());
- monitor.worked(1);
- if (monitor.isCanceled()) {
- break;
- }
+ // load target platform bundles
+ IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
+ monitor.beginTask(Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", models.length); //$NON-NLS-1$
+ 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);
+ 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;
}
- if (e.pakage.endsWith(".")) { //$NON-NLS-1$
- e.pakage = e.pakage.substring(0, e.pakage.length() - 1);
+ 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 {
- 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));
}
}
- }
- } 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();
}
}
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ monitor.done();
}
- }
- monitor.done();
+ });
+ } catch (InvocationTargetException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
}
- });
- } catch (InvocationTargetException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ }
+ });
+
}
}

Back to the top