01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.search;
11:
12: import org.eclipse.core.runtime.IProgressMonitor;
13: import org.eclipse.core.runtime.IStatus;
14: import org.eclipse.core.runtime.Status;
15: import org.eclipse.pde.core.ISourceObject;
16: import org.eclipse.pde.internal.core.search.PluginSearchInput;
17: import org.eclipse.search.ui.ISearchQuery;
18: import org.eclipse.search.ui.ISearchResult;
19: import org.eclipse.search.ui.text.AbstractTextSearchResult;
20: import org.eclipse.search.ui.text.Match;
21:
22: public class PluginSearchQuery implements ISearchQuery {
23:
24: private SearchResult fSearchResult;
25:
26: private PluginSearchInput fSearchInput;
27:
28: public PluginSearchQuery(PluginSearchInput input) {
29: fSearchInput = input;
30: }
31:
32: /*
33: * (non-Javadoc)
34: *
35: * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
36: */
37: public IStatus run(IProgressMonitor monitor) {
38: final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult();
39: result.removeAll();
40: ISearchResultCollector collector = new ISearchResultCollector() {
41: public void accept(Object match) {
42: if (match instanceof ISourceObject) {
43: ISourceObject object = (ISourceObject) match;
44: result.addMatch(new Match(match, Match.UNIT_LINE,
45: object.getStartLine() - 1, 1));
46: }
47: }
48: };
49: PluginSearchOperation op = new PluginSearchOperation(
50: 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 getLabel() {
62: return fSearchInput.getSearchString();
63: }
64:
65: /*
66: * (non-Javadoc)
67: *
68: * @see org.eclipse.search.ui.ISearchQuery#canRerun()
69: */
70: public boolean canRerun() {
71: return true;
72: }
73:
74: /*
75: * (non-Javadoc)
76: *
77: * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
78: */
79: public boolean canRunInBackground() {
80: return true;
81: }
82:
83: /*
84: * (non-Javadoc)
85: *
86: * @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
87: */
88: public ISearchResult getSearchResult() {
89: if (fSearchResult == null)
90: fSearchResult = new SearchResult(this);
91: return fSearchResult;
92: }
93:
94: }
|