1 11 package org.eclipse.ui.internal; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.ui.IActionFilter; 18 import org.eclipse.ui.internal.util.Util; 19 20 24 public class ObjectFilterTest { 25 private HashMap filterElements; 26 27 30 public ObjectFilterTest() { 31 } 33 34 39 public boolean addFilterElement(IConfigurationElement element) { 40 String name = element.getAttribute("name"); if (name == null) { 42 return false; 43 } 44 45 String value = element.getAttribute("value"); if (value == null) { 48 return false; 49 } 50 if (filterElements == null) { 51 filterElements = new HashMap (); 52 } 53 filterElements.put(name, value); 54 return true; 55 } 56 57 70 public boolean matches(Object object, boolean adaptable) { 71 if (filterElements == null) { 73 return true; 74 } 75 76 if (this.preciselyMatches(object)) { 78 return true; 79 } 80 return false; 81 } 82 83 86 private boolean preciselyMatches(Object object) { 87 IActionFilter filter = (IActionFilter)Util.getAdapter(object, IActionFilter.class); 89 if (filter == null) { 90 return false; 91 } 92 93 Iterator iter = filterElements.keySet().iterator(); 95 while (iter.hasNext()) { 96 String name = (String ) iter.next(); 97 String value = (String ) filterElements.get(name); 98 if (!filter.testAttribute(object, name, value)) { 99 return false; 100 } 101 } 102 return true; 103 } 104 } 105 106 | Popular Tags |