Creating and using Extension PointsEclipse notes on plugins has a great deal of very useful information on plugin including how to create and use plugin extensions. Creating Extension PointsIn the Plug-in Manifest Editor's Extension Point tab, new extension points can be declared. In addition the plugin.xml file can be edited by hand to declare new extension points. Plug-in Manifest Editor(Assumes eclipse is being used)
The extension-point schema defines how to parameterize extensions. Extension-point SchemaThe extension-point schema defines how to parameterize extensions. An extension-point schema can be edited by hand or using eclipse's extension-point schema editor. See Eclipse help guide for detailed instructions on editing extension-point schemas. To create a extension-point schema that requires a extension to implement an interface:
Done. Finding ExtensionsThe following classes demonstrates how to find registered extensions: import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; public interface IProcessMember { public Object process(IExtension extension, IConfigurationElement member); } This class is a visitor. import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; public class ProcessExtensions { public static void process(String xpid, IProcessMember processor) { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry.getExtensionPoint(xpid); IExtension[] extensions = extensionPoint.getExtensions(); // For each extension ... for (int i = 0; i < extensions.length; i++) { IExtension extension = extensions[i]; IConfigurationElement[] elements = extension.getConfigurationElements(); // For each member of the extension ... for (int j = 0; j < elements.length; j++) { IConfigurationElement element = elements[j]; processor.process(extension, element); } } } } This class is used to process extensions as identified by an id. An id and a visitor are passed to the process method. The visitor knows the class that uses the extension. |
(c) Copyright (c) 2004,2005 Refractions Research Inc. and others. |