1 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 32 class NLSSearchOperation extends WorkspaceModifyOperation { 33 34 private IWorkspace fWorkspace; 35 private IJavaElement fElementPattern; 36 private int fLimitTo; 37 38 private String fStringPattern; 39 private int fSearchFor; 40 private IJavaSearchScope fScope; 41 private String fScopeDescription; 42 private NLSSearchResultCollector fCollector; 43 44 protected NLSSearchOperation( 45 IWorkspace workspace, 46 int limitTo, 47 IJavaSearchScope scope, 48 String 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 scopeDescription, 65 NLSSearchResultCollector collector) { 66 this(workspace, limitTo, scope, scopeDescription, collector); 67 fElementPattern= pattern; 68 } 69 70 71 public NLSSearchOperation( 72 IWorkspace workspace, 73 String pattern, 74 int searchFor, 75 int limitTo, 76 IJavaSearchScope scope, 77 String scopeDescription, 78 NLSSearchResultCollector collector) { 79 this(workspace, limitTo, scope, scopeDescription, collector); 80 fStringPattern= pattern; 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 90 engine.search(fWorkspace, fStringPattern, fSearchFor, fLimitTo, fScope, fCollector); 91 } 92 93 String getSingularLabel() { 94 String [] args= new String [] {getDescriptionPattern(), fScopeDescription}; return NLSSearchMessages.getFormattedString("SearchOperation.singularLabelPostfix", args); } 97 98 String getPluralLabelPattern() { 99 String [] args= new String [] {getDescriptionPattern(), "{0}", fScopeDescription}; return NLSSearchMessages.getFormattedString("SearchOperation.pluralLabelPatternPostfix", args); } 102 103 private String getDescriptionPattern() { 104 if (fElementPattern != null) { 105 if (fLimitTo == IJavaSearchConstants.REFERENCES 106 && fElementPattern.getElementType() == IJavaElement.METHOD) 107 return PrettySignature.getUnqualifiedMethodSignature((IMethod)fElementPattern); 108 else 109 return fElementPattern.getElementName(); 110 } 111 else 112 return fStringPattern; 113 } 114 115 ImageDescriptor getImageDescriptor() { 116 return JavaPluginImages.DESC_OBJS_SEARCH_REF; 117 } 118 } 119 | Popular Tags |