1 17 package org.eclipse.emf.edit; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.StringTokenizer ; 25 26 import org.eclipse.core.runtime.IConfigurationElement; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.emf.common.EMFPlugin; 29 import org.eclipse.emf.common.notify.AdapterFactory; 30 import org.eclipse.emf.common.util.ResourceLocator; 31 import org.eclipse.emf.ecore.EPackage; 32 import org.eclipse.emf.ecore.plugin.RegistryReader; 33 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 34 35 36 48 public final class EMFEditPlugin extends EMFPlugin 49 { 50 53 public static final EMFEditPlugin INSTANCE = new EMFEditPlugin(); 54 55 58 private static Implementation plugin; 59 60 63 private EMFEditPlugin() 64 { 65 super(new ResourceLocator[] {}); 66 } 67 68 71 public ResourceLocator getPluginResourceLocator() 72 { 73 return plugin; 74 } 75 76 80 public static ComposedAdapterFactory.Descriptor.Registry getComposedAdapterFactoryDescriptorRegistry() 81 { 82 final ComposedAdapterFactory.Descriptor.Registry.Impl result = 83 new ComposedAdapterFactory.Descriptor.Registry.Impl(null) 84 { 85 public ComposedAdapterFactory.Descriptor delegatedGetDescriptor(Collection types) 86 { 87 List stringTypes = new ArrayList (types.size()); 88 for (Iterator i = types.iterator(); i.hasNext(); ) 89 { 90 Object key = i.next(); 91 if (key instanceof EPackage) 92 { 93 stringTypes.add(((EPackage)key).getNsURI()); 94 } 95 else if (key instanceof Package ) 96 { 97 stringTypes.add(((Package )key).getName()); 98 } 99 else if (key instanceof Class ) 100 { 101 stringTypes.add(((Class )key).getName()); 102 } 103 else 104 { 105 return null; 106 } 107 } 108 ComposedAdapterFactory.Descriptor descriptor = (ComposedAdapterFactory.Descriptor)get(stringTypes); 109 if (descriptor != null) 110 { 111 put(types, descriptor); 112 return descriptor; 113 } 114 115 return super.delegatedGetDescriptor(types); 116 } 117 }; 118 if (INSTANCE.getPluginResourceLocator() instanceof EclipsePlugin) 119 { 120 RegistryReader registryReader = 121 new RegistryReader(Platform.getExtensionRegistry(), INSTANCE.getSymbolicName(), "itemProviderAdapterFactories") 122 { 123 protected boolean readElement(IConfigurationElement element) 124 { 125 if (element.getName().equals("factory")) 126 { 127 String packageURI = element.getAttribute("uri"); 128 String className = element.getAttribute("class"); 129 String supportedTypes = element.getAttribute("supportedTypes"); 130 if (packageURI == null) 131 { 132 logMissingAttribute(element, "uri"); 133 } 134 else if (className == null) 135 { 136 logMissingAttribute(element, "class"); 137 } 138 else if (supportedTypes == null) 139 { 140 logMissingAttribute(element, "supportedTypes"); 141 } 142 143 class PluginAdapterFactoryDescriptor extends PluginClassDescriptor implements ComposedAdapterFactory.Descriptor 144 { 145 public PluginAdapterFactoryDescriptor(IConfigurationElement element, String attributeName) 146 { 147 super(element, attributeName); 148 } 149 150 public AdapterFactory createAdapterFactory() 151 { 152 return (AdapterFactory)createInstance(); 153 } 154 } 155 156 for (StringTokenizer stringTokenizer = new StringTokenizer (supportedTypes); stringTokenizer.hasMoreTokens(); ) 157 { 158 String supportedType = stringTokenizer.nextToken(); 159 List key = new ArrayList (); 160 key.add(packageURI); 161 key.add(supportedType); 162 result.put(key, new PluginAdapterFactoryDescriptor(element, "class")); 163 } 164 165 return true; 166 } 167 return false; 168 } 169 }; 170 registryReader.readRegistry(); 171 } 172 return result; 173 } 174 175 179 public static Implementation getPlugin() 180 { 181 return plugin; 182 } 183 184 187 public static class Implementation extends EclipsePlugin 188 { 189 192 public Implementation() 193 { 194 super(); 195 196 plugin = this; 199 } 200 } 201 } 202 | Popular Tags |