List of usage examples for org.eclipse.jface.viewers StructuredViewer testFindItem
public Widget testFindItem(Object element)
From source file:net.sourceforge.tagsea.core.ui.internal.views.CachingTreePatternFilter.java
License:Open Source License
/** * Check if the current (leaf) element is a match with the filter text. * The default behavior checks that the label of the element is a match. * // w w w. j a va 2 s. c om * Subclasses should override this method. * * @param viewer the viewer that contains the element * @param element the tree element to check * @return true if the given element's label matches the filter text */ public boolean isLeafMatch(Viewer viewer, Object element) { if (element == viewer.getInput()) return false; if (!(viewer instanceof StructuredViewer)) return false; StructuredViewer sv = (StructuredViewer) viewer; String labelText = null; Widget widget = sv.testFindItem(element); if (widget instanceof Item) { labelText = ((Item) widget).getText(); } if (labelText == null) { if (!(sv.getLabelProvider() instanceof ILabelProvider)) return false; ILabelProvider labelProvider = (ILabelProvider) sv.getLabelProvider(); labelText = labelProvider.getText(element); } if (labelText == null) { return false; } //check all words. String[] fullText = labelText.split("\\."); boolean match = false; for (int i = 0; i < fullText.length; i++) { match = wordMatches(fullText[i]); if (match) return match; } return match; }
From source file:org.eclipse.search.tests.filesearch.SearchResultPageTest.java
License:Open Source License
private void checkElementDisplay(StructuredViewer viewer, AbstractTextSearchResult result, Object element) { Widget widget = viewer.testFindItem(element); assertTrue(widget instanceof Item); Item item = (Item) widget;//from w ww .java2s .c o m int itemCount = result.getMatchCount(element); assertTrue(itemCount > 0); if (itemCount > 1) assertTrue(item.getText().indexOf(String.valueOf(itemCount)) >= 0); }
From source file:org.key_project.util.eclipse.swt.SWTUtil.java
License:Open Source License
/** * Invokes {@link StructuredViewer#testFindItem(Object)} thread save. * @param viewer The {@link StructuredViewer} to invoke method on. * @param element The element to test.// w ww.j ava2 s . com * @return The found {@link Item} or {@code null} if not available. */ public static Object testFindItem(final StructuredViewer viewer, final Object element) { IRunnableWithResult<Object> run = new AbstractRunnableWithResult<Object>() { @Override public void run() { setResult(viewer.testFindItem(element)); } }; viewer.getControl().getDisplay().syncExec(run); return run.getResult(); }
From source file:v9t9.gui.client.swt.shells.DemoSelector.java
License:Open Source License
/** * @param viewer/*from ww w.j a va 2s. c om*/ * @param control * @param realModules */ protected void addIterativeSearch(final StructuredViewer viewer, Control control) { control.addKeyListener(new KeyAdapter() { StringBuilder search = new StringBuilder(); int index = 0; IDemo[] demos; @Override public void keyPressed(KeyEvent e) { int direction = 1; if (demos == null) { demos = demoManager.getDemos(); } if (e.keyCode == '\b') { search.setLength(0); index = 0; e.doit = e.keyCode != '\b'; demos = demoManager.getDemos(); } else if (e.keyCode == SWT.ARROW_DOWN) { direction = 1; e.doit = false; } else if (e.keyCode == SWT.ARROW_UP) { direction = -1; e.doit = false; } else if (e.character >= 32 && e.character < 127) { search.append(e.character); e.doit = false; } else { return; } int end = (index + demos.length - 1) % demos.length; String searchString = search.toString().toLowerCase(); if (searchString.length() > 0) { for (int i = index; i != end; i = (i + 1) % demos.length) { IDemo m = demos[i]; if (m.getName().toLowerCase().contains(searchString)) { viewer.setSelection(new StructuredSelection(m), true); viewer.reveal(m); index = i; break; } } } else { int count = demos.length; if (getDisplay().getFocusControl() != filterText) { // not yet in tree index += direction; } do { index = (index + demos.length) % demos.length; IDemo m = demos[index]; viewer.setSelection(new StructuredSelection(m), true); viewer.reveal(m); if (viewer.testFindItem(m) != null) // TODO: cleaner way to see what's not filtered break; index += direction; } while (count-- > 0); } } }); }