1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.swt.widgets.Table; 17 18 import org.eclipse.jface.viewers.IStructuredContentProvider; 19 import org.eclipse.jface.viewers.TableViewer; 20 21 public class JavaSearchTableContentProvider extends JavaSearchContentProvider implements IStructuredContentProvider { 22 public JavaSearchTableContentProvider(JavaSearchResultPage page) { 23 super(page); 24 } 25 public Object [] getElements(Object inputElement) { 26 if (inputElement instanceof JavaSearchResult) { 27 Set filteredElements= new HashSet (); 28 Object [] rawElements= ((JavaSearchResult)inputElement).getElements(); 29 int limit= getPage().getElementLimit().intValue(); 30 for (int i= 0; i < rawElements.length; i++) { 31 if (getPage().getDisplayedMatchCount(rawElements[i]) > 0) { 32 filteredElements.add(rawElements[i]); 33 if (limit != -1 && limit < filteredElements.size()) { 34 break; 35 } 36 } 37 } 38 return filteredElements.toArray(); 39 } 40 return EMPTY_ARR; 41 } 42 43 public void elementsChanged(Object [] updatedElements) { 44 if (getSearchResult() == null) 45 return; 46 47 int addCount= 0; 48 int removeCount= 0; 49 int addLimit= getAddLimit(); 50 51 TableViewer viewer= (TableViewer) getPage().getViewer(); 52 Set updated= new HashSet (); 53 Set added= new HashSet (); 54 Set removed= new HashSet (); 55 for (int i= 0; i < updatedElements.length; i++) { 56 if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) { 57 if (viewer.testFindItem(updatedElements[i]) != null) 58 updated.add(updatedElements[i]); 59 else { 60 if (addLimit > 0) { 61 added.add(updatedElements[i]); 62 addLimit--; 63 addCount++; 64 } 65 } 66 } else { 67 removed.add(updatedElements[i]); 68 removeCount++; 69 } 70 } 71 72 viewer.add(added.toArray()); 73 viewer.update(updated.toArray(), new String [] { SearchLabelProvider.PROPERTY_MATCH_COUNT }); 74 viewer.remove(removed.toArray()); 75 } 76 77 private int getAddLimit() { 78 int limit= getPage().getElementLimit().intValue(); 79 if (limit != -1) { 80 Table table= (Table) getPage().getViewer().getControl(); 81 int itemCount= table.getItemCount(); 82 if (itemCount >= limit) { 83 return 0; 84 } 85 return limit - itemCount; 86 } 87 return Integer.MAX_VALUE; 88 } 89 90 public void clear() { 91 getPage().getViewer().refresh(); 92 } 93 94 } 95 | Popular Tags |