1 19 20 package org.netbeans.modules.editor.mimelookup.impl; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.Collections ; 25 import java.util.List ; 26 import java.util.logging.Logger ; 27 import org.netbeans.spi.editor.mimelookup.InstanceProvider; 28 import org.openide.util.lookup.AbstractLookup; 29 import org.openide.util.lookup.InstanceContent; 30 31 35 public final class InstanceProviderLookup extends AbstractLookup { 36 37 private static final Logger LOG = Logger.getLogger(InstanceProvider.class.getName()); 38 39 private InstanceContent content; 40 private InstanceProvider instanceProvider; 41 42 private CompoundFolderChildren children; 43 private PCL listener = new PCL(); 44 45 private final String LOCK = new String ("InstanceProviderLookup.LOCK"); 47 48 public InstanceProviderLookup(String [] paths, InstanceProvider instanceProvider) { 49 this(paths, instanceProvider, new InstanceContent()); 50 } 51 52 private InstanceProviderLookup(String [] paths, InstanceProvider instanceProvider, InstanceContent content) { 53 super(content); 54 55 this.content = content; 56 this.instanceProvider = instanceProvider; 57 58 this.children = new CompoundFolderChildren(paths, true); 59 this.children.addPropertyChangeListener(listener); 60 61 rebuild(); 62 } 63 64 private void rebuild() { 65 List files = children.getChildren(); 66 Object instance = instanceProvider.createInstance(files); 67 content.set(Collections.singleton(instance), null); 68 } 69 70 private class PCL implements PropertyChangeListener { 71 public void propertyChange(PropertyChangeEvent evt) { 72 rebuild(); 73 } 74 } } 76 | Popular Tags |