public boolean canRunInBackground() {
return true;
}
public final IStatus run(IProgressMonitor monitor) {
final BeansSearchResult result = (BeansSearchResult) getSearchResult();
result.removeAll();
for (IModelElement element : scope.getModelElements()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
IModelElementVisitor visitor = new IModelElementVisitor() {
public boolean visit(IModelElement element,
IProgressMonitor monitor) {
if (doesMatch(element, compiledPattern, monitor)) {
int startLine;
int lines;
if (element instanceof ISourceModelElement) {
ISourceModelElement sourceElement =
(ISourceModelElement) element;
startLine = sourceElement.getElementStartLine();
lines = sourceElement.getElementEndLine()
- startLine + 1;
} else {
startLine = -1;
lines = -1;
}
Match match = new Match(element, Match.UNIT_LINE,
startLine, lines);
result.addMatch(match);
}
return true;
}
};
element.accept(visitor, monitor);
}
Object[] args = new Object[] { new Integer(result.getMatchCount()) };
String message = MessageUtils.format(
BeansSearchMessages.SearchQuery_status, args);
return new Status(IStatus.OK, BeansSearchPlugin.PLUGIN_ID, 0, message,
null);
}