KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > PluginSearchQuery


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.search;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.pde.core.ISourceObject;
17 import org.eclipse.pde.internal.core.search.PluginSearchInput;
18 import org.eclipse.search.ui.ISearchQuery;
19 import org.eclipse.search.ui.ISearchResult;
20 import org.eclipse.search.ui.text.AbstractTextSearchResult;
21 import org.eclipse.search.ui.text.Match;
22
23 public class PluginSearchQuery implements ISearchQuery {
24
25     private SearchResult fSearchResult;
26
27     private PluginSearchInput fSearchInput;
28
29     public PluginSearchQuery(PluginSearchInput input) {
30         fSearchInput = input;
31     }
32
33     /*
34      * (non-Javadoc)
35      *
36      * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
37      */

38     public IStatus run(IProgressMonitor monitor) {
39         final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult();
40         result.removeAll();
41         ISearchResultCollector collector = new ISearchResultCollector() {
42             public void accept(Object JavaDoc match) {
43                 if (match instanceof ISourceObject) {
44                     ISourceObject object = (ISourceObject) match;
45                     result.addMatch(new Match(match, Match.UNIT_LINE,
46                             object.getStartLine() - 1, 1));
47                 }
48             }
49         };
50         PluginSearchOperation op = new PluginSearchOperation(fSearchInput, collector);
51         op.execute(monitor);
52         monitor.done();
53         return Status.OK_STATUS;
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.eclipse.search.ui.ISearchQuery#getLabel()
60      */

61     public String JavaDoc getLabel() {
62         return fSearchInput.getSearchString();
63     }
64     
65
66     /*
67      * (non-Javadoc)
68      *
69      * @see org.eclipse.search.ui.ISearchQuery#canRerun()
70      */

71     public boolean canRerun() {
72         return true;
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
79      */

80     public boolean canRunInBackground() {
81         return true;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
88      */

89     public ISearchResult getSearchResult() {
90         if (fSearchResult == null)
91             fSearchResult = new SearchResult(this);
92         return fSearchResult;
93     }
94
95 }
96
Popular Tags