Search in sources :

Example 1 with MatchEvent

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

the class TestSearchResult method testMatchEvent.

@Test
public void testMatchEvent() {
    final boolean[] wasAdded = { false };
    final boolean[] wasRemoved = { false };
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    result.addListener(new ISearchResultListener() {

        @Override
        public void searchResultChanged(SearchResultEvent e) {
            if (e instanceof MatchEvent) {
                MatchEvent evt = (MatchEvent) e;
                if (evt.getKind() == MatchEvent.ADDED) {
                    wasAdded[0] = true;
                } else {
                    wasRemoved[0] = true;
                }
            }
        }
    });
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatch(match1);
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.addMatch(match1);
    assertFalse(wasAdded[0]);
    Match match2 = new Match(object, 0, 0);
    result.addMatch(match2);
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.removeMatch(match2);
    assertTrue(wasRemoved[0]);
    wasRemoved[0] = false;
    result.removeMatch(match2);
    assertFalse(wasRemoved[0]);
}
Also used : SearchResultEvent(org.eclipse.search.ui.SearchResultEvent) MatchEvent(org.eclipse.search.ui.text.MatchEvent) ISearchResultListener(org.eclipse.search.ui.ISearchResultListener) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 2 with MatchEvent

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

the class TestSearchResult method testBatchedMatchEvent.

@Test
public void testBatchedMatchEvent() {
    final boolean[] wasAdded = { false };
    final boolean[] wasRemoved = { false };
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    result.addListener(new ISearchResultListener() {

        @Override
        public void searchResultChanged(SearchResultEvent e) {
            if (e instanceof MatchEvent) {
                MatchEvent evt = (MatchEvent) e;
                if (evt.getKind() == MatchEvent.ADDED) {
                    wasAdded[0] = true;
                } else {
                    wasRemoved[0] = true;
                }
            }
        }
    });
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatches(new Match[] { match1 });
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.addMatches(new Match[] { match1 });
    assertFalse(wasAdded[0]);
    Match match2 = new Match(object, 0, 0);
    result.addMatches(new Match[] { match2 });
    assertTrue(wasAdded[0]);
    wasAdded[0] = false;
    result.removeMatches(new Match[] { match2 });
    assertTrue(wasRemoved[0]);
    wasRemoved[0] = false;
    result.removeMatches(new Match[] { match2 });
    assertFalse(wasRemoved[0]);
}
Also used : SearchResultEvent(org.eclipse.search.ui.SearchResultEvent) MatchEvent(org.eclipse.search.ui.text.MatchEvent) ISearchResultListener(org.eclipse.search.ui.ISearchResultListener) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match) Test(org.junit.Test)

Example 3 with MatchEvent

use of org.eclipse.search.ui.text.MatchEvent 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 4 with MatchEvent

use of org.eclipse.search.ui.text.MatchEvent 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)

Aggregations

AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)4 Match (org.eclipse.search.ui.text.Match)4 MatchEvent (org.eclipse.search.ui.text.MatchEvent)4 ISearchQuery (org.eclipse.search.ui.ISearchQuery)2 ISearchResult (org.eclipse.search.ui.ISearchResult)2 ISearchResultListener (org.eclipse.search.ui.ISearchResultListener)2 SearchResultEvent (org.eclipse.search.ui.SearchResultEvent)2 RemoveAllEvent (org.eclipse.search.ui.text.RemoveAllEvent)2 Test (org.junit.Test)2 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 FilterUpdateEvent (org.eclipse.search.ui.text.FilterUpdateEvent)1