Search in sources :

Example 21 with AbstractTextSearchResult

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) Test(org.junit.Test)

Example 22 with AbstractTextSearchResult

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) Test(org.junit.Test)

Example 23 with AbstractTextSearchResult

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) Test(org.junit.Test)

Example 24 with AbstractTextSearchResult

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;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult)

Example 25 with AbstractTextSearchResult

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;
}
Also used : StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult)

Aggregations

AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)35 Test (org.junit.Test)20 Match (org.eclipse.search.ui.text.Match)19 ISearchQuery (org.eclipse.search.ui.ISearchQuery)11 IFile (org.eclipse.core.resources.IFile)6 Position (org.eclipse.jface.text.Position)6 Annotation (org.eclipse.jface.text.source.Annotation)5 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 IDocument (org.eclipse.jface.text.IDocument)4 ISearchResult (org.eclipse.search.ui.ISearchResult)4 MatchEvent (org.eclipse.search.ui.text.MatchEvent)4 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)2 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)2 ISearchResultListener (org.eclipse.search.ui.ISearchResultListener)2 SearchResultEvent (org.eclipse.search.ui.SearchResultEvent)2