KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > core > text > TextSearchEngine


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.search.internal.core.text;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.MultiStatus;
17
18 import org.eclipse.jface.util.Assert;
19
20 import org.eclipse.search.ui.NewSearchUI;
21
22 import org.eclipse.search.internal.core.SearchScope;
23 import org.eclipse.search.internal.ui.Messages;
24 import org.eclipse.search.internal.ui.SearchMessages;
25
26 public class TextSearchEngine {
27         
28     public IStatus search(SearchScope scope, boolean visitDerived, ITextSearchResultCollector collector, MatchLocator matchLocator) {
29         Assert.isNotNull(scope);
30         Assert.isNotNull(collector);
31         Assert.isNotNull(matchLocator);
32         IProgressMonitor monitor= collector.getProgressMonitor();
33         
34         String JavaDoc message= SearchMessages.TextSearchEngine_statusMessage;
35         MultiStatus status= new MultiStatus(NewSearchUI.PLUGIN_ID, IStatus.OK, message, null);
36         
37         int amountOfWork= new AmountOfWorkCalculator(scope, status, visitDerived).process();
38         try {
39             monitor.beginTask("", amountOfWork); //$NON-NLS-1$
40
if (amountOfWork > 0) {
41                 Integer JavaDoc[] args= new Integer JavaDoc[] {new Integer JavaDoc(1), new Integer JavaDoc(amountOfWork)};
42                 monitor.setTaskName(Messages.format(SearchMessages.TextSearchEngine_scanning, args));
43             }
44             collector.aboutToStart();
45             TextSearchVisitor visitor= new TextSearchVisitor(matchLocator, scope, visitDerived, collector, status, amountOfWork);
46             visitor.process();
47         } catch (CoreException ex) {
48             status.add(ex.getStatus());
49         } finally {
50             monitor.done();
51             try {
52                 collector.done();
53             } catch (CoreException ex) {
54                 status.add(ex.getStatus());
55             }
56         }
57         return status;
58     }
59 }
60
Popular Tags