Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErich Gamma2004-04-13 09:01:30 +0000
committerErich Gamma2004-04-13 09:01:30 +0000
commit18f3b53bff6e3f8f6bcaa7a48ab8b01fcd9abc19 (patch)
tree4d9cbd3d9b33816d768e3285703dcbc7bc63b5ae
parent1acf79cd877363c20e5bdd3473a118a5200020eb (diff)
downloadeclipse.platform.text-18f3b53bff6e3f8f6bcaa7a48ab8b01fcd9abc19.tar.gz
eclipse.platform.text-18f3b53bff6e3f8f6bcaa7a48ab8b01fcd9abc19.tar.xz
eclipse.platform.text-18f3b53bff6e3f8f6bcaa7a48ab8b01fcd9abc19.zip
show progress bar in status area during search
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java64
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java139
2 files changed, 180 insertions, 23 deletions
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
index fb4584c22..91eaf0135 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
@@ -62,6 +62,7 @@ public class InternalSearchUI {
public Job fJob;
public boolean fBackground;
public boolean fIsRunning;
+ public ProgressMonitorWrapper fProgressMonitor;
SearchJobRecord(ISearchQuery job, boolean bg) {
fQuery= job;
@@ -70,6 +71,50 @@ public class InternalSearchUI {
}
}
+ private class ProgressMonitorWrapper implements IProgressMonitor {
+ private IProgressMonitor fMonitor;
+ public int fTotalWork;
+ public double fWorked;
+
+ public ProgressMonitorWrapper(IProgressMonitor pm) {
+ fMonitor= pm;
+ }
+
+ public void beginTask(String name, int totalWork) {
+ fTotalWork= totalWork;
+ fMonitor.beginTask(name, totalWork);
+ }
+
+ public void done() {
+ fMonitor.done();
+ }
+
+ public void internalWorked(double work) {
+ fWorked+= work;
+ fMonitor.internalWorked(work);
+ }
+
+ public boolean isCanceled() {
+ return fMonitor.isCanceled();
+ }
+
+ public void setCanceled(boolean value) {
+ fMonitor.setCanceled(value);
+ }
+
+ public void setTaskName(String name) {
+ fMonitor.setTaskName(name);
+ }
+
+ public void subTask(String name) {
+ fMonitor.subTask(name);
+ }
+
+ public void worked(int work) {
+ fMonitor.worked(work);
+ }
+
+ }
private class InternalSearchJob extends Job {
SearchJobRecord fSearchJobRecord;
public InternalSearchJob(SearchJobRecord sjr) {
@@ -79,10 +124,11 @@ public class InternalSearchUI {
protected IStatus run(IProgressMonitor monitor) {
fSearchJobRecord.fJob= this;
+ fSearchJobRecord.fProgressMonitor= new ProgressMonitorWrapper(monitor);
searchJobStarted(fSearchJobRecord);
IStatus status= null;
try{
- status= fSearchJobRecord.fQuery.run(monitor);
+ status= fSearchJobRecord.fQuery.run(fSearchJobRecord.fProgressMonitor);
} finally {
searchJobFinished(fSearchJobRecord);
}
@@ -166,8 +212,6 @@ public class InternalSearchUI {
}
private void configureJob(Job job) {
- job.setProperty(new QualifiedName("org.eclipse.ui.workbench.progress", "keep"), Boolean.TRUE);
- job.setProperty(new QualifiedName("org.eclipse.ui.workbench.progress", "goto"), new ShowJobResultAction());
try {
URL install= SearchPlugin.getDefault().getDescriptor().getInstallURL();
URL icon;
@@ -246,6 +290,20 @@ public class InternalSearchUI {
rec.fJob.cancel();
}
+ public int getAmountOfWork(ISearchQuery job) {
+ SearchJobRecord rec= (SearchJobRecord) fSearchJobs.get(job);
+ if (rec != null && rec.fJob != null)
+ return rec.fProgressMonitor.fTotalWork;
+ return 0;
+ }
+
+ public double getCurrentAmountOfWork(ISearchQuery job) {
+ SearchJobRecord rec= (SearchJobRecord) fSearchJobs.get(job);
+ if (rec != null && rec.fJob != null)
+ return rec.fProgressMonitor.fWorked;
+ return 1;
+ }
+
public ISearchResultViewPart activateSearchView() {
String defaultPerspectiveId= SearchUI.getDefaultPerspectiveId();
if (defaultPerspectiveId != null) {
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
index 587bec659..054c52064 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java
@@ -2,19 +2,31 @@ package org.eclipse.search2.internal.ui;
import java.util.HashMap;
import java.util.Iterator;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Tree;
-
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
-
+import org.eclipse.search.internal.ui.SearchPluginImages;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.search.ui.IQueryListener;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultListener;
+import org.eclipse.search.ui.ISearchResultPage;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.SearchResultEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.ProgressBar;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IViewSite;
@@ -29,17 +41,7 @@ import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
-
-import org.eclipse.search.ui.IContextMenuConstants;
-import org.eclipse.search.ui.IQueryListener;
-import org.eclipse.search.ui.ISearchQuery;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultListener;
-import org.eclipse.search.ui.ISearchResultPage;
-import org.eclipse.search.ui.ISearchResultViewPart;
-import org.eclipse.search.ui.SearchResultEvent;
-
-import org.eclipse.search.internal.ui.SearchPluginImages;
+import org.eclipse.ui.progress.UIJob;
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
@@ -70,6 +72,10 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
private CancelSearchAction fCancelAction;
private IMemento fPageState;
+ private ProgressBar fBar;
+ private UpdateUIJob fUpdateJob;
+ private Composite fParent;
+
private static void createStandardGroups(IContributionManager menu) {
menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
@@ -175,6 +181,28 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
}
}
+ class UpdateUIJob extends UIJob {
+ private boolean fRunning= true;
+
+ public UpdateUIJob(String name) {
+ super(name);
+ setSystem(true);
+ }
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ refreshProgress();
+ schedule(200);
+ return Status.OK_STATUS;
+ }
+
+ public void stop() {
+ fRunning= false;
+ }
+ public boolean shouldSchedule() {
+ return fRunning;
+ }
+
+
+ }
public SearchView() {
super();
fPartsToPages= new HashMap();
@@ -258,7 +286,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
page.setInput(search, fSearchViewStates.get(search));
updateTitle(search);
}
-
+
private void updateTitle(ISearchResult search) {
if (search != null) {
boolean queryRunning= InternalSearchUI.getInstance().isQueryRunning(search.getQuery());
@@ -277,17 +305,66 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
}
}
+ protected void refreshProgress() {
+ ISearchQuery query= getCurrentSearchResult().getQuery();
+ double current= InternalSearchUI.getInstance().getCurrentAmountOfWork(query);
+ boolean queryRunning= InternalSearchUI.getInstance().isQueryRunning(query);
+ if (fBar != null) {
+ if (queryRunning) {
+ fBar.setSelection((int)current);
+ } else {
+ hideProgressBar();
+ }
+ }
+ }
+
public ISearchResult getCurrentSearchResult() {
return fCurrentSearch;
}
public void createPartControl(Composite parent) {
+ fParent= parent;
+ GridLayout gridLayout= new GridLayout();
+ gridLayout.numColumns= 1;
+ gridLayout.horizontalSpacing= 0;
+ gridLayout.marginHeight= 0;
+ gridLayout.marginWidth= 0;
+ gridLayout.verticalSpacing= 0;
+ gridLayout.horizontalSpacing= 0;
+ parent.setLayout(gridLayout);
+
super.createPartControl(parent);
+
+ Composite book= getPageBook();
+ GridData gd= new GridData();
+ gd.horizontalAlignment= GridData.FILL;
+ gd.verticalAlignment= GridData.FILL;
+ gd.grabExcessHorizontalSpace= true;
+ gd.grabExcessVerticalSpace= true;
+ book.setLayoutData(gd);
+
createActions();
initializeToolBar();
InternalSearchUI.getInstance().getSearchManager().addQueryListener(this);
}
+ private void showProgressBar() {
+ fBar= new ProgressBar(fParent, SWT.HORIZONTAL);
+ GridData gd= new GridData();
+ gd.horizontalAlignment= GridData.FILL;
+ gd.grabExcessHorizontalSpace= true;
+ gd.heightHint= 12;
+ fBar.setLayoutData(gd);
+ fBar.setVisible(true);
+ fParent.layout(true);
+ }
+
+ private void hideProgressBar() {
+ fBar.dispose();
+ fBar= null;
+ fParent.layout(true);
+ }
+
private void initializeToolBar() {
IToolBarManager tbm= getViewSite().getActionBars().getToolBarManager();
createStandardGroups(tbm);
@@ -344,10 +421,32 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
public void queryStarting(ISearchQuery query) {
updateTitle();
+ if (getPageBook() != null && !getPageBook().isDisposed()) {
+ getPageBook().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ ISearchResult result= getCurrentSearchResult();
+ showProgressBar();
+ int max= InternalSearchUI.getInstance().getAmountOfWork(result.getQuery());
+ fBar.setMaximum(max);
+ fUpdateJob= new UpdateUIJob("Refresh Search Progress"); //$NON-NLS-1$
+ fUpdateJob.schedule(200);
+ }
+ });
+ }
+
}
public void queryFinished(ISearchQuery query) {
updateTitle();
+ if (getPageBook() != null && !getPageBook().isDisposed()) {
+ getPageBook().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (fBar != null)
+ hideProgressBar();
+ }
+ });
+ }
+ fUpdateJob.stop();
}
// Methods related to saving page state. -------------------------------------------

Back to the top