Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Maeder2004-03-03 14:42:09 +0000
committerThomas Maeder2004-03-03 14:42:09 +0000
commit97e57831f92d884eaac83909dfa7791ce39ea377 (patch)
tree1042f61b772f05d140c9819136e7e22b0a081f76 /org.eclipse.search
parentd57d26ee320edddd9460058503ad049ff5ba3cd7 (diff)
downloadeclipse.platform.text-97e57831f92d884eaac83909dfa7791ce39ea377.tar.gz
eclipse.platform.text-97e57831f92d884eaac83909dfa7791ce39ea377.tar.xz
eclipse.platform.text-97e57831f92d884eaac83909dfa7791ce39ea377.zip
Results of API review + added some tests
Diffstat (limited to 'org.eclipse.search')
-rw-r--r--org.eclipse.search/.project4
-rw-r--r--org.eclipse.search/icons/full/clcl16/stop.gifbin0 -> 109 bytes
-rw-r--r--org.eclipse.search/icons/full/clcl16/stop_nav.gifbin163 -> 0 bytes
-rw-r--r--org.eclipse.search/icons/full/dlcl16/stop.gifbin0 -> 85 bytes
-rw-r--r--org.eclipse.search/icons/full/dlcl16/stop_nav.gifbin91 -> 0 bytes
-rw-r--r--org.eclipse.search/icons/full/elcl16/stop.gifbin0 -> 88 bytes
-rw-r--r--org.eclipse.search/icons/full/elcl16/stop_nav.gifbin120 -> 0 bytes
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/IQueryListener.java (renamed from org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManagerListener.java)20
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/ISearchQuery.java32
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/ISearchResult.java24
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultListener.java2
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManager.java56
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultPage.java28
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/NewSearchUI.java62
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/SearchResultEvent.java3
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java108
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java99
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/CancelSearchAction.java5
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java93
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java (renamed from org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchResultsManager.java)63
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchAgainAction.java2
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java10
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java77
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchesAction.java15
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java108
-rw-r--r--org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java29
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java2
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java23
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java17
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java9
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java6
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java5
32 files changed, 515 insertions, 387 deletions
diff --git a/org.eclipse.search/.project b/org.eclipse.search/.project
index aa7e58b5ea3..378d65270af 100644
--- a/org.eclipse.search/.project
+++ b/org.eclipse.search/.project
@@ -5,14 +5,10 @@
<projects>
<project>org.eclipse.core.boot</project>
<project>org.eclipse.core.filebuffers</project>
- <project>org.eclipse.core.resources</project>
<project>org.eclipse.core.runtime</project>
- <project>org.eclipse.core.runtime.compatibility</project>
<project>org.eclipse.jface.text</project>
<project>org.eclipse.swt</project>
- <project>org.eclipse.ui</project>
<project>org.eclipse.ui.editors</project>
- <project>org.eclipse.ui.ide</project>
<project>org.eclipse.ui.workbench.texteditor</project>
</projects>
<buildSpec>
diff --git a/org.eclipse.search/icons/full/clcl16/stop.gif b/org.eclipse.search/icons/full/clcl16/stop.gif
new file mode 100644
index 00000000000..d47876f6857
--- /dev/null
+++ b/org.eclipse.search/icons/full/clcl16/stop.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/clcl16/stop_nav.gif b/org.eclipse.search/icons/full/clcl16/stop_nav.gif
deleted file mode 100644
index 4eb53ec41c4..00000000000
--- a/org.eclipse.search/icons/full/clcl16/stop_nav.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.search/icons/full/dlcl16/stop.gif b/org.eclipse.search/icons/full/dlcl16/stop.gif
new file mode 100644
index 00000000000..bf1546066bd
--- /dev/null
+++ b/org.eclipse.search/icons/full/dlcl16/stop.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/dlcl16/stop_nav.gif b/org.eclipse.search/icons/full/dlcl16/stop_nav.gif
deleted file mode 100644
index 7f0f9b925f8..00000000000
--- a/org.eclipse.search/icons/full/dlcl16/stop_nav.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.search/icons/full/elcl16/stop.gif b/org.eclipse.search/icons/full/elcl16/stop.gif
new file mode 100644
index 00000000000..8ea6ff73dcd
--- /dev/null
+++ b/org.eclipse.search/icons/full/elcl16/stop.gif
Binary files differ
diff --git a/org.eclipse.search/icons/full/elcl16/stop_nav.gif b/org.eclipse.search/icons/full/elcl16/stop_nav.gif
deleted file mode 100644
index a519f44d453..00000000000
--- a/org.eclipse.search/icons/full/elcl16/stop_nav.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManagerListener.java b/org.eclipse.search/new search/org/eclipse/search/ui/IQueryListener.java
index 93b6213cfa2..b799f49c028 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManagerListener.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/IQueryListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Common Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/cpl-v10.html
@@ -8,24 +8,24 @@
******************************************************************************/
package org.eclipse.search.ui;
/**
- * A listener for changes to the set of ISearchResults
+ * A listener for changes to the set of search queries.
+ * This interface is supposed to be implemented by clients.
*
* This API is preliminary and subject to change at any time.
*
* @since 3.0
*/
-public interface ISearchResultManagerListener {
+public interface IQueryListener {
/**
- * Called when an ISearchResult has been added to the ISearchResultManager.
+ * Called when an query has been added to the system.
*
- * @param search The search result that has been added
+ * @param query The query that has been added
*/
- void searchResultAdded(ISearchResult search);
+ void queryAdded(ISearchQuery query);
/**
- * Called when an ISearchResult has been removed from the
- * ISearchResultManager.
+ * Called when a query has been removed.
*
- * @param search The search result that has been removed
+ * @param query The query that has been removed
*/
- void searchResultRemoved(ISearchResult search);
+ void queryRemoved(ISearchQuery query);
}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchQuery.java b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchQuery.java
index 36515c72c4f..b00c1913930 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchQuery.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchQuery.java
@@ -10,8 +10,8 @@ package org.eclipse.search.ui;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
/**
- * Represents a particular search query (i.e. "fina all occurrences of 'foo' in
- * workspace"). When executed, the query must update the given search result
+ * Represents a particular search query (e.g. "find all occurrences of 'foo' in
+ * workspace"). When executed, the query must update its ISearchResult
* with the results of the query. This interface must be implemented by
* clients.
*
@@ -24,16 +24,32 @@ public interface ISearchQuery {
* Runs this query.
*
* @param monitor The progress monitor to be used
- * @param result The search result where the query should put the results.
* @return The status after completion of the search job.
*/
- IStatus run(IProgressMonitor monitor, ISearchResult result);
+ IStatus run(IProgressMonitor monitor);
/**
- * Returns the name of this search job. This will be used, for example to
- * set the <code>Job</code> name if this search job is executed in the
+ * Returns the a user readeable label for this query. This will be used, for example to
+ * set the <code>Job</code> name if this query is executed in the
* background.
*
- * @return The user readeable name of this query.
+ * @return The user readeable label of this query.
*/
- String getName();
+ String getLabel();
+ /**
+ * Returns whether the query can be run more than once. Some queries may depend on transient
+ * information.
+ * @return Whether this query can be run more than once.
+ */
+ boolean canRerun();
+ /**
+ * Returns whether this query can be run in the background. Note that queries must do proper locking
+ * when they are run in the background (e.g. get the appropriate workspace locks).
+ * @return Whether this query can be run in the background.
+ */
+ boolean canRunInBackground();
+ /**
+ * Returns the search result associated with this query.
+ * @return This query's search result.
+ */
+ ISearchResult getSearchResult();
}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResult.java b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResult.java
index 3c6cbbd9de9..a300cbf7fc1 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResult.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResult.java
@@ -15,49 +15,43 @@ import org.eclipse.jface.resource.ImageDescriptor;
/**
* Represents the result of a search. No assumptions about the
* structure of these results is made at this level.
- * Clients may implement this interface. In fact the choice of
- * which org.eclipse.search2.ui.ISearchResultsPage is used
- * to present the ISearchResult is based on the type of search
- * result a client creates.
+ * Clients may implement this interface.
*
* This API is preliminary and subject to change at any time.
* @since 3.0
*/
public interface ISearchResult {
/**
- * Adds a ISearchResultChangedListener. Has no effect when the
+ * Adds a <code>ISearchResultListener</code>. Has no effect when the
* listener has already been added.
- * @param l
+ * @param l The listener to be added
*/
public void addListener(ISearchResultListener l);
/**
* Removes a ISearchResultChangedListener. Has no effect when the
* listener hasn't previously been added.
- * @param l
+ * @param l The listener to be removed.
*/
public void removeListener(ISearchResultListener l);
/**
- * Returns a user readeable label for the given ISearchResult.
+ * Returns a user readeable label for this search result.
* @return The label for this search result.
*/
- String getText();
+ String getLabel();
/**
- * Returns a tooltip for the given ISearchResult.
+ * Returns a tooltip for this search result.
* @return A user readeable String.
*/
public String getTooltip();
/**
* Returns an image descriptor for the given ISearchResult.
- * The image descriptor will be used for rendereing in menus,
- * view titles, etc.
* @return An image representing this search result or <code>null</code>.
*/
ImageDescriptor getImageDescriptor();
/**
- * Returns the query that is responsible for putting matches for this
- * search result.
- * @return The query producing this result or <code>null</code>
+ * Returns the query that produced this search result.
+ * @return The query producing this result.
*/
ISearchQuery getQuery();
}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultListener.java b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultListener.java
index 99a9ccced3d..c93d5f9e6b5 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultListener.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultListener.java
@@ -20,7 +20,7 @@ public interface ISearchResultListener {
* The event object <code>e</code> can only guarantueed to be valid for
* the duration of the call.
*
- * @param e The event object describing the change. Notice that
+ * @param e The event object describing the change. Note that
* implementers of <code>ISearchResult</code> will be sending
* subclasses of <code>SearchResultEvent</code>.
*/
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManager.java b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManager.java
deleted file mode 100644
index f0c0df5e0d3..00000000000
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultManager.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Common Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.search.ui;
-/**
- * This class manages the set of search results.
- *
- * This API is preliminary and subject to change at any time.
- *
- * @since 3.0
- */
-public interface ISearchResultManager {
- /**
- * Returns all search results know to this ISearchResultManager.
- *
- * @return All search result.
- */
- ISearchResult[] getSearchResults();
- /**
- * Removes the given search result from this manager. Does nothing if the
- * search result is not found
- *
- * @param search
- */
- void removeSearchResult(ISearchResult searchResult);
- /**
- * Adds the given search result to the search manager Does nothing if the
- * search result is already present.
- *
- * @param searchResult
- */
- void addSearchResult(ISearchResult searchResult);
- /**
- * Adds the given listener. Does nothing when the listener is already
- * present.
- *
- * @param l The listener to be added.
- */
- public void addSearchResultListener(ISearchResultManagerListener l);
- /**
- * Removes the give ISearchResultListener. Does nothing if the listener is
- * not present.
- *
- * @param l The listener to be removed.
- */
- public void removeSearchResultListener(ISearchResultManagerListener l);
- /**
- * Removes all <code>ISearchResults</code> from search manager.
- */
- void removeAll();
-}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultPage.java b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultPage.java
index 7838a213fe2..55f74258920 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultPage.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/ISearchResultPage.java
@@ -10,7 +10,11 @@ package org.eclipse.search.ui;
import org.eclipse.ui.part.IPageBookViewPage;
/**
* Extensions of extension point org.eclipse.search.ui.searchResultViewPages
- * must implement this interface
+ * must implement this interface.
+ * When the user selects an <code>ISearchResult</code> in the search results
+ * view, the corresponding (as configured in the extension) <code>ISearchResultPage</code>
+ * will be used to display the search result.
+ *
*
* This API is preliminary and subject to change at any time.
*
@@ -18,15 +22,6 @@ import org.eclipse.ui.part.IPageBookViewPage;
*/
public interface ISearchResultPage extends IPageBookViewPage {
/**
- * Sets the search result to be shown in this search results page.
- *
- * @param search The search to be shown
- * @param uiState The previously saved UI state.
- * @return Returns the visual state for the previously shown search. May
- * return null if no view state can or should be saved.
- */
- void setInput(ISearchResult search, Object uiState);
- /**
* Returns an Object representing the current state of the page UI. For
* example, the current selection in a viewer. The UI state will be later
* passed into the <code>setInput()</code> method when the currently
@@ -36,7 +31,18 @@ public interface ISearchResultPage extends IPageBookViewPage {
*/
Object getUIState();
/**
- * Sets the search view this search results page is shown in.
+ * Sets the search result to be shown in this search results page. Implementers
+ * should restore UI state (e.g. selection) from the previously saved <code>uiState</code>
+ * object.
+ * @see ISearchResultPage#getUIState()
+ *
+ * @param search The search result to be shown
+ * @param uiState The previously saved UI state.
+ */
+ void setInput(ISearchResult search, Object uiState);
+ /**
+ * Sets the search view this search results page is shown in. This method will be called before the page is shown
+ * for the first time (i.e. before the page control is created).
*
* @param part The parent search view.
*/
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/NewSearchUI.java b/org.eclipse.search/new search/org/eclipse/search/ui/NewSearchUI.java
index f898b208bb7..6695bd6a1c2 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/NewSearchUI.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/NewSearchUI.java
@@ -8,6 +8,7 @@
******************************************************************************/
package org.eclipse.search.ui;
import org.eclipse.jface.operation.IRunnableContext;
+
import org.eclipse.search2.internal.ui.InternalSearchUI;
/**
* A facade for the new search ui. This API is preliminary and subject to
@@ -17,38 +18,63 @@ import org.eclipse.search2.internal.ui.InternalSearchUI;
*/
public class NewSearchUI {
/**
- * @return Returns the singleton search manager.
- */
- public static ISearchResultManager getSearchManager() {
- return InternalSearchUI.getInstance().getSearchManager();
- }
- /**
* Activates the search result view in the current perspective.
*/
public static void activateSearchResultView() {
InternalSearchUI.getInstance().activateSearchView();
}
+
/**
- * Runs the given search job and associates it with the given search
- * result. This method runs the query in the background.
+ * Runs the given search query. This method may run the given query in a separate thread
+ * if <code>ISearchQuery#canRunInBackground()</code> returns <code>true</code>.
+ * Running a query adds it to the set of known queries.
*
* @param query The query to execute.
- * @param search The search result the given query should fill.
*/
- public static void runSearchInBackground(ISearchQuery query, ISearchResult result) {
- InternalSearchUI.getInstance().runSearchInBackground(query, result);
+ public static void runQuery(ISearchQuery query) {
+ if (query.canRunInBackground())
+ InternalSearchUI.getInstance().runSearchInBackground(query);
+ else
+ InternalSearchUI.getInstance().runSearchInForeground(null, query);
}
+
/**
- * Runs the given search job and associates it with the given search
- * result. This method will execute the query in the same thread as the
- * caller. This method blocks until the query is finished.
+ * Runs the given search query. This method will execute the query in the same thread
+ * as the caller. This method blocks until the query is finished.
+ * Running a query adds it to the set of known queries.
*
* @param context The runnable context to run the query in.
* @param query The query to execute.
- * @param search The search result the given query should fill.
*/
- public static void runSearchInForeground(IRunnableContext context, ISearchQuery job, ISearchResult result) {
- InternalSearchUI.getInstance().runSearchInForeground(context, job,
- result);
+ public static void runQueryInForeground(IRunnableContext context, ISearchQuery query) {
+ InternalSearchUI.getInstance().runSearchInForeground(context, query);
+ }
+
+ /**
+ * Adds the given query listener. Does nothing when the listener is already
+ * present.
+ *
+ * @param l The listener to be added.
+ */
+ public static void addQueryListener(IQueryListener l) {
+ InternalSearchUI.getInstance().addQueryListener(l);
+ }
+ /**
+ * Removes the given query listener. Does nothing if the listener is
+ * not present.
+ *
+ * @param l The listener to be removed.
+ */
+ public static void removeQueryListener(IQueryListener l) {
+ InternalSearchUI.getInstance().removeQueryListener(l);
+ }
+
+ /**
+ * Returns all search results know to the search ui.
+ *
+ * @return All search result.
+ */
+ public static ISearchQuery[] getQueries() {
+ return InternalSearchUI.getInstance().getQueries();
}
}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/SearchResultEvent.java b/org.eclipse.search/new search/org/eclipse/search/ui/SearchResultEvent.java
index a152f8f9aa1..c43eac02c2e 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/SearchResultEvent.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/SearchResultEvent.java
@@ -24,7 +24,7 @@ public abstract class SearchResultEvent {
this(null);
}
/**
- * Get the <code>ISearhResult</code> that sent out this notfication.
+ * Gets the <code>ISearchResult</code> for this event.
*
* @return The source of this event.
*/
@@ -32,6 +32,7 @@ public abstract class SearchResultEvent {
return fSearchResult;
}
/**
+ * Sets the search result for this event.
* @param searchResult The searchResult to set.
*/
protected void setSearchResult(ISearchResult searchResult) {
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
index 12bdc14756c..bce8c4790da 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
@@ -8,13 +8,24 @@
******************************************************************************/
package org.eclipse.search.ui.text;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
import org.eclipse.core.resources.IFile;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
+
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.ISearchResultListener;
import org.eclipse.search.ui.SearchResultEvent;
@@ -23,20 +34,81 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
private List fListeners;
private static final Match[] EMPTY_ARRAY= new Match[0];
private MatchEvent fMatchEvent;
+
+ /**
+ * Constructor
+ */
protected AbstractTextSearchResult() {
fElementsToMatches= new HashMap();
fListeners= new ArrayList();
fMatchEvent= new MatchEvent(this);
}
+
+
+ /**
+ * Adds annotations to the given editor. The default implementation works for editors that
+ * implement <code>ITextEditor</code>.
+ * Subclasses may override this method.
+ * @param editor
+ * @param annotationToPositionMap A map containing annotations as keys and Positions as values.
+ * @see Annotation
+ * @see Position
+ */
+ public void addAnnotations(IEditorPart editor, Map annotationToPositionMap) {
+ if (!(editor instanceof ITextEditor))
+ return;
+ ITextEditor textEditor= (ITextEditor) editor;
+ IAnnotationModel model= textEditor.getDocumentProvider().getAnnotationModel(textEditor.getEditorInput());
+ if (model == null) {
+ return;
+ }
+ if (model instanceof IAnnotationModelExtension) {
+ IAnnotationModelExtension ame= (IAnnotationModelExtension) model;
+ ame.replaceAnnotations(new Annotation[0], annotationToPositionMap);
+ } else {
+ for (Iterator elements= annotationToPositionMap.keySet().iterator(); elements.hasNext();) {
+ Annotation element= (Annotation) elements.next();
+ Position p= (Position) annotationToPositionMap.get(element);
+ model.addAnnotation(element, p);
+ }
+ }
+ }
+
+ /**
+ * Removes annotations from the given editor. The default implementation works for editors that
+ * implement <code>ITextEditor</code>.
+ * Subclasses may override this method.
+ * @param editor
+ * @param annotions A set containing the annotations to be removed.
+ * @see Annotation
+ */
+ public void removeAnnotations(IEditorPart editor, Set annotations) {
+ if (!(editor instanceof ITextEditor))
+ return;
+ ITextEditor textEditor= (ITextEditor) editor;
+ IAnnotationModel model= textEditor.getDocumentProvider().getAnnotationModel(textEditor.getEditorInput());
+ if (model == null)
+ return;
+ if (model instanceof IAnnotationModelExtension) {
+ IAnnotationModelExtension ame= (IAnnotationModelExtension) model;
+ Annotation[] annotationArray= new Annotation[annotations.size()];
+ ame.replaceAnnotations((Annotation[]) annotations.toArray(annotationArray), Collections.EMPTY_MAP);
+ } else {
+ for (Iterator iter= annotations.iterator(); iter.hasNext();) {
+ Annotation element= (Annotation) iter.next();
+ model.removeAnnotation(element);
+ }
+ }
+ }
+
/**
* Returns an array with all matches reported against the given element.
*
* @see Match#getElement()
* @param element The element to report matches for.
- * @return All matches against this element or an empty array if none are
- * found.
+ * @return All matches reported for this element.
*/
- public final Match[] getMatches(Object element) {
+ public Match[] getMatches(Object element) {
synchronized (fElementsToMatches) {
return doGetMatches(element);
}
@@ -53,7 +125,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
*
* @param match The match to add.
*/
- public final void addMatch(Match match) {
+ public void addMatch(Match match) {
boolean hasAdded= false;
synchronized (fElementsToMatches) {
hasAdded= doAddMatch(match);
@@ -66,6 +138,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
fMatchEvent.setMatch(match);
return fMatchEvent;
}
+
private boolean doAddMatch(Match match) {
List matches= (List) fElementsToMatches.get(match.getElement());
if (matches == null) {
@@ -81,7 +154,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
/**
* Removes all matches from this search result.
*/
- public final void removeAll() {
+ public void removeAll() {
synchronized (fElementsToMatches) {
doRemoveAll();
}
@@ -129,6 +202,13 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
fListeners.remove(l);
}
}
+
+ /**
+ * Send the given <code>SearchResultEvent<code> to all registered search
+ * result listeners
+ * @see ISearchResultListener
+ * @param e The event to be sent.
+ */
protected void fireChange(SearchResultEvent e) {
HashSet copiedListeners= new HashSet();
synchronized (fListeners) {
@@ -172,14 +252,15 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
* Returns an array containing the set of all elements that matches are
* reported against in this search result.
*
- * @return The set of elements in this search result. This will not return
- * null.
+ * @return The set of elements in this search result.
*/
public Object[] getElements() {
synchronized (fElementsToMatches) {
return fElementsToMatches.keySet().toArray();
}
}
+
+
/**
* Returns an array with all matches contained in the given file. If the
* matches are not contained within an <code>IFile</code>, this method
@@ -190,17 +271,18 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
*/
public abstract Match[] findContainedMatches(IFile file);
/**
- * Returns the file the given element is associated with (usually the file
+ * Returns the file associated with the given element (usually the file
* the element is contained in). If the element is not associated with a
- * file, this method must return null.
+ * file, this method should return <code>null</code>.
*
* @param element An element associated with a match.
* @return The file associated with the element or null.
*/
public abstract IFile getFile(Object element);
/**
- * Determines whether a match is contained in the element shown in the
- * given editor.
+ * Determines whether a match should be displayed in the given editor.
+ * For example, if a match is reported in a file, This method should return
+ * <code>true</code>, if the given editor displays the file.
*
* @param match The match.
* @param editor The editor that possibly contains the matches element.
@@ -210,10 +292,14 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
/**
* Returns all matches that are contained in the element shown in the given
* editor.
+ * For example, if the editor shows a particular file, all matches in that file should
+ * be returned.
*
* @param editor The editor.
* @return All matches that are contained in the element that is shown in
* the given editor.
*/
public abstract Match[] findContainedMatches(IEditorPart editor);
+
+
}
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
index ec5ec70d455..be773d05a65 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java
@@ -5,6 +5,14 @@ import java.util.Set;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionManager;
@@ -14,7 +22,7 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.text.Position;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -24,14 +32,26 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.search.internal.ui.CopyToClipboardAction;
-import org.eclipse.search.internal.ui.SearchPluginImages;
+
+import org.eclipse.jface.text.Position;
+
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+
import org.eclipse.search.ui.IContextMenuConstants;
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.CopyToClipboardAction;
+import org.eclipse.search.internal.ui.SearchPluginImages;
+
import org.eclipse.search2.internal.ui.InternalSearchUI;
import org.eclipse.search2.internal.ui.SearchMessages;
import org.eclipse.search2.internal.ui.basic.views.INavigate;
@@ -43,18 +63,6 @@ import org.eclipse.search2.internal.ui.basic.views.SetLayoutAction;
import org.eclipse.search2.internal.ui.basic.views.ShowNextResultAction;
import org.eclipse.search2.internal.ui.basic.views.ShowPreviousResultAction;
import org.eclipse.search2.internal.ui.text.AnnotationManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.part.IPageSite;
-import org.eclipse.ui.part.Page;
public abstract class AbstractTextSearchViewPage extends Page implements ISearchResultPage {
private static final boolean INITIALLY_FLAT= false;
@@ -104,12 +112,15 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
/**
* Opens an editor on the given element and selects the given range
* of text.
- * @param object The object to show
- * @param offset The start offset of the selection
- * @param length The length of the selection
+ * The location of matches are automatically updated when a file is editor through the file buffer
+ * infrastructure (@see org.eclipse.core.filebuffers.ITextFileBufferManager). When a file buffer is
+ * saved, the current positions are written back to the match.
+ * @param match The match to show
+ * @param currentOffset The current start offset of the match
+ * @param currentLength The current length of the selection
* @throws PartInitException If an editor can't be opened.
*/
- protected abstract void showMatch(Object object, int offset, int length) throws PartInitException;
+ protected abstract void showMatch(Match match, int currentOffset, int currentLength) throws PartInitException;
/**
* This method is called whenever the set of matches for the given elements
* changes. This method is guaranteed to be called in the UI thread.
@@ -130,11 +141,17 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
protected abstract void clear();
/**
- * Sets up the given viewer. Implementers have to set up at least
+ * Configures the given viewer. Implementers have to set at least
+ * a content provider and a label provider.
+ * @param viewer The viewer to be configured
+ */
+ protected abstract void configureTreeViewer(AbstractTreeViewer viewer);
+ /**
+ * Configures the given viewer. Implementers have to set at least
* a content provider and a label provider.
- * @param viewer The viewer to be set up. Will be either a TreeViewer or a TableViewer.
+ * @param viewer The viewer to be configured
*/
- protected abstract void configureViewer(StructuredViewer viewer);
+ protected abstract void configureTableViewer(TableViewer viewer);
private static void createStandardGroups(IContributionManager menu) {
menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
@@ -150,7 +167,13 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
}
+
+ /**
+ * Fills the context menu for this page.
+ * Subclasses may override this method.
+ * @param tbm
+ */
protected void fillContextMenu(IMenuManager mgr) {
mgr.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fCopyToClipboardAction);
mgr.appendToGroup(IContextMenuConstants.GROUP_SHOW, fShowNextAction);
@@ -205,6 +228,8 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
/**
* Tells whether the page shows it's result as a tree or as a
* table.
+ * @see AbstractTextSearchViewPage#configureTreeViewer(AbstractTreeViewer);
+ * @see AbstractTextSearchViewPage#configureTableViewer(TableViewer);
* @return Whether the page shows a tree or a table.
*/
public boolean isFlatLayout() {
@@ -214,13 +239,18 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
private void createViewer(Composite parent, boolean flatMode) {
if (flatMode) {
- fViewer= new SearchResultsTableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ TableViewer viewer= new SearchResultsTableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ fViewer= viewer;
+ configureTableViewer(viewer);
} else {
- fViewer= new SearchResultsTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ TreeViewer viewer= new SearchResultsTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ fViewer= viewer;
+ configureTreeViewer(viewer);
}
- configureViewer(fViewer);
IToolBarManager tbm= getSite().getActionBars().getToolBarManager();
+ tbm.removeAll();
+ createStandardGroups(tbm);
fillToolbar(tbm);
tbm.update(false);
@@ -305,6 +335,10 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
return result;
}
+ /**
+ * Returns the viewer currently used in this page.
+ * @return The currently used viewer or <code>null</code> if none has been created yet.
+ */
protected StructuredViewer getViewer() {
return fViewer;
}
@@ -321,9 +355,9 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
public void run() throws Exception {
Position currentPosition= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
if (currentPosition != null) {
- showMatch(match.getElement(), currentPosition.getOffset(), currentPosition.getLength());
+ showMatch(match, currentPosition.getOffset(), currentPosition.getLength());
} else {
- showMatch(match.getElement(), match.getOffset(), match.getLength());
+ showMatch(match, match.getOffset(), match.getLength());
}
}
@@ -390,7 +424,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
/**
* Returns the currently selected match.
- * @return The selected match or null.
+ * @return The selected match or null if none are selected.
*/
public Match getCurrentMatch() {
Object element= getFirstSelectedElement();
@@ -422,13 +456,16 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch
*/
public void init(IPageSite pageSite) {
super.init(pageSite);
-
+
addLayoutMenu(pageSite.getActionBars().getMenuManager());
}
+ /**
+ * Fills the toolbar contribution for this page.
+ * Subclasses may override this method.
+ * @param tbm
+ */
protected void fillToolbar(IToolBarManager tbm) {
- tbm.removeAll();
- createStandardGroups(tbm);
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, fShowNextAction); //$NON-NLS-1$
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, fShowPreviousAction); //$NON-NLS-1$
tbm.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, fRemoveResultsAction); //$NON-NLS-1$
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/CancelSearchAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/CancelSearchAction.java
index 46b42bffe01..268ac2fea57 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/CancelSearchAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/CancelSearchAction.java
@@ -12,6 +12,8 @@ package org.eclipse.search2.internal.ui;
import org.eclipse.jface.action.Action;
+import org.eclipse.search.ui.ISearchResult;
+
import org.eclipse.search.internal.ui.SearchPluginImages;
public class CancelSearchAction extends Action {
@@ -26,6 +28,7 @@ public class CancelSearchAction extends Action {
}
public void run() {
- InternalSearchUI.getInstance().cancelSearch(fView.getCurrentSearchResult().getQuery());
+ ISearchResult result= fView.getCurrentSearchResult();
+ InternalSearchUI.getInstance().cancelSearch(result.getQuery());
}
}
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 545c33fecef..4b51a7598c8 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
@@ -20,9 +20,8 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
+import org.eclipse.search.ui.IQueryListener;
import org.eclipse.search.ui.ISearchQuery;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultManager;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.internal.ui.SearchPlugin;
@@ -36,11 +35,11 @@ public class InternalSearchUI {
private static InternalSearchUI plugin;
private HashMap fSearchJobs;
- private ISearchResultManager fSearchResultsManager;
+ private QueryManager fSearchResultsManager;
private PositionTracker fPositionTracker;
private HashSet fJobListeners;
- private static final String SEARCH_VIEW_ID= "org.eclipse.search.ui.views.SearchView"; //$NON-NLS-1$
+ public static final String SEARCH_VIEW_ID= "org.eclipse.search.ui.views.SearchView"; //$NON-NLS-1$
private class SearchJobRecord {
public ISearchQuery fQuery;
@@ -57,11 +56,9 @@ public class InternalSearchUI {
private class InternalSearchJob extends Job {
SearchJobRecord fSearchJobRecord;
- ISearchResult fResult;
- public InternalSearchJob(SearchJobRecord sjr, ISearchResult result) {
- super(sjr.fQuery.getName());
+ public InternalSearchJob(SearchJobRecord sjr) {
+ super(sjr.fQuery.getLabel());
fSearchJobRecord= sjr;
- fResult= result;
}
protected IStatus run(IProgressMonitor monitor) {
@@ -69,7 +66,7 @@ public class InternalSearchUI {
searchJobStarted(fSearchJobRecord);
IStatus status= null;
try{
- status= fSearchJobRecord.fQuery.run(monitor, fResult);
+ status= fSearchJobRecord.fQuery.run(monitor);
} finally {
searchJobFinished(fSearchJobRecord);
}
@@ -111,7 +108,7 @@ public class InternalSearchUI {
public InternalSearchUI() {
plugin= this;
fSearchJobs= new HashMap();
- fSearchResultsManager= new SearchResultsManager();
+ fSearchResultsManager= new QueryManager();
fPositionTracker= new PositionTracker();
fJobListeners= new HashSet();
}
@@ -129,64 +126,66 @@ public class InternalSearchUI {
return SearchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SEARCH_VIEW_ID);
}
- public boolean runSearchInBackground(ISearchQuery job, ISearchResult result) {
- Assert.isTrue(fSearchJobs.get(job) == null);
+ public boolean runSearchInBackground(ISearchQuery query) {
+ Assert.isTrue(fSearchJobs.get(query) == null);
- getSearchManager().addSearchResult(result);
+ getSearchManager().addQuery(query);
- if (isQueryRunning(job))
+ if (isQueryRunning(query))
return false;
- SearchJobRecord sjr= new SearchJobRecord(job, true);
- fSearchJobs.put(job, sjr);
- doRunSearchInBackground(sjr, result);
+ SearchJobRecord sjr= new SearchJobRecord(query, true);
+ fSearchJobs.put(query, sjr);
+ doRunSearchInBackground(sjr);
return true;
}
- boolean isQueryRunning(ISearchQuery job) {
- SearchJobRecord sjr= (SearchJobRecord) fSearchJobs.get(job);
+ public boolean isQueryRunning(ISearchQuery query) {
+ SearchJobRecord sjr= (SearchJobRecord) fSearchJobs.get(query);
return sjr != null && sjr.fIsRunning;
}
- public boolean runSearchInForeground(IRunnableContext context, final ISearchQuery job, ISearchResult result) {
- Assert.isTrue(fSearchJobs.get(job) == null);
- getSearchManager().addSearchResult(result);
- if (isQueryRunning(job))
+ public boolean runSearchInForeground(IRunnableContext context, final ISearchQuery query) {
+ Assert.isTrue(fSearchJobs.get(query) == null);
+ getSearchManager().addQuery(query);
+ if (isQueryRunning(query))
return false;
- SearchJobRecord sjr= new SearchJobRecord(job, false);
- fSearchJobs.put(job, sjr);
+ SearchJobRecord sjr= new SearchJobRecord(query, false);
+ fSearchJobs.put(query, sjr);
- doRunSearchInForeground(sjr, result, context);
+ doRunSearchInForeground(sjr, context);
return true;
}
- private void doRunSearchInBackground(SearchJobRecord jobRecord, ISearchResult result) {
+ private void doRunSearchInBackground(SearchJobRecord jobRecord) {
if (jobRecord.fJob == null) {
- jobRecord.fJob= new InternalSearchJob(jobRecord, result);
+ jobRecord.fJob= new InternalSearchJob(jobRecord);
jobRecord.fJob.setPriority(Job.BUILD);
}
jobRecord.fJob.schedule();
}
- public boolean runAgain(ISearchQuery job, ISearchResult result) {
+ public boolean runAgain(ISearchQuery job) {
final SearchJobRecord rec= (SearchJobRecord) fSearchJobs.get(job);
if (rec == null)
return false;
if (rec.fBackground) {
- doRunSearchInBackground(rec, result);
+ doRunSearchInBackground(rec);
} else {
ProgressMonitorDialog pmd= new ProgressMonitorDialog(getSearchView().getSite().getShell());
- doRunSearchInForeground(rec, result, pmd);
+ doRunSearchInForeground(rec, pmd);
}
return true;
}
- private void doRunSearchInForeground(final SearchJobRecord rec, final ISearchResult result, IRunnableContext context) {
+ private void doRunSearchInForeground(final SearchJobRecord rec, IRunnableContext context) {
+ if (context == null)
+ context= getContext();
try {
context.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
searchJobStarted(rec);
try {
- rec.fQuery.run(monitor, result);
+ rec.fQuery.run(monitor);
} finally {
searchJobFinished(rec);
}
@@ -200,6 +199,13 @@ public class InternalSearchUI {
}
}
+ /**
+ * @return
+ */
+ private IRunnableContext getContext() {
+ return new ProgressMonitorDialog(null);
+ }
+
public void shutdown() {
Iterator jobRecs= fSearchJobs.values().iterator();
while (jobRecs.hasNext()) {
@@ -239,11 +245,30 @@ public class InternalSearchUI {
}
}
- public ISearchResultManager getSearchManager() {
+ public QueryManager getSearchManager() {
return fSearchResultsManager;
}
public PositionTracker getPositionTracker() {
return fPositionTracker;
}
+
+ public void addQueryListener(IQueryListener l) {
+ getSearchManager().addQueryListener(l);
+ }
+ public ISearchQuery[] getQueries() {
+ return getSearchManager().getQueries();
+ }
+ public void removeQueryListener(IQueryListener l) {
+ getSearchManager().removeQueryListener(l);
+ }
+
+ public void removeQuery(ISearchQuery query) {
+ cancelSearch(query);
+ getSearchManager().removeQuery(query);
+ }
+
+ public void addQuery(ISearchQuery query) {
+ getSearchManager().addQuery(query);
+ }
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchResultsManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java
index d7315fc7808..426319f2928 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchResultsManager.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java
@@ -16,83 +16,82 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultManagerListener;
-import org.eclipse.search.ui.ISearchResultManager;
+import org.eclipse.search.ui.IQueryListener;
+import org.eclipse.search.ui.ISearchQuery;
-public class SearchResultsManager implements ISearchResultManager {
- private List fSearches;
+class QueryManager {
+ private List fQueries;
private List fListeners;
- public SearchResultsManager() {
+ public QueryManager() {
super();
// an ArrayList should be plenty fast enough (few searches).
- fSearches= new ArrayList();
+ fQueries= new ArrayList();
fListeners= new ArrayList();
}
- public synchronized ISearchResult[] getSearchResults() {
- ISearchResult[] result= new ISearchResult[fSearches.size()];
- return (ISearchResult[]) fSearches.toArray(result);
+ synchronized ISearchQuery[] getQueries() {
+ ISearchQuery[] result= new ISearchQuery[fQueries.size()];
+ return (ISearchQuery[]) fQueries.toArray(result);
}
- public void removeSearchResult(ISearchResult search) {
- synchronized (fSearches) {
- fSearches.remove(search);
+ void removeQuery(ISearchQuery query) {
+ synchronized (fQueries) {
+ fQueries.remove(query);
}
- fireRemoved(search);
+ fireRemoved(query);
}
- public void addSearchResult(ISearchResult search) {
- synchronized (fSearches) {
- if (fSearches.contains(search))
+ void addQuery(ISearchQuery query) {
+ synchronized (fQueries) {
+ if (fQueries.contains(query))
return;
- fSearches.add(search);
+ fQueries.add(query);
}
- fireAdded(search);
+ fireAdded(query);
}
- public void addSearchResultListener(ISearchResultManagerListener l) {
+ void addQueryListener(IQueryListener l) {
synchronized (fListeners) {
fListeners.add(l);
}
}
- public void removeSearchResultListener(ISearchResultManagerListener l) {
+ void removeQueryListener(IQueryListener l) {
synchronized (fListeners) {
fListeners.remove(l);
}
}
- void fireAdded(ISearchResult search) {
+ void fireAdded(ISearchQuery query) {
Set copiedListeners= new HashSet();
synchronized (fListeners) {
copiedListeners.addAll(fListeners);
}
Iterator listeners= copiedListeners.iterator();
while (listeners.hasNext()) {
- ISearchResultManagerListener l= (ISearchResultManagerListener) listeners.next();
- l.searchResultAdded(search);
+ IQueryListener l= (IQueryListener) listeners.next();
+ l.queryAdded(query);
}
}
- void fireRemoved(ISearchResult search) {
+ void fireRemoved(ISearchQuery query) {
Set copiedListeners= new HashSet();
synchronized (fListeners) {
copiedListeners.addAll(fListeners);
}
Iterator listeners= copiedListeners.iterator();
while (listeners.hasNext()) {
- ISearchResultManagerListener l= (ISearchResultManagerListener) listeners.next();
- l.searchResultRemoved(search);
+ IQueryListener l= (IQueryListener) listeners.next();
+ l.queryRemoved(query);
}
}
- public void removeAll() {
+ void removeAll() {
Set copiedSearches= new HashSet();
- synchronized (fSearches) {
- copiedSearches.addAll(fSearches);
- fSearches.clear();
+ synchronized (fQueries) {
+ copiedSearches.addAll(fQueries);
+ fQueries.clear();
Iterator iter= copiedSearches.iterator();
while (iter.hasNext()) {
- ISearchResult element= (ISearchResult) iter.next();
+ ISearchQuery element= (ISearchQuery) iter.next();
fireRemoved(element);
}
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchAgainAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchAgainAction.java
index f8cd0e7f6ae..024e63f8e3d 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchAgainAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchAgainAction.java
@@ -37,7 +37,7 @@ class SearchAgainAction extends Action {
final ISearchResult search= fView.getCurrentSearchResult();
if (search != null) {
InternalSearchUI.getInstance().cancelSearch(search.getQuery());
- InternalSearchUI.getInstance().runAgain(search.getQuery(), search);
+ InternalSearchUI.getInstance().runAgain(search.getQuery());
}
}
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
index 707b654d6c8..ebbc53239a4 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchDropDownAction.java
@@ -20,8 +20,8 @@ import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.internal.ui.SearchPluginImages;
@@ -56,15 +56,15 @@ class SearchDropDownAction extends Action implements IMenuCreator {
fMenu.dispose();
fMenu= new Menu(parent);
- ISearchResult[] searches= NewSearchUI.getSearchManager().getSearchResults();
+ ISearchQuery[] searches= InternalSearchUI.getInstance().getSearchManager().getQueries();
for (int i= 0; i < searches.length; i++) {
- ISearchResult search= searches[i];
- String label= search.getText();
+ ISearchResult search= searches[i].getSearchResult();
+ String label= search.getLabel();
String tooltip= search.getTooltip();
ImageDescriptor image= search.getImageDescriptor();
if (InternalSearchUI.getInstance().isQueryRunning(search.getQuery()))
label= label+ SearchMessages.getString("SearchDropDownAction.running.message"); //$NON-NLS-1$
- ShowSearchAction action= new ShowSearchAction(fSearchView, searches[i], label, image, tooltip );
+ ShowSearchAction action= new ShowSearchAction(fSearchView, search, label, image, tooltip );
if (searches[i].equals(currentSearch))
action.setChecked(true);
addActionToMenu(fMenu, action);
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 1fc9f054bbf..105e156a149 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,27 +2,19 @@ package org.eclipse.search2.internal.ui;
import java.util.HashMap;
+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.jface.action.Action;
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.ISearchQuery;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultListener;
-import org.eclipse.search.ui.ISearchResultManagerListener;
-import org.eclipse.search.ui.ISearchResultPage;
-import org.eclipse.search.ui.ISearchResultViewPart;
-import org.eclipse.search.ui.NewSearchUI;
-import org.eclipse.search.ui.SearchResultEvent;
-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.ui.IPropertyListener;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
@@ -34,6 +26,17 @@ import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
+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;
+
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
@@ -49,7 +52,7 @@ import org.eclipse.ui.part.PageBookView;
* @author Thomas Mäder
*
*/
-public class SearchView extends PageBookView implements ISearchResultViewPart, ISearchResultManagerListener, ISearchResultListener, ISearchQueryListener {
+public class SearchView extends PageBookView implements ISearchResultViewPart, IQueryListener, ISearchResultListener, ISearchQueryListener {
private HashMap fPartsToPages;
private HashMap fPagesToParts;
private HashMap fSearchViewStates;
@@ -120,20 +123,16 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
// do nothing
}
- /* (non-Javadoc)
+ /** (non-Javadoc)
* @see org.eclipse.search2.ui.ISearchResultsPage#getUIState()
*/
public Object getUIState() {
- // TODO Auto-generated method stub
+ // empty implementation
return null;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.IPageBookViewPage#init(org.eclipse.ui.part.IPageSite)
- */
public void init(IPageSite pageSite) {
- // TODO Auto-generated method stub
super.init(pageSite);
getSite().setSelectionProvider(null);
}
@@ -197,7 +196,8 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
ISearchResultPage currentPage= (ISearchResultPage) getCurrentPage();
Object uiState= currentPage.getUIState();
if (fCurrentSearch != null) {
- fSearchViewStates.put(fCurrentSearch, uiState);
+ if (uiState != null)
+ fSearchViewStates.put(fCurrentSearch, uiState);
fCurrentSearch.removeListener(this);
}
currentPage.setInput(null, null);
@@ -225,16 +225,19 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
private void updateTitle(ISearchResult search) {
String label= SearchMessages.getString("SearchView.title.search"); //$NON-NLS-1$
- label+= "(";
+
+ // TODO workaround for bug 53391
+ label+= "("; //$NON-NLS-1$
if (search != null) {
boolean queryRunning= InternalSearchUI.getInstance().isQueryRunning(search.getQuery());
fCancelAction.setEnabled(queryRunning);
if (queryRunning) {
label= label+SearchMessages.getString("SearchView.title.running"); //$NON-NLS-1$
}
- label= label+" "+search.getText(); //$NON-NLS-1$ //$NON-NLS-2$
+ label= label+" "+search.getLabel(); //$NON-NLS-1$ //$NON-NLS-2$
}
- label+= ")";
+ // TODO workaround for bug 53391
+ label+= ")"; //$NON-NLS-1$
setTitle(label);
}
@@ -256,7 +259,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
super.createPartControl(parent);
createActions();
initializeToolBar();
- NewSearchUI.getSearchManager().addSearchResultListener(this);
+ InternalSearchUI.getInstance().getSearchManager().addQueryListener(this);
}
private void initializeToolBar() {
@@ -269,33 +272,33 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I
private void createActions() {
fSearchesDropDownAction= new SearchDropDownAction(this);
- fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
+ fSearchesDropDownAction.setEnabled(InternalSearchUI.getInstance().getSearchManager().getQueries().length != 0);
fSearchAgainAction= new SearchAgainAction(this);
fCancelAction= new CancelSearchAction(this);
fCancelAction.setEnabled(false);
}
public void dispose() {
- NewSearchUI.getSearchManager().removeSearchResultListener(this);
+ InternalSearchUI.getInstance().getSearchManager().removeQueryListener(this);
if (fCurrentSearch != null)
fCurrentSearch.removeListener(this);
InternalSearchUI.getInstance().removeSearchQueryListener(this);
super.dispose();
}
- public void searchResultAdded(ISearchResult search) {
- showSearchResult(search);
- fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
+ public void queryAdded(ISearchQuery query) {
+ showSearchResult(query.getSearchResult());
+ fSearchesDropDownAction.setEnabled(InternalSearchUI.getInstance().getSearchManager().getQueries().length != 0);
}
- public void searchResultRemoved(ISearchResult search) {
- InternalSearchUI.getInstance().cancelSearch(search.getQuery());
- if (search.equals(fCurrentSearch)) {
+ public void queryRemoved(ISearchQuery query) {
+ InternalSearchUI.getInstance().cancelSearch(query);
+ if (query.getSearchResult().equals(fCurrentSearch)) {
showSearchResult(null);
partActivated(fDefaultPart);
}
- fSearchViewStates.remove(search);
- fSearchesDropDownAction.setEnabled(NewSearchUI.getSearchManager().getSearchResults().length != 0);
+ fSearchViewStates.remove(query.getSearchResult());
+ fSearchesDropDownAction.setEnabled(InternalSearchUI.getInstance().getSearchManager().getQueries().length != 0);
}
public void searchResultChanged(SearchResultEvent e) {
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchesAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchesAction.java
index c01f7e652d4..f0013a2b04f 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchesAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchesAction.java
@@ -15,9 +15,8 @@ import java.util.ArrayList;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultManager;
-import org.eclipse.search.ui.NewSearchUI;
/**
* Invoke the resource creation wizard selection Wizard.
@@ -68,17 +67,17 @@ class ShowSearchesAction extends Action {
}
public void run() {
- ISearchResultManager sm= NewSearchUI.getSearchManager();
- ISearchResult[] searches= sm.getSearchResults();
+ QueryManager sm= InternalSearchUI.getInstance().getSearchManager();
+ ISearchQuery[] queries= sm.getQueries();
ArrayList input= new ArrayList();
int i= 0;
- for (int j= 0; j < searches.length; j++) {
- ISearchResult search= searches[i];
- String label= searches[i].getText();
+ for (int j= 0; j < queries.length; j++) {
+ ISearchResult search= queries[i].getSearchResult();
+ String label= search.getLabel();
String tooltip= search.getTooltip();
ImageDescriptor image= search.getImageDescriptor();
- ShowSearchAction action= new ShowSearchAction(fSearchView, searches[i], label, image, tooltip );
+ ShowSearchAction action= new ShowSearchAction(fSearchView, search, label, image, tooltip );
input.add(action);
}
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
index 7960310fa86..91fd1e8f9dd 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManager.java
@@ -1,14 +1,10 @@
/*
- * Created on 13.11.2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
*/
+
package org.eclipse.search2.internal.ui.text;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -16,10 +12,10 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchPart;
@@ -37,21 +33,17 @@ import org.eclipse.search.ui.text.MatchEvent;
import org.eclipse.search.ui.text.RemoveAllEvent;
public class AnnotationManager implements ISearchResultListener, IPartListener {
-
private AbstractTextSearchResult fResult;
private Map fMatchesToAnnotations;
+ private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup();
private ITextEditor fEditor;
private IWorkbenchWindow fWindow;
- private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup();
-
private static HashMap fSearchResultMap;
private static AnnotationManager fgManager;
-
static {
fSearchResultMap= new HashMap();
fgManager= new AnnotationManager();
IWindowListener listener= new IWindowListener() {
-
public void windowActivated(IWorkbenchWindow window) {
switchedTo(window);
}
@@ -70,18 +62,18 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
};
PlatformUI.getWorkbench().addWindowListener(listener);
}
-
+
public static void searchResultActivated(IWorkbenchWindow window, AbstractTextSearchResult result) {
fSearchResultMap.put(window, result);
switchedTo(window);
}
-
+
public static void switchedTo(IWorkbenchWindow window) {
fgManager.setWindow(window);
AbstractTextSearchResult result= (AbstractTextSearchResult) fSearchResultMap.get(window);
fgManager.setSearchResult(result);
}
-
+
public AnnotationManager() {
fMatchesToAnnotations= new HashMap();
}
@@ -89,8 +81,8 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
public synchronized void setSearchResult(AbstractTextSearchResult result) {
if (result == fResult)
return;
- removeAnnotations();
if (fResult != null) {
+ removeAnnotations();
fResult.removeListener(this);
}
fResult= result;
@@ -99,45 +91,22 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
addAnnotations();
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.search2.ui.ISearchResultChangedListener#searchResultsChanged(org.eclipse.search2.ui.SearchResultEvent)
- */
+
public synchronized void searchResultChanged(SearchResultEvent e) {
if (e instanceof MatchEvent) {
MatchEvent me= (MatchEvent) e;
- if (fEditor != null && fResult.isShownInEditor(me.getMatch(), fEditor)) {
+ if (fEditor != null
+ && fResult.isShownInEditor(me.getMatch(), fEditor)) {
if (me.getKind() == MatchEvent.ADDED) {
- addAnnotation(fEditor, me.getMatch());
+ addAnnotations(fEditor, new Match[]{me.getMatch()});
} else {
- removeAnnotation(fEditor, me.getMatch());
+ removeAnnotations(fEditor, new Match[]{me.getMatch()});
}
}
} else if (e instanceof RemoveAllEvent)
removeAnnotations();
}
-
- private void addAnnotation(ITextEditor textEditor, Match match) {
- IAnnotationModel model= textEditor.getDocumentProvider().getAnnotationModel(textEditor.getEditorInput());
- if (model != null) {
- Annotation annotation= new Annotation(fAnnotationTypeLookup.getAnnotationType(SearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO), true, null);
- fMatchesToAnnotations.put(match, annotation);
- model.addAnnotation(annotation, new Position(match.getOffset(), match.getLength()));
- }
- }
-
- private void removeAnnotation(ITextEditor textEditor, Match match) {
- Annotation annotation= (Annotation) fMatchesToAnnotations.remove(match);
- if (annotation != null) {
- IAnnotationModel model= textEditor.getDocumentProvider().getAnnotationModel(textEditor.getEditorInput());
- if (model != null) {
- model.removeAnnotation(annotation);
- }
- }
-
- }
-
public synchronized void partActivated(IWorkbenchPart part) {
if (part instanceof ITextEditor && part != fEditor) {
removeAnnotations();
@@ -145,45 +114,36 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
addAnnotations();
}
}
-
+
private void addAnnotations() {
if (fEditor == null || fResult == null)
return;
Match[] matches= fResult.findContainedMatches(fEditor);
if (matches == null)
return;
- for (int i= 0; i < matches.length; i++) {
- addAnnotation(fEditor, matches[i]);
- }
+ addAnnotations(fEditor, matches);
}
private void removeAnnotations() {
ITextEditor editor= fEditor;
if (editor == null)
return;
- Set matches= new HashSet();
- matches.addAll(fMatchesToAnnotations.keySet());
- for (Iterator annotations= matches.iterator(); annotations.hasNext();) {
- removeAnnotation(editor, (Match) annotations.next());
- }
+ Set matchSet= fMatchesToAnnotations.keySet();
+ Match[] matches= new Match[matchSet.size()];
+ removeAnnotations(editor, (Match[]) matchSet.toArray(matches));
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
- */
+
public void partBroughtToTop(IWorkbenchPart part) {
partActivated(part);
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
- */
public void partClosed(IWorkbenchPart part) {
if (part == fEditor) {
removeAnnotations();
fEditor= null;
}
}
-
+
public void setWindow(IWorkbenchWindow window) {
if (fWindow != null)
fWindow.getPartService().removePartListener(AnnotationManager.this);
@@ -192,18 +152,34 @@ public class AnnotationManager implements ISearchResultListener, IPartListener {
partActivated(window.getActivePage().getActiveEditor());
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
- */
public void partDeactivated(IWorkbenchPart part) {
//partClosed(part);
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
- */
public void partOpened(IWorkbenchPart part) {
// ignore, will be handled by activate
}
-
+
+ private void addAnnotations(IEditorPart editor, Match[] matches) {
+ HashMap map= new HashMap(matches.length);
+ for (int i= 0; i < matches.length; i++) {
+ Annotation annotation= new Annotation(fAnnotationTypeLookup.getAnnotationType(SearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO), true, null);
+ fMatchesToAnnotations.put(matches[i], annotation);
+ map.put(annotation, new Position(matches[i].getOffset(), matches[i].getLength()));
+ }
+ fResult.addAnnotations(editor, map);
+ }
+
+ private void removeAnnotations(IEditorPart editor, Match[] matches) {
+ HashSet annotations= new HashSet(matches.length);
+ for (int i= 0; i < matches.length; i++) {
+ Annotation annotation= (Annotation) fMatchesToAnnotations.remove(matches[i]);
+ if (annotation != null) {
+ annotations.add(annotation);
+ }
+ }
+ fResult.removeAnnotations(editor, annotations);
+ }
+
+
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java
index 69bfba1244f..901c41b3251 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java
@@ -29,9 +29,10 @@ import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Position;
+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.ISearchResultManagerListener;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.SearchResultEvent;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
@@ -44,7 +45,7 @@ import org.eclipse.search.ui.text.RemoveAllEvent;
* @author Thomas Mäder
*
*/
-public class PositionTracker implements ISearchResultManagerListener, ISearchResultListener, IFileBufferListener {
+public class PositionTracker implements IQueryListener, ISearchResultListener, IFileBufferListener {
private Map fMatchesToPositions= new HashMap();
private Map fMatchesToSearchResults= new HashMap();
@@ -55,18 +56,19 @@ public class PositionTracker implements ISearchResultManagerListener, ISearchRes
}
public PositionTracker() {
- NewSearchUI.getSearchManager().addSearchResultListener(this);
+ NewSearchUI.addQueryListener(this);
FileBuffers.getTextFileBufferManager().addFileBufferListener(this);
}
// tracking search results --------------------------------------------------------------
- public void searchResultAdded(org.eclipse.search.ui.ISearchResult result) {
- if (result instanceof AbstractTextSearchResult) {
- result.addListener(this);
+ public void queryAdded(ISearchQuery query) {
+ if (query.getSearchResult() instanceof AbstractTextSearchResult) {
+ query.getSearchResult().addListener(this);
}
}
- public void searchResultRemoved(ISearchResult result) {
+ public void queryRemoved(ISearchQuery query) {
+ ISearchResult result= query.getSearchResult();
if (result instanceof AbstractTextSearchResult) {
untrackAll((AbstractTextSearchResult)result);
result.removeListener(this);
@@ -158,7 +160,7 @@ public class PositionTracker implements ISearchResultManagerListener, ISearchRes
}
public void dispose() {
- NewSearchUI.getSearchManager().removeSearchResultListener(this);
+ NewSearchUI.removeQueryListener(this);
FileBuffers.getTextFileBufferManager().removeFileBufferListener(this);
}
@@ -174,13 +176,14 @@ public class PositionTracker implements ISearchResultManagerListener, ISearchRes
IFile file= ws.getRoot().getFileForLocation(buffer.getLocation());
if (file == null)
file= ws.getRoot().getFile(buffer.getLocation());
- ISearchResult[] results= NewSearchUI.getSearchManager().getSearchResults();
- for (int i= 0; i < results.length; i++) {
- if (results[i] instanceof AbstractTextSearchResult) {
- Match[] matches= ((AbstractTextSearchResult)results[i]).findContainedMatches(file);
+ ISearchQuery[] queries= NewSearchUI.getQueries();
+ for (int i= 0; i < queries.length; i++) {
+ ISearchResult result= queries[i].getSearchResult();
+ if (result instanceof AbstractTextSearchResult) {
+ Match[] matches= ((AbstractTextSearchResult)result).findContainedMatches(file);
for (int j= 0; j < matches.length; j++) {
trackCount[0]++;
- trackPosition((AbstractTextSearchResult)results[i], (ITextFileBuffer) buffer, matches[j]);
+ trackPosition((AbstractTextSearchResult)result, (ITextFileBuffer) buffer, matches[j]);
}
}
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
index da6d28b5337..538ccd5bdda 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
@@ -62,7 +62,7 @@ public class SearchPluginImages {
public static final String IMG_LCL_SEARCH_HISTORY= NAME_PREFIX + "search_history.gif"; //$NON-NLS-1$
public static final String IMG_LCL_SEARCH_FLAT_LAYOUT= NAME_PREFIX + "flatLayout.gif"; //$NON-NLS-1$
public static final String IMG_LCL_SEARCH_HIERARCHICAL_LAYOUT= NAME_PREFIX + "hierarchicalLayout.gif"; //$NON-NLS-1$
- public static final String IMG_LCL_SEARCH_CANCEL= NAME_PREFIX + "stop_nav.gif"; //$NON-NLS-1$
+ public static final String IMG_LCL_SEARCH_CANCEL= NAME_PREFIX + "stop.gif"; //$NON-NLS-1$
public static final String IMG_VIEW_SEARCHRES= NAME_PREFIX + "searchres.gif"; //$NON-NLS-1$
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
index 336dc8860bb..bc6bbfdcee2 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java
@@ -18,10 +18,10 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
@@ -35,6 +35,7 @@ import org.eclipse.search.ui.IContextMenuConstants;
import org.eclipse.search.ui.ISearchResultViewPart;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.search.ui.text.Match;
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.internal.ui.SearchPlugin;
@@ -62,19 +63,21 @@ public class FileSearchPage extends AbstractTextSearchViewPage {
return getViewer();
}
- protected void configureViewer(StructuredViewer viewer) {
+ protected void configureTableViewer(TableViewer viewer) {
viewer.setLabelProvider(new DelegatingLabelProvider(this, new FileLabelProvider(FileLabelProvider.SHOW_LABEL)));
- if (viewer instanceof TreeViewer)
- viewer.setContentProvider(new FileTreeContentProvider((TreeViewer) viewer));
- else {
- viewer.setContentProvider(new FileTableContentProvider((TableViewer) viewer));
- setSortOrder(fCurrentSortAction);
- }
+ viewer.setContentProvider(new FileTableContentProvider(viewer));
+ setSortOrder(fCurrentSortAction);
+ fContentProvider= (FileContentProvider) viewer.getContentProvider();
+ }
+
+ protected void configureTreeViewer(AbstractTreeViewer viewer) {
+ viewer.setLabelProvider(new DelegatingLabelProvider(this, new FileLabelProvider(FileLabelProvider.SHOW_LABEL)));
+ viewer.setContentProvider(new FileTreeContentProvider(viewer));
fContentProvider= (FileContentProvider) viewer.getContentProvider();
}
- protected void showMatch(Object element, int offset, int length) throws PartInitException {
- IFile file= (IFile) element;
+ protected void showMatch(Match match, int offset, int length) throws PartInitException {
+ IFile file= (IFile) match.getElement();
IWorkbenchPage page= SearchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor= IDE.openEditor(page, file, false);
if (!(editor instanceof ITextEditor)) {
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
index b713a719680..ea22d39ffff 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java
@@ -36,6 +36,7 @@ public class FileSearchQuery implements ISearchQuery {
private String fSearchOptions;
private TextSearchScope fScope;
private String fName;
+ private FileSearchResult fResult;
public FileSearchQuery(TextSearchScope scope, String options, String searchString, String description) {
@@ -49,8 +50,8 @@ public class FileSearchQuery implements ISearchQuery {
return true;
}
- public IStatus run(final IProgressMonitor pm, ISearchResult result) {
- final AbstractTextSearchResult textResult= (AbstractTextSearchResult) result;
+ public IStatus run(final IProgressMonitor pm) {
+ final AbstractTextSearchResult textResult= (AbstractTextSearchResult) getSearchResult();
textResult.removeAll();
ITextSearchResultCollector collector= new ITextSearchResultCollector() {
public IProgressMonitor getProgressMonitor() {
@@ -78,7 +79,7 @@ public class FileSearchQuery implements ISearchQuery {
return new Status(IStatus.OK, SearchPlugin.getDefault().getDescriptor().getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
}
- public String getName() {
+ public String getLabel() {
return fName;
}
@@ -128,4 +129,14 @@ public class FileSearchQuery implements ISearchQuery {
new TextSearchEngine().search(SearchPlugin.getWorkspace(), scope, collector, new MatchLocator(fSearchString, fSearchOptions));
return new Status(IStatus.OK, SearchPlugin.getDefault().getDescriptor().getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
}
+
+ public boolean canRerun() {
+ return true;
+ }
+
+ public ISearchResult getSearchResult() {
+ if (fResult == null)
+ fResult= new FileSearchResult(this);
+ return fResult;
+ }
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java
index 33fa743c87c..b29d99b2c4c 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java
@@ -25,6 +25,8 @@ import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.Match;
+import org.eclipse.search.internal.ui.SearchPluginImages;
+
/**
* @author Thomas Mäder
@@ -41,16 +43,15 @@ public class FileSearchResult extends AbstractTextSearchResult {
fQuery= job;
}
public ImageDescriptor getImageDescriptor() {
- // TODO Auto-generated method stub
- return null;
+ return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN;
}
- public String getText() {
+ public String getLabel() {
if (getMatchCount() == 1)
return fQuery.getSingularLabel();
else return MessageFormat.format(fQuery.getPluralPattern(), new Object[] { new Integer(getMatchCount()) });
}
public String getTooltip() {
- return getText();
+ return getLabel();
}
public Match[] findContainedMatches(IFile file) {
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
index e2ca1f64197..b41b09b9626 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java
@@ -17,17 +17,17 @@ import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
/**
* @author Thomas Mäder
*
*/
public class FileTreeContentProvider extends FileContentProvider implements ITreeContentProvider {
- private TreeViewer fTreeViewer;
+ private AbstractTreeViewer fTreeViewer;
private Map fChildrenMap;
- FileTreeContentProvider(TreeViewer viewer) {
+ FileTreeContentProvider(AbstractTreeViewer viewer) {
fTreeViewer= viewer;
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
index 4221f42b792..1e261078a11 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
@@ -67,8 +67,8 @@ import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.search.ui.IReplacePage;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
-import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.ISearchResultViewEntry;
+import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.internal.core.text.TextSearchScope;
@@ -258,8 +258,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
scope.addExtensions(patternData.fileNamePatterns);
FileSearchQuery wsJob= new FileSearchQuery(scope, getSearchOptions(), patternData.textPattern, "Searching for "+patternData.textPattern);
- ISearchResult result= new FileSearchResult(wsJob);
- org.eclipse.search.ui.NewSearchUI.runSearchInBackground(wsJob, result);
+ NewSearchUI.runQuery(wsJob);
return true;
}

Back to the top