1 19 package org.netbeans.modules.java.source; 20 21 import org.netbeans.api.java.source.JavaSourceTaskFactory; 22 import org.openide.util.Lookup; 23 import org.openide.util.LookupEvent; 24 import org.openide.util.LookupListener; 25 import org.openide.util.RequestProcessor; 26 27 31 public final class JavaSourceTaskFactoryManager { 32 33 private static JavaSourceTaskFactoryManager INSTANCE; 34 35 public static synchronized void register() { 36 INSTANCE = new JavaSourceTaskFactoryManager(); 37 } 38 39 private Lookup.Result<JavaSourceTaskFactory> factories; 40 41 42 private JavaSourceTaskFactoryManager() { 43 final RequestProcessor.Task updateTask = new RequestProcessor("JavaSourceTaskFactoryManager Worker", 1).create(new Runnable () { 44 public void run() { 45 update(); 46 } 47 }); 48 49 factories = Lookup.getDefault().lookupResult(JavaSourceTaskFactory.class); 50 factories.addLookupListener(new LookupListener() { 51 public void resultChanged(LookupEvent ev) { 52 updateTask.schedule(0); 53 } 54 }); 55 56 update(); 57 } 58 59 private void update() { 60 for (JavaSourceTaskFactory f : factories.allInstances()) { 61 ACCESSOR.fireChangeEvent(f); 62 } 63 } 64 65 public static interface Accessor { 66 public abstract void fireChangeEvent(JavaSourceTaskFactory f); 67 } 68 69 public static Accessor ACCESSOR; 70 71 } 72 | Popular Tags |