1 19 20 package org.openide.loaders; 21 22 23 import org.openide.filesystems.FileObject; 24 import java.lang.reflect.*; 25 import java.util.*; 26 import javax.swing.event.ChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 29 import org.openide.util.Lookup; 30 31 36 public final class AddLoaderManuallyHid { 37 38 private AddLoaderManuallyHid() {} 39 40 41 public static void addRemoveLoader(DataLoader l, boolean add) throws Exception { 42 45 Class lpnClazz = Class.forName("org.netbeans.core.LoaderPoolNode"); 49 Field loadersF = lpnClazz.getDeclaredField("loaders"); 50 loadersF.setAccessible(true); 51 List loaders = (List)loadersF.get(null); 52 if (add) { 53 if (loaders.contains(l)) throw new IllegalArgumentException (); 54 loaders.add(0, l); 55 } else { 56 if (! loaders.contains(l)) throw new IllegalArgumentException (); 57 loaders.remove(l); 58 } 59 60 DataLoaderPool pool = DataLoaderPool.getDefault (); 61 if (add) { 62 l.addPropertyChangeListener((PropertyChangeListener )pool); 63 } else { 64 l.removePropertyChangeListener((PropertyChangeListener )pool); 65 } 66 Field loadersArrayF = lpnClazz.getDeclaredField("loadersArray"); 68 loadersArrayF.setAccessible(true); 69 loadersArrayF.set(null, null); 70 pool.fireChangeEvent(new ChangeEvent (pool)); 71 } 72 73 } 74 | Popular Tags |