KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > dependencies > DependencyExtentQuery


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.dependencies;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jdt.core.IPackageFragmentRoot;
20 import org.eclipse.jdt.core.JavaCore;
21 import org.eclipse.jdt.core.JavaModelException;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.search.ui.ISearchQuery;
24 import org.eclipse.search.ui.ISearchResult;
25 import org.eclipse.search.ui.text.AbstractTextSearchResult;
26
27
28 public class DependencyExtentQuery implements ISearchQuery {
29     
30     private ISearchResult fSearchResult;
31     private IProject fProject;
32     private String JavaDoc fImportID;
33     
34     public DependencyExtentQuery(IProject project, String JavaDoc importID) {
35         fProject = project;
36         fImportID = importID;
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
41      */

42     public IStatus run(IProgressMonitor monitor) {
43         final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult();
44         result.removeAll();
45         DependencyExtentOperation op = new DependencyExtentOperation(fProject, fImportID, result);
46         op.execute(monitor);
47         return Status.OK_STATUS;
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.search.ui.ISearchQuery#getLabel()
52      */

53     public String JavaDoc getLabel() {
54         return PDEUIMessages.DependencyExtentQuery_label + " " + fImportID; //$NON-NLS-1$
55
}
56
57     /* (non-Javadoc)
58      * @see org.eclipse.search.ui.ISearchQuery#canRerun()
59      */

60     public boolean canRerun() {
61         return true;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
66      */

67     public boolean canRunInBackground() {
68         return true;
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
73      */

74     public ISearchResult getSearchResult() {
75         if (fSearchResult == null)
76             fSearchResult = new DependencyExtentSearchResult(this);
77         return fSearchResult;
78     }
79     
80     public IPackageFragmentRoot[] getDirectRoots() {
81         ArrayList JavaDoc result = new ArrayList JavaDoc();
82         try {
83             IPackageFragmentRoot[] roots = JavaCore.create(fProject).getPackageFragmentRoots();
84             for (int i = 0; i < roots.length; i++) {
85                 if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE
86                         || (roots[i].isArchive() && !roots[i].isExternal())) {
87                     result.add(roots[i]);
88                 }
89             }
90         } catch (JavaModelException e) {
91         }
92         return (IPackageFragmentRoot[]) result
93                 .toArray(new IPackageFragmentRoot[result.size()]);
94     }
95
96 }
97
Popular Tags