Search in sources :

Example 6 with ISearchQuery

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

the class QueryManager method removeAll.

public void removeAll() {
    synchronized (this) {
        List<ISearchQuery> old = fQueries;
        fQueries = new LinkedList<>();
        Iterator<ISearchQuery> iter = old.iterator();
        while (iter.hasNext()) {
            ISearchQuery element = iter.next();
            fireRemoved(element);
        }
    }
}
Also used : ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 7 with ISearchQuery

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

the class SearchView method initializePageSwitcher.

private void initializePageSwitcher() {
    new PageSwitcher(this) {

        @Override
        public void activatePage(Object page) {
            ISearchResult searchResult = ((ISearchQuery) page).getSearchResult();
            InternalSearchUI.getInstance().showSearchResult(SearchView.this, searchResult, false);
        }

        @Override
        public ImageDescriptor getImageDescriptor(Object page) {
            ISearchResult searchResult = ((ISearchQuery) page).getSearchResult();
            return searchResult.getImageDescriptor();
        }

        @Override
        public String getName(Object page) {
            ISearchResult searchResult = ((ISearchQuery) page).getSearchResult();
            return searchResult.getLabel();
        }

        @Override
        public Object[] getPages() {
            return NewSearchUI.getQueries();
        }
    };
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) PageSwitcher(org.eclipse.ui.part.PageSwitcher) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 8 with ISearchQuery

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

the class QueryManagerTest method testQueryListener.

@Test
public void testQueryListener() {
    final boolean[] wasAdded = { false };
    final boolean[] wasRemoved = { false };
    IQueryListener l = new IQueryListener() {

        @Override
        public void queryAdded(ISearchQuery query) {
            wasAdded[0] = true;
        }

        @Override
        public void queryRemoved(ISearchQuery query) {
            wasRemoved[0] = true;
        }

        @Override
        public void queryStarting(ISearchQuery query) {
        // not interested
        }

        @Override
        public void queryFinished(ISearchQuery query) {
        // not interested
        }
    };
    NewSearchUI.addQueryListener(l);
    ISearchQuery query = new NullQuery();
    InternalSearchUI.getInstance().addQuery(query);
    assertTrue(wasAdded[0]);
    InternalSearchUI.getInstance().removeQuery(query);
    assertTrue(wasRemoved[0]);
    InternalSearchUI.getInstance().removeQueryListener(l);
    wasAdded[0] = false;
    wasRemoved[0] = false;
    InternalSearchUI.getInstance().addQuery(query);
    assertFalse(wasAdded[0]);
    InternalSearchUI.getInstance().removeQuery(query);
    assertFalse(wasRemoved[0]);
}
Also used : IQueryListener(org.eclipse.search.ui.IQueryListener) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Test(org.junit.Test)

Example 9 with ISearchQuery

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

the class TestSearchResult method testAddMatchDifferentStart.

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

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

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