1 11 12 package org.eclipse.ui.internal.intro.impl.model.loader; 13 14 import java.util.Enumeration ; 15 import java.util.Hashtable ; 16 import java.util.Iterator ; 17 18 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; 19 import org.eclipse.ui.internal.intro.impl.model.IntroContentProvider; 20 import org.eclipse.ui.internal.intro.impl.util.Log; 21 import org.eclipse.ui.intro.config.IIntroContentProvider; 22 import org.eclipse.ui.intro.config.IIntroContentProviderSite; 23 24 41 42 public class ContentProviderManager { 43 44 private static ContentProviderManager inst = new ContentProviderManager(); 46 47 48 private Hashtable contentProviders = new Hashtable (); 53 54 55 class ContentProviderWrapper { 56 57 IIntroContentProvider provider; 58 AbstractIntroPage parentPage; 59 60 ContentProviderWrapper(IIntroContentProvider provider, AbstractIntroPage parentPage) { 61 this.provider = provider; 62 this.parentPage = parentPage; 63 } 64 65 IIntroContentProvider getIIntroContentProvider() { 66 return provider; 67 } 68 69 AbstractIntroPage getParentPage() { 70 return parentPage; 71 } 72 } 73 74 75 76 79 protected ContentProviderManager() { 80 } 82 83 86 public static ContentProviderManager getInst() { 87 return inst; 88 } 89 90 96 public IIntroContentProvider getContentProvider(IntroContentProvider provider) { 97 ContentProviderWrapper providerWrapper = (ContentProviderWrapper) contentProviders.get(provider 99 .getId()); 100 if (providerWrapper == null) 101 return null; 103 IIntroContentProvider providerClass = providerWrapper.getIIntroContentProvider(); 104 return providerClass; 105 } 106 107 115 public IIntroContentProvider createContentProvider(IntroContentProvider provider, 116 IIntroContentProviderSite site) { 117 118 String pluginId = (provider.getPluginId() != null) ? provider.getPluginId() : provider.getBundle() 121 .getSymbolicName(); 122 Object aClass = ModelLoaderUtil.createClassInstance(pluginId, provider.getClassName()); 123 IIntroContentProvider providerClass = null; 124 if (aClass != null && aClass instanceof IIntroContentProvider) { 125 providerClass = ((IIntroContentProvider) aClass); 126 providerClass.init(site); 127 if (provider.getId() != null) { 128 ContentProviderWrapper wrapper = new ContentProviderWrapper(providerClass, provider 130 .getParentPage()); 131 contentProviders.put(provider.getId(), wrapper); 132 } 133 } else 134 Log.warning("Failed to create Intro model content provider: " + provider.getClassName()); 136 return providerClass; 137 } 138 139 140 public AbstractIntroPage getContentProviderParentPage(IIntroContentProvider provider) { 141 Enumeration keys = contentProviders.keys(); 142 while (keys.hasMoreElements()) { 143 String key = (String ) keys.nextElement(); 144 ContentProviderWrapper wrapper = (ContentProviderWrapper) contentProviders.get(key); 145 boolean foundKey = wrapper.getIIntroContentProvider().equals(provider) ? true : false; 146 if (foundKey) { 147 return wrapper.getParentPage(); 148 } 149 } 150 return null; 151 } 152 153 public void clear() { 154 for (Iterator it = contentProviders.values().iterator(); it.hasNext();) { 155 ContentProviderWrapper providerWrapper = (ContentProviderWrapper) it.next(); 156 IIntroContentProvider provider = providerWrapper.getIIntroContentProvider(); 157 provider.dispose(); 158 } 159 contentProviders.clear(); 160 if (Log.logInfo) 161 Log.info("Cleared Intro model content providers"); } 163 164 165 } 166 | Popular Tags |