Search in sources :

Example 36 with Match

use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.

the class EditorAnnotationManager method searchResultChanged.

@Override
public synchronized void searchResultChanged(SearchResultEvent e) {
    ISearchResult searchResult = e.getSearchResult();
    if (searchResult instanceof AbstractTextSearchResult) {
        AbstractTextSearchResult result = (AbstractTextSearchResult) searchResult;
        if (e instanceof MatchEvent) {
            MatchEvent me = (MatchEvent) e;
            Match[] matchesInEditor = getMatchesInEditor(me.getMatches(), result);
            if (matchesInEditor != null) {
                if (me.getKind() == MatchEvent.ADDED) {
                    addAnnotations(matchesInEditor);
                } else {
                    removeAnnotations(matchesInEditor);
                }
            }
        } else if (e instanceof RemoveAllEvent) {
            removeAnnotations(result);
        } else if (e instanceof FilterUpdateEvent) {
            Match[] matchesInEditor = getMatchesInEditor(((FilterUpdateEvent) e).getUpdatedMatches(), result);
            if (matchesInEditor != null) {
                removeAnnotations(matchesInEditor);
                addAnnotations(matchesInEditor);
            }
        }
    }
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) RemoveAllEvent(org.eclipse.search.ui.text.RemoveAllEvent) MatchEvent(org.eclipse.search.ui.text.MatchEvent) FilterUpdateEvent(org.eclipse.search.ui.text.FilterUpdateEvent) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Match(org.eclipse.search.ui.text.Match)

Example 37 with Match

use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.

the class EditorAnnotationManager method getMatchesInEditor.

private Match[] getMatchesInEditor(Match[] matches, AbstractTextSearchResult result) {
    IEditorMatchAdapter adapter = result.getEditorMatchAdapter();
    if (adapter == null) {
        return null;
    }
    // optimize the array-length == 1 case (most common)
    if (matches.length == 1) {
        return adapter.isShownInEditor(matches[0], fEditor) ? matches : null;
    }
    // lazy initialization
    ArrayList<Match> matchesInEditor = null;
    for (Match curr : matches) {
        if (adapter.isShownInEditor(curr, fEditor)) {
            if (matchesInEditor == null) {
                matchesInEditor = new ArrayList<>();
            }
            matchesInEditor.add(curr);
        }
    }
    if (matchesInEditor != null) {
        return matchesInEditor.toArray(new Match[matchesInEditor.size()]);
    }
    return null;
}
Also used : IEditorMatchAdapter(org.eclipse.search.ui.text.IEditorMatchAdapter) Match(org.eclipse.search.ui.text.Match)

Example 38 with Match

use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.

the class PositionTracker method searchResultChanged.

// tracking matches ---------------------------------------------------------------------
@Override
public void searchResultChanged(SearchResultEvent e) {
    if (e instanceof MatchEvent) {
        MatchEvent evt = (MatchEvent) e;
        Match[] matches = evt.getMatches();
        int kind = evt.getKind();
        AbstractTextSearchResult result = (AbstractTextSearchResult) e.getSearchResult();
        for (Match match : matches) {
            ITextFileBuffer fb = getTrackedFileBuffer(result, match.getElement());
            if (fb != null) {
                updateMatch(match, fb, kind, result);
            }
        }
    } else if (e instanceof RemoveAllEvent) {
        RemoveAllEvent evt = (RemoveAllEvent) e;
        ISearchResult result = evt.getSearchResult();
        untrackAll((AbstractTextSearchResult) result);
    }
}
Also used : RemoveAllEvent(org.eclipse.search.ui.text.RemoveAllEvent) ISearchResult(org.eclipse.search.ui.ISearchResult) MatchEvent(org.eclipse.search.ui.text.MatchEvent) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Match(org.eclipse.search.ui.text.Match)

Example 39 with Match

use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.

the class PositionTrackerTest method checkInsertInsideMatch.

private void checkInsertInsideMatch(FileSearchResult result, IFile file) throws PartInitException, BadLocationException {
    Match[] matches = result.getMatches(file);
    try {
        SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
        ITextFileBuffer fb = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
        IDocument doc = fb.getDocument();
        for (int i = 0; i < matches.length; i++) {
            Position currentPosition = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(matches[i]);
            assertNotNull(currentPosition);
            doc.replace(currentPosition.offset + 1, 0, "Test");
        }
        for (int i = 0; i < matches.length; i++) {
            Position currentPosition = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(matches[i]);
            assertNotNull(currentPosition);
            String text = doc.get(currentPosition.offset, currentPosition.length);
            StringBuilder buf = new StringBuilder();
            buf.append(text.charAt(0));
            buf.append(text.substring(5));
            assertEquals(buf.toString(), ((FileSearchQuery) result.getQuery()).getSearchString());
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : Position(org.eclipse.jface.text.Position) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Match(org.eclipse.search.ui.text.Match)

Example 40 with Match

use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.

the class SearchResultPageTest method testRemoveTreeMatches.

@Test
// checkElementDisplay(..) misses cases where one line contains multiple matches
@Ignore
public void testRemoveTreeMatches() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    ISearchResultViewPart view = NewSearchUI.getSearchResultView();
    FileSearchPage page = (FileSearchPage) view.getActivePage();
    page.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_TREE);
    AbstractTreeViewer viewer = (AbstractTreeViewer) page.getViewer();
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    // make sure all elements have items.
    viewer.expandAll();
    Object[] elements = result.getElements();
    // page.setUpdateTracing(true);
    for (int i = 0; i < elements.length; i++) {
        Match[] matches = result.getMatches(elements[i]);
        viewer.reveal(elements[i]);
        for (int j = 0; j < matches.length; j++) {
            checkElementDisplay(viewer, result, elements[i]);
            result.removeMatch(matches[j]);
            consumeEvents(page);
        }
    }
// page.setUpdateTracing(false);
}
Also used : ISearchResultViewPart(org.eclipse.search.ui.ISearchResultViewPart) FileSearchPage(org.eclipse.search.internal.ui.text.FileSearchPage) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Match(org.eclipse.search.ui.text.Match) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Match (org.eclipse.search.ui.text.Match)45 AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)19 Test (org.junit.Test)14 ISearchQuery (org.eclipse.search.ui.ISearchQuery)11 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)7 IFile (org.eclipse.core.resources.IFile)7 Position (org.eclipse.jface.text.Position)7 Annotation (org.eclipse.jface.text.source.Annotation)6 ArrayList (java.util.ArrayList)5 BadLocationException (org.eclipse.jface.text.BadLocationException)5 IDocument (org.eclipse.jface.text.IDocument)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)4 ISearchResult (org.eclipse.search.ui.ISearchResult)4 IResource (org.eclipse.core.resources.IResource)3 MatchEvent (org.eclipse.search.ui.text.MatchEvent)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2