1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.refactoring.nls.search;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.resources.IFile;
19 import org.eclipse.search.ui.ISearchQuery;
20 import org.eclipse.search.ui.ISearchResult;
22 import org.eclipse.jdt.core.Flags;
23 import org.eclipse.jdt.core.IField;
24 import org.eclipse.jdt.core.IJavaElement;
25 import org.eclipse.jdt.core.JavaModelException;
26 import org.eclipse.jdt.core.search.IJavaSearchScope;
28 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSRefactoring;
29 import org.eclipse.jdt.internal.corext.util.Messages;
31 import org.eclipse.jdt.ui.JavaElementLabels;
34 public class NLSSearchQuery implements ISearchQuery {
36 NLSSearchResult fResult;
37 IJavaElement[] fWrapperClass;
38 IFile[] fPropertiesFile;
39 IJavaSearchScope fScope;
40 private String fScopeDescription;
42 public NLSSearchQuery(IJavaElement[] wrapperClass, IFile[] propertiesFile, IJavaSearchScope scope, String scopeDescription) {
43 fWrapperClass= wrapperClass;
44 fPropertiesFile= propertiesFile;
46 fScopeDescription= scopeDescription;
50 * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
52 public IStatus run(IProgressMonitor monitor) {
53 monitor.beginTask("", 5 * fWrapperClass.length); //$NON-NLS-1$
55 return fResult.generated_2736082692135152007(this, monitor);
58 boolean isNLSField(IField field) throws JavaModelException {
59 int flags= field.getFlags();
60 if (!Flags.isPublic(flags))
63 if (!Flags.isStatic(flags))
66 String fieldName= field.getElementName();
67 if (NLSRefactoring.BUNDLE_NAME_FIELD.equals(fieldName))
70 if ("RESOURCE_BUNDLE".equals(fieldName)) //$NON-NLS-1$
77 * @see org.eclipse.search.ui.ISearchQuery#getLabel()
79 public String getLabel() {
80 return NLSSearchMessages.NLSSearchQuery_label;
83 public String getResultLabel(int nMatches) {
84 if (fWrapperClass.length == 1) {
86 String[] args= new String[] {JavaElementLabels.getElementLabel(fWrapperClass[0], JavaElementLabels.ALL_DEFAULT), fScopeDescription};
87 return Messages.format(NLSSearchMessages.SearchOperation_singularLabelPostfix, args);
89 String[] args= new String[] {JavaElementLabels.getElementLabel(fWrapperClass[0], JavaElementLabels.ALL_DEFAULT), String.valueOf(nMatches), fScopeDescription};
90 return Messages.format(NLSSearchMessages.SearchOperation_pluralLabelPatternPostfix, args);
93 return Messages.format(NLSSearchMessages.NLSSearchQuery_oneProblemInScope_description, fScopeDescription);
95 return Messages.format(NLSSearchMessages.NLSSearchQuery_xProblemsInScope_description, new Object[] {String.valueOf(nMatches), fScopeDescription});
100 * @see org.eclipse.search.ui.ISearchQuery#canRerun()
102 public boolean canRerun() {
107 * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
109 public boolean canRunInBackground() {
114 * @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
116 public ISearchResult getSearchResult() {
118 fResult= new NLSSearchResult(this);