use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.
the class AnnotationManagerTest method testReplaceQuery.
@Test
public void testReplaceQuery() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
Object[] files = result.getElements();
NewSearchUI.runQueryInForeground(null, fQuery2);
try {
for (int i = 0; i < files.length; i++) {
IFile file = (IFile) files[i];
ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
int annotationCount = 0;
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
for (Iterator<Annotation> annotations = annotationModel.getAnnotationIterator(); annotations.hasNext(); ) {
Annotation annotation = annotations.next();
if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
Position p = annotationModel.getPosition(annotation);
String text = document.get(p.getOffset(), p.getLength());
assertTrue(text.equalsIgnoreCase(fQuery2.getSearchString()));
}
}
assertEquals(0, annotationCount);
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.
the class AnnotationManagerTest method testRemoveQuery.
@Test
public void testRemoveQuery() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
Object[] files = result.getElements();
InternalSearchUI.getInstance().removeQuery(fQuery1);
try {
for (int i = 0; i < files.length; i++) {
IFile file = (IFile) files[i];
ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
int annotationCount = 0;
for (Iterator<Annotation> annotations = annotationModel.getAnnotationIterator(); annotations.hasNext(); ) {
Annotation annotation = annotations.next();
if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
annotationCount++;
}
}
assertEquals(0, annotationCount);
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.
the class AnnotationManagerTest method testSwitchQuery.
@Test
public void testSwitchQuery() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
Object[] files = result.getElements();
NewSearchUI.runQueryInForeground(null, fQuery2);
SearchTestPlugin.getDefault().getSearchView().showSearchResult(result);
try {
for (int i = 0; i < files.length; i++) {
IFile file = (IFile) files[i];
ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
int annotationCount = 0;
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
for (Iterator<Annotation> annotations = annotationModel.getAnnotationIterator(); annotations.hasNext(); ) {
Annotation annotation = annotations.next();
if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
Position p = annotationModel.getPosition(annotation);
String text = document.get(p.getOffset(), p.getLength());
assertTrue(text.equalsIgnoreCase(fQuery1.getSearchString()));
}
}
assertEquals(0, annotationCount);
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.
the class FileLabelProvider method getColoredLabelWithCounts.
private StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
AbstractTextSearchResult result = fPage.getInput();
if (result == null)
return coloredName;
int matchCount = result.getMatchCount(element);
if (matchCount <= 1)
return coloredName;
String countInfo = Messages.format(SearchMessages.FileLabelProvider_count_format, Integer.valueOf(matchCount));
coloredName.append(' ').append(countInfo, StyledString.COUNTER_STYLER);
return coloredName;
}
use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.
the class FileSearchPage method getLabel.
@Override
public String getLabel() {
String label = super.getLabel();
StructuredViewer viewer = getViewer();
if (viewer instanceof TableViewer) {
TableViewer tv = (TableViewer) viewer;
AbstractTextSearchResult result = getInput();
if (result != null) {
int itemCount = ((IStructuredContentProvider) tv.getContentProvider()).getElements(getInput()).length;
if (showLineMatches()) {
int matchCount = getInput().getMatchCount();
if (itemCount < matchCount) {
return Messages.format(SearchMessages.FileSearchPage_limited_format_matches, new Object[] { label, Integer.valueOf(itemCount), Integer.valueOf(matchCount) });
}
} else {
int fileCount = getInput().getElements().length;
if (itemCount < fileCount) {
return Messages.format(SearchMessages.FileSearchPage_limited_format_files, new Object[] { label, Integer.valueOf(itemCount), Integer.valueOf(fileCount) });
}
}
}
}
return label;
}
Aggregations