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.dependencies;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.core.resources.IProject;
15: import org.eclipse.core.runtime.IProgressMonitor;
16: import org.eclipse.core.runtime.IStatus;
17: import org.eclipse.core.runtime.Status;
18: import org.eclipse.jdt.core.IPackageFragmentRoot;
19: import org.eclipse.jdt.core.JavaCore;
20: import org.eclipse.jdt.core.JavaModelException;
21: import org.eclipse.pde.internal.ui.PDEUIMessages;
22: import org.eclipse.search.ui.ISearchQuery;
23: import org.eclipse.search.ui.ISearchResult;
24: import org.eclipse.search.ui.text.AbstractTextSearchResult;
25:
26: public class DependencyExtentQuery implements ISearchQuery {
27:
28: private ISearchResult fSearchResult;
29: private IProject fProject;
30: private String fImportID;
31:
32: public DependencyExtentQuery(IProject project, String importID) {
33: fProject = project;
34: fImportID = importID;
35: }
36:
37: /* (non-Javadoc)
38: * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
39: */
40: public IStatus run(IProgressMonitor monitor) {
41: final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult();
42: result.removeAll();
43: DependencyExtentOperation op = new DependencyExtentOperation(
44: fProject, fImportID, result);
45: op.execute(monitor);
46: return Status.OK_STATUS;
47: }
48:
49: /* (non-Javadoc)
50: * @see org.eclipse.search.ui.ISearchQuery#getLabel()
51: */
52: public String getLabel() {
53: return PDEUIMessages.DependencyExtentQuery_label
54: + " " + 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 result = new ArrayList();
82: try {
83: IPackageFragmentRoot[] roots = JavaCore.create(fProject)
84: .getPackageFragmentRoots();
85: for (int i = 0; i < roots.length; i++) {
86: if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE
87: || (roots[i].isArchive() && !roots[i]
88: .isExternal())) {
89: result.add(roots[i]);
90: }
91: }
92: } catch (JavaModelException e) {
93: }
94: return (IPackageFragmentRoot[]) result
95: .toArray(new IPackageFragmentRoot[result.size()]);
96: }
97:
98: }
|