Search in sources :

Example 21 with ISearchQuery

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

the class TestSearchResult method testAddMatchOrderPreserving.

@Test
public void testAddMatchOrderPreserving() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 1, 0);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    Match match2 = new Match(object, 1, 0);
    result.addMatch(match2);
    Match[] matches = result.getMatches(object);
    assertTrue("matches[0]", matches[0] == match1);
    assertTrue("matches[1]", matches[1] == match2);
}
Also used : 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 22 with ISearchQuery

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

the class TestSearchResult method testAddMatchDifferentLength.

@Test
public void testAddMatchDifferentLength() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 1, 1);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    Match match2 = new Match(object, 1, 0);
    result.addMatch(match2);
    Match[] matches = result.getMatches(object);
    assertTrue("matches[0]", matches[0] == match2);
    assertTrue("matches[1]", matches[1] == match1);
}
Also used : 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 23 with ISearchQuery

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

the class TestSearchResult method testRemoveMatches.

@Test
public void testRemoveMatches() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    Match match2 = new Match(object, 0, 0);
    result.addMatches(new Match[] { match1, match2 });
    assertEquals(result.getMatchCount(), 2);
    result.removeMatches(new Match[] { match1, match2 });
    assertEquals(result.getMatchCount(), 0);
}
Also used : 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 24 with ISearchQuery

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

the class TestSearchResult method testAddMatch.

@Test
public void testAddMatch() {
    ISearchQuery query = new NullQuery();
    AbstractTextSearchResult result = (AbstractTextSearchResult) query.getSearchResult();
    // $NON-NLS-1$
    String object = "object";
    Match match1 = new Match(object, 0, 0);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 1);
    Match match2 = new Match(object, 0, 0);
    result.addMatch(match2);
    assertEquals(result.getMatchCount(), 2);
    result.addMatch(match1);
    assertEquals(result.getMatchCount(), 2);
}
Also used : 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 25 with ISearchQuery

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

the class AbstractTextSearchViewPage method createQueryListener.

private IQueryListener createQueryListener() {
    return new IQueryListener() {

        @Override
        public void queryAdded(ISearchQuery query) {
        // ignore
        }

        @Override
        public void queryRemoved(ISearchQuery query) {
        // ignore
        }

        @Override
        public void queryStarting(final ISearchQuery query) {
            final Runnable runnable1 = new Runnable() {

                @Override
                public void run() {
                    updateBusyLabel();
                    AbstractTextSearchResult result = getInput();
                    if (result == null || !result.getQuery().equals(query)) {
                        return;
                    }
                    turnOffDecoration();
                    scheduleUIUpdate();
                }
            };
            asyncExec(runnable1);
        }

        @Override
        public void queryFinished(final ISearchQuery query) {
            // handle the end of the query in the UIUpdateJob, as ui updates
            // may not be finished here.
            postEnsureSelection();
        }
    };
}
Also used : IQueryListener(org.eclipse.search.ui.IQueryListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Aggregations

ISearchQuery (org.eclipse.search.ui.ISearchQuery)30 Test (org.junit.Test)13 AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)11 Match (org.eclipse.search.ui.text.Match)11 ISearchResult (org.eclipse.search.ui.ISearchResult)6 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 IStatus (org.eclipse.core.runtime.IStatus)2 IQueryListener (org.eclipse.search.ui.IQueryListener)2 ISearchResultListener (org.eclipse.search.ui.ISearchResultListener)2 SearchResultEvent (org.eclipse.search.ui.SearchResultEvent)2 MatchEvent (org.eclipse.search.ui.text.MatchEvent)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1