1 11 12 package org.eclipse.ui.internal.splash; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.IExtension; 19 import org.eclipse.core.runtime.IExtensionPoint; 20 import org.eclipse.core.runtime.IProduct; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.core.runtime.SafeRunner; 23 import org.eclipse.jface.util.SafeRunnable; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.internal.WorkbenchPlugin; 26 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 27 import org.eclipse.ui.splash.AbstractSplashHandler; 28 29 34 public final class SplashHandlerFactory { 35 36 44 public static AbstractSplashHandler findSplashHandlerFor(IProduct product) { 45 if (product == null) 46 return null; 47 48 IExtensionPoint point = Platform.getExtensionRegistry() 49 .getExtensionPoint(PlatformUI.PLUGIN_ID, 50 IWorkbenchRegistryConstants.PL_SPLASH_HANDLERS); 51 52 if (point == null) 53 return null; 54 55 IExtension[] extensions = point.getExtensions(); 56 Map idToSplash = new HashMap (); String [] targetId = new String [1]; 58 for (int i = 0; i < extensions.length; i++) { 59 IConfigurationElement[] children = extensions[i] 60 .getConfigurationElements(); 61 for (int j = 0; j < children.length; j++) { 62 AbstractSplashHandler handler = processElement(children[j], 63 idToSplash, targetId, product); 64 if (handler != null) 65 return handler; 66 67 } 68 } 69 return null; 70 } 71 72 86 private static AbstractSplashHandler processElement( 87 IConfigurationElement configurationElement, Map idToSplash, 88 String [] targetId, IProduct product) { 89 String type = configurationElement.getName(); 90 if (IWorkbenchRegistryConstants.TAG_SPLASH_HANDLER.equals(type)) { 91 String id = configurationElement 92 .getAttribute(IWorkbenchRegistryConstants.ATT_ID); 93 if (id == null) 94 return null; 95 96 if (targetId[0] != null && id.equals(targetId[0])) { 98 return create(configurationElement); 99 } 100 idToSplash.put(id, configurationElement); 102 103 } else if (IWorkbenchRegistryConstants.TAG_SPLASH_HANDLER_PRODUCT_BINDING 104 .equals(type)) { 105 String productId = configurationElement 106 .getAttribute(IWorkbenchRegistryConstants.ATT_PRODUCTID); 107 if (product.getId().equals(productId) && targetId[0] == null) { targetId[0] = configurationElement 110 .getAttribute(IWorkbenchRegistryConstants.ATT_SPLASH_ID); 111 IConfigurationElement splashElement = (IConfigurationElement) idToSplash 113 .get(targetId[0]); 114 if (splashElement != null) 115 return create(splashElement); 116 } 117 } 118 119 return null; 120 } 121 122 129 private static AbstractSplashHandler create( 130 final IConfigurationElement splashElement) { 131 final AbstractSplashHandler[] handler = new AbstractSplashHandler[1]; 132 SafeRunner.run(new SafeRunnable() { 133 134 139 public void run() throws Exception { 140 handler[0] = (AbstractSplashHandler) WorkbenchPlugin 141 .createExtension(splashElement, 142 IWorkbenchRegistryConstants.ATT_CLASS); 143 } 144 145 150 public void handleException(Throwable e) { 151 WorkbenchPlugin 152 .log("Problem creating splash implementation", e); } 154 }); 155 156 return handler[0]; 157 } 158 } 159 | Popular Tags |