1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.jface.preference.IPreferenceNode; 21 import org.eclipse.jface.viewers.ITreeContentProvider; 22 import org.eclipse.jface.viewers.TreeViewer; 23 import org.eclipse.jface.viewers.Viewer; 24 import org.eclipse.ui.dialogs.PatternFilter; 25 import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode; 26 27 34 public class PreferencePatternFilter extends PatternFilter { 35 36 41 private Map keywordCache = new HashMap (); 42 43 48 public PreferencePatternFilter() { 49 super(); 50 } 51 52 57 private String [] getKeywords(Object element) { 58 List keywordList = new ArrayList (); 59 if (element instanceof WorkbenchPreferenceExtensionNode) { 60 WorkbenchPreferenceExtensionNode workbenchNode = (WorkbenchPreferenceExtensionNode) element; 61 62 Collection keywordCollection = (Collection ) keywordCache 63 .get(element); 64 if (keywordCollection == null) { 65 keywordCollection = workbenchNode.getKeywordLabels(); 66 keywordCache.put(element, keywordCollection); 67 } 68 if (!keywordCollection.isEmpty()){ 69 Iterator keywords = keywordCollection.iterator(); 70 while (keywords.hasNext()) { 71 keywordList.add(keywords.next()); 72 } 73 } 74 } 75 return (String []) keywordList.toArray(new String [keywordList.size()]); 76 } 77 78 83 public boolean isElementSelectable(Object element) { 84 return element instanceof WorkbenchPreferenceExtensionNode; 85 } 86 87 90 public boolean isElementVisible(Viewer viewer, Object element) { 91 if (isLeafMatch(viewer, element)) { 94 return true; 95 } 96 97 ITreeContentProvider contentProvider = (ITreeContentProvider) ((TreeViewer) viewer) 98 .getContentProvider(); 99 IPreferenceNode node = (IPreferenceNode) element; 100 Object [] children = contentProvider.getChildren(node); 101 if (filter(viewer, element, children).length > 0) { 103 return true; 104 } 105 return false; 106 } 107 108 112 protected boolean isLeafMatch(Viewer viewer, Object element) { 113 IPreferenceNode node = (IPreferenceNode) element; 114 String text = node.getLabelText(); 115 116 if (wordMatches(text)) { 117 return true; 118 } 119 120 String [] keywords = getKeywords(node); 122 for (int i = 0; i < keywords.length; i++){ 123 if (wordMatches(keywords[i])) { 124 return true; 125 } 126 } 127 return false; 128 } 129 130 } 131 | Popular Tags |