use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class SortingTest method testSorted.
@Test
public void testSorted() throws Exception {
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInForeground(null, fQuery1);
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
int originalMatchCount = result.getMatchCount();
List<Match> allMatches = new ArrayList<>(originalMatchCount);
// first, collect all matches
Object[] elements = result.getElements();
for (int i = 0; i < elements.length; i++) {
Match[] matches = result.getMatches(elements[i]);
for (int j = 0; j < matches.length; j++) {
allMatches.add(matches[j]);
}
}
// now remove them and readd them in reverse order
result.removeAll();
assertTrue("removed all matches", result.getMatchCount() == 0);
for (int i = allMatches.size() - 1; i >= 0; i--) {
result.addMatch(allMatches.get(i));
}
assertEquals("Test that all matches have been added again", result.getMatchCount(), originalMatchCount);
// now check that they're ordered by position.
for (int i = 0; i < elements.length; i++) {
Match[] matches = result.getMatches(elements[i]);
assertTrue("has matches", matches.length > 0);
for (int j = 1; j < matches.length; j++) {
assertTrue("order problem", isLessOrEqual(matches[j - 1], matches[j]));
}
}
}
use of org.eclipse.search.ui.text.Match 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);
}
use of org.eclipse.search.ui.text.Match 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]);
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class TestSearchResult method testRemoveMatch.
@Test
public void testRemoveMatch() {
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);
Match match2 = new Match(object, 0, 0);
result.addMatch(match2);
assertEquals(result.getMatchCount(), 2);
result.removeMatch(match1);
assertEquals(result.getMatchCount(), 1);
result.removeMatch(match1);
assertEquals(result.getMatchCount(), 1);
}
use of org.eclipse.search.ui.text.Match in project titan.EclipsePlug-ins by eclipse.
the class LogSearchResultPage method configureTreeViewer.
@Override
protected void configureTreeViewer(final TreeViewer viewer) {
treeViewer = viewer;
contentProvider = new TreeContentProvider(this);
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new SearchLabelProvider());
viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
try {
Object selectedElement = ((TreeSelection) event.getSelection()).getFirstElement();
if (selectedElement instanceof Match) {
showMatch((Match) selectedElement, 0, 0, true);
return;
}
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new TechnicalException("Could not show the selected match. Reason: " + e.getMessage()));
}
}
});
}
Aggregations