1 11 package org.eclipse.ui.internal.intro; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtension; 18 import org.eclipse.core.runtime.IExtensionPoint; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.WorkbenchPlugin; 24 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 25 import org.eclipse.ui.internal.registry.RegistryReader; 26 27 32 public class IntroRegistry implements IIntroRegistry { 33 private static final String TAG_INTRO = "intro"; 35 private static final String TAG_INTROPRODUCTBINDING = "introProductBinding"; 37 private static final String ATT_INTROID = "introId"; 39 private static final String ATT_PRODUCTID = "productId"; 41 46 public int getIntroCount() { 47 return getIntros().length; 48 } 49 50 55 public IIntroDescriptor[] getIntros() { 56 IExtensionPoint point = Platform.getExtensionRegistry() 57 .getExtensionPoint(PlatformUI.PLUGIN_ID, 58 IWorkbenchRegistryConstants.PL_INTRO); 59 if (point == null) { 60 return new IIntroDescriptor[0]; 61 } 62 63 IExtension[] extensions = point.getExtensions(); 64 extensions = RegistryReader.orderExtensions(extensions); 65 66 ArrayList list = new ArrayList (extensions.length); 67 for (int i = 0; i < extensions.length; i++) { 68 IConfigurationElement[] elements = extensions[i] 69 .getConfigurationElements(); 70 for (int j = 0; j < elements.length; j++) { 71 if (elements[j].getName().equals(TAG_INTRO)) { 72 try { 73 IIntroDescriptor descriptor = new IntroDescriptor( 74 elements[j]); 75 list.add(descriptor); 76 } catch (CoreException e) { 77 WorkbenchPlugin 79 .log( 80 IntroMessages.Intro_could_not_create_descriptor, e.getStatus()); 81 } 82 } 83 } 84 } 85 86 return (IIntroDescriptor[]) list.toArray(new IIntroDescriptor[list 87 .size()]); 88 } 89 90 95 public IIntroDescriptor getIntroForProduct(String targetProductId) { 96 IExtensionPoint point = Platform.getExtensionRegistry() 97 .getExtensionPoint(PlatformUI.PLUGIN_ID, 98 IWorkbenchRegistryConstants.PL_INTRO); 99 if (point == null) { 100 return null; 101 } 102 103 IExtension[] extensions = point.getExtensions(); 104 extensions = RegistryReader.orderExtensions(extensions); 105 106 String targetIntroId = getIntroForProduct(targetProductId, extensions); 107 if (targetIntroId == null) { 108 return null; 109 } 110 111 IIntroDescriptor descriptor = null; 112 113 IIntroDescriptor[] intros = getIntros(); 114 for (int i = 0; i < intros.length; i++) { 115 if (intros[i].getId().equals(targetIntroId)) { 116 descriptor = intros[i]; 117 break; 118 } 119 } 120 121 return descriptor; 122 } 123 124 129 private String getIntroForProduct(String targetProductId, 130 IExtension[] extensions) { 131 for (int i = 0; i < extensions.length; i++) { 132 IConfigurationElement[] elements = extensions[i] 133 .getConfigurationElements(); 134 for (int j = 0; j < elements.length; j++) { 135 if (elements[j].getName().equals(TAG_INTROPRODUCTBINDING)) { 136 String introId = elements[j].getAttribute(ATT_INTROID); 137 String productId = elements[j].getAttribute(ATT_PRODUCTID); 138 139 if (introId == null || productId == null) { 140 IStatus status = new Status( 141 IStatus.ERROR, 142 elements[j].getDeclaringExtension() 143 .getNamespace(), 144 IStatus.ERROR, 145 "introId and productId must be defined.", new IllegalArgumentException ()); WorkbenchPlugin.log("Invalid intro binding", status); continue; 148 } 149 150 if (targetProductId.equals(productId)) { 151 return introId; 152 } 153 } 154 } 155 } 156 return null; 157 } 158 159 164 public IIntroDescriptor getIntro(String id) { 165 IIntroDescriptor[] intros = getIntros(); 166 for (int i = 0; i < intros.length; i++) { 167 IIntroDescriptor desc = intros[i]; 168 if (desc.getId().equals(id)) { 169 return desc; 170 } 171 } 172 return null; 173 } 174 } 175 | Popular Tags |