KickJava   Java API By Example, From Geeks To Geeks.

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


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.MultiStatus;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IResourceProxy;
18 import org.eclipse.core.resources.IResourceProxyVisitor;
19
20 import org.eclipse.search.internal.core.SearchScope;
21
22 /**
23  * The visitor that does the actual work.
24  */

25 public class AmountOfWorkCalculator implements IResourceProxyVisitor {
26     
27     private SearchScope fScope;
28     private int fFileCount;
29     private boolean fVisitDerived;
30     private final MultiStatus fStatus;
31
32     AmountOfWorkCalculator(SearchScope scope, MultiStatus status, boolean visitDerived) {
33         fStatus= status;
34         fScope= scope;
35         fVisitDerived= visitDerived;
36     }
37         
38     public boolean visit(IResourceProxy proxy) {
39         if (proxy.getType() != IResource.FILE) {
40             return true;
41         }
42         
43         if ((fVisitDerived || !proxy.isDerived()) && fScope.matchesFileName(proxy.getName())) {
44             fFileCount++;
45         }
46         return true;
47     }
48     
49     public int process() {
50         fFileCount= 0;
51         IResource[] roots= fScope.getRootElements();
52         for (int i= 0; i < roots.length; i++) {
53             try {
54                 roots[i].accept(this, 0);
55             } catch (CoreException ex) {
56                 fStatus.add(ex.getStatus());
57             }
58         }
59         return fFileCount;
60     }
61 }
62
Popular Tags