1 19 20 package org.netbeans.modules.navigator; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.StringTokenizer ; 31 import java.util.logging.Logger ; 32 import org.netbeans.spi.navigator.NavigatorPanel; 33 import org.openide.ErrorManager; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileSystem; 36 import org.openide.filesystems.Repository; 37 import org.openide.loaders.DataFolder; 38 import org.openide.loaders.DataObject; 39 import org.openide.loaders.FolderLookup; 40 import org.openide.util.Lookup; 41 42 48 class ProviderRegistry { 49 50 51 private static final String PANELS_FOLDER = "/Navigator/Panels/"; 53 private static final Lookup.Template<NavigatorPanel> NAV_PANEL_TEMPLATE = 54 new Lookup.Template<NavigatorPanel>(NavigatorPanel.class); 55 56 57 private static ProviderRegistry instance; 58 59 64 private Map <String , Collection <? extends NavigatorPanel>> contentTypes2Providers; 65 66 67 68 private ProviderRegistry () { 69 } 70 71 72 73 public static ProviderRegistry getInstance () { 74 if (instance == null ) { 75 instance = new ProviderRegistry(); 76 } 77 return instance; 78 } 79 80 87 public Collection <? extends NavigatorPanel> getProviders (String contentType) { 88 if (contentTypes2Providers == null) { 89 contentTypes2Providers = new HashMap <String , Collection <? extends NavigatorPanel>>(15); 90 } 91 Collection <? extends NavigatorPanel> result = contentTypes2Providers.get(contentType); 92 if (result == null) { 93 result = loadProviders(contentType); 95 contentTypes2Providers.put(contentType, result); 96 } 97 98 return result; 99 } 100 101 102 103 104 107 private Collection <? extends NavigatorPanel> loadProviders (String contentType) { 108 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 109 FileObject fo = fs.findResource(PANELS_FOLDER + contentType); 110 111 if (fo == null) { 112 Logger.getAnonymousLogger().fine("No providers for content type " + contentType); return Collections.emptyList(); 115 } 116 117 DataFolder.Container dContainer; 118 try { 119 dContainer = DataFolder.findContainer(fo); 120 } catch (IllegalArgumentException exc) { 121 ErrorManager.getDefault().annotate(exc, 122 "Navigator content type " + contentType + 123 " is probably malformed, as it doesn't point to folder."); 124 ErrorManager.getDefault().notify(ErrorManager.WARNING, exc); 125 return Collections.emptyList(); 126 } 127 128 FolderLookup fLookup = new FolderLookup(dContainer, ""); 129 Lookup.Result<NavigatorPanel> result = fLookup.getLookup().lookup(NAV_PANEL_TEMPLATE); 130 131 return result.allInstances(); 132 } 133 134 } 135 | Popular Tags |