KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > nls > search > NLSSearchOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.refactoring.nls.search;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 import org.eclipse.core.resources.IWorkspace;
17
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.IMethod;
20 import org.eclipse.jdt.core.search.IJavaSearchConstants;
21 import org.eclipse.jdt.core.search.IJavaSearchScope;
22 import org.eclipse.jdt.core.search.SearchEngine;
23
24 import org.eclipse.jface.resource.ImageDescriptor;
25
26 import org.eclipse.ui.actions.WorkspaceModifyOperation;
27
28 import org.eclipse.jdt.internal.ui.JavaPluginImages;
29 import org.eclipse.jdt.internal.ui.search.PrettySignature;
30
31 /** @deprecated */
32 class NLSSearchOperation extends WorkspaceModifyOperation {
33     
34     private IWorkspace fWorkspace;
35     private IJavaElement fElementPattern;
36     private int fLimitTo;
37     /** @deprecated TODO: remove dead code */
38     private String JavaDoc fStringPattern;
39     private int fSearchFor;
40     private IJavaSearchScope fScope;
41     private String JavaDoc fScopeDescription;
42     private NLSSearchResultCollector fCollector;
43     
44     protected NLSSearchOperation(
45                 IWorkspace workspace,
46                 int limitTo,
47                 IJavaSearchScope scope,
48                 String JavaDoc scopeDescription,
49                 NLSSearchResultCollector collector) {
50         super(null);
51         fWorkspace= workspace;
52         fLimitTo= limitTo;
53         fScope= scope;
54         fScopeDescription= scopeDescription;
55         fCollector= collector;
56         fCollector.setOperation(this);
57     }
58     
59     public NLSSearchOperation(
60                 IWorkspace workspace,
61                 IJavaElement pattern,
62                 int limitTo,
63                 IJavaSearchScope scope,
64                 String JavaDoc scopeDescription,
65                 NLSSearchResultCollector collector) {
66         this(workspace, limitTo, scope, scopeDescription, collector);
67         fElementPattern= pattern;
68     }
69     
70     /** @deprecated TODO: remove dead code */
71     public NLSSearchOperation(
72                 IWorkspace workspace,
73                 String JavaDoc pattern,
74                 int searchFor,
75                 int limitTo,
76                 IJavaSearchScope scope,
77                 String JavaDoc scopeDescription,
78                 NLSSearchResultCollector collector) {
79         this(workspace, limitTo, scope, scopeDescription, collector);
80         fStringPattern= pattern; /** @deprecated TODO: remove dead code */
81         fSearchFor= searchFor;
82     }
83
84     protected void execute(IProgressMonitor monitor) throws CoreException {
85         fCollector.setProgressMonitor(monitor);
86         SearchEngine engine= new SearchEngine();
87         if (fElementPattern != null)
88             engine.search(fWorkspace, fElementPattern, fLimitTo, fScope, fCollector);
89         else /** @deprecated TODO: remove dead code */
90             engine.search(fWorkspace, fStringPattern, fSearchFor, fLimitTo, fScope, fCollector);
91     }
92
93     String JavaDoc getSingularLabel() {
94         String JavaDoc[] args= new String JavaDoc[] {getDescriptionPattern(), fScopeDescription}; //$NON-NLS-1$
95
return NLSSearchMessages.getFormattedString("SearchOperation.singularLabelPostfix", args); //$NON-NLS-1$
96
}
97
98     String JavaDoc getPluralLabelPattern() {
99         String JavaDoc[] args= new String JavaDoc[] {getDescriptionPattern(), "{0}", fScopeDescription}; //$NON-NLS-1$
100
return NLSSearchMessages.getFormattedString("SearchOperation.pluralLabelPatternPostfix", args); //$NON-NLS-1$
101
}
102     
103     private String JavaDoc getDescriptionPattern() {
104         if (fElementPattern != null) {
105             if (fLimitTo == IJavaSearchConstants.REFERENCES
106             && fElementPattern.getElementType() == IJavaElement.METHOD)
107                 return PrettySignature.getUnqualifiedMethodSignature((IMethod)fElementPattern); /** @deprecated TODO: remove dead code */
108             else
109                 return fElementPattern.getElementName();
110         }
111         else /** @deprecated TODO: remove dead code */
112             return fStringPattern;
113     }
114     
115     ImageDescriptor getImageDescriptor() {
116         return JavaPluginImages.DESC_OBJS_SEARCH_REF;
117     }
118 }
119
Popular Tags