1 19 20 21 package org.openidex.search; 22 23 import java.util.Collections ; 24 import java.util.Enumeration ; 25 26 import org.openide.ServiceType; 27 import org.openide.nodes.Node; 28 import org.openide.util.Lookup; 29 30 31 39 public abstract class SearchType extends ServiceType implements Cloneable { 40 41 static final long serialVersionUID = 1L; 43 44 45 public static final String PROP_VALID = "valid"; 47 48 protected static final String PROP_OBJECT_CHANGED = "org.openidex.search.objectChanged"; 50 51 private boolean valid; 52 53 54 55 private Class [] searchTypeClasses; 56 57 58 64 public synchronized final Class [] getSearchTypeClasses() { 65 if (searchTypeClasses == null) { 66 searchTypeClasses = createSearchTypeClasses(); 67 } 68 return searchTypeClasses; 69 } 70 71 75 protected abstract Class [] createSearchTypeClasses(); 76 77 78 83 protected Node[] acceptSearchRootNodes(Node[] roots) { 84 return roots; 85 } 86 87 95 protected boolean acceptSearchObject(Object searchObject) { 96 return true; 97 } 98 99 102 protected void prepareSearchObject(Object searchObject) {} 103 104 112 protected abstract boolean testObject(Object searchObject); 113 114 123 public Node[] getDetails(Object resultObject) { 124 return null; 125 } 126 127 140 public Node[] getDetails(Node node) { 141 return null; 142 } 143 144 155 public abstract boolean enabled(Node[] nodes); 156 157 158 public final void setValid(boolean state) { 159 boolean old = valid; 160 valid = state; 161 firePropertyChange(PROP_VALID, old ? Boolean.TRUE : Boolean.FALSE, state ? Boolean.TRUE : Boolean.FALSE); 162 } 163 164 165 public final boolean isValid() { 166 return valid; 167 } 168 169 170 public Object clone() { 171 try { 172 return super.clone(); 173 } catch (CloneNotSupportedException ex) { 174 throw new RuntimeException ("SearchType must be cloneable."); } 176 } 177 178 179 185 public static Enumeration enumerateSearchTypes () { 186 return Collections.enumeration(Lookup.getDefault().lookup(new Lookup.Template(SearchType.class)).allInstances()); 187 } 188 189 } 190 | Popular Tags |