1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.folding;
13 import java.util.Collections;
14 import java.util.HashMap;
17 import net.sourceforge.phpdt.ui.PreferenceConstants;
18 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IConfigurationElement;
23 import org.eclipse.core.runtime.IExtensionRegistry;
24 import org.eclipse.core.runtime.Platform;
29 public class JavaFoldingStructureProviderRegistry {
31 private static final String EXTENSION_POINT= "foldingStructureProviders"; //$NON-NLS-1$
33 /** The map of descriptors, indexed by their identifiers. */
34 private Map fDescriptors;
37 * Creates a new instance.
39 public JavaFoldingStructureProviderRegistry() {
43 * Returns an array of <code>IJavaFoldingProviderDescriptor</code> describing
44 * all extension to the <code>foldingProviders</code> extension point.
46 * @return the list of extensions to the
47 * <code>quickDiffReferenceProvider</code> extension point.
49 public JavaFoldingStructureProviderDescriptor[] getFoldingProviderDescriptors() {
52 return (JavaFoldingStructureProviderDescriptor[]) fDescriptors.values().toArray(new JavaFoldingStructureProviderDescriptor[fDescriptors.size()]);
57 * Returns the folding provider with identifier <code>id</code> or
58 * <code>null</code> if no such provider is registered.
60 * @param id the identifier for which a provider is wanted
61 * @return the corresponding provider, or <code>null</code> if none can be
64 public JavaFoldingStructureProviderDescriptor getFoldingProviderDescriptor(String id) {
67 return (JavaFoldingStructureProviderDescriptor) fDescriptors.get(id);
72 * Instantiates and returns the provider that is currently configured in the
75 * @return the current provider according to the preferences
77 public IJavaFoldingStructureProvider getCurrentFoldingProvider() {
78 String id= PHPeclipsePlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.EDITOR_FOLDING_PROVIDER);
79 JavaFoldingStructureProviderDescriptor desc= getFoldingProviderDescriptor(id);
82 return desc.createProvider();
83 } catch (CoreException e) {
84 PHPeclipsePlugin.log(e);
91 * Ensures that the extensions are read and stored in
92 * <code>fDescriptors</code>.
94 private void ensureRegistered() {
95 if (fDescriptors == null)
100 * Reads all extensions.
102 * This method can be called more than once in
103 * order to reload from a changed extension registry.
106 public void reloadExtensions() {
107 IExtensionRegistry registry= Platform.getExtensionRegistry();
108 Map map= new HashMap();
110 IConfigurationElement[] elements= registry.getConfigurationElementsFor(PHPeclipsePlugin.getPluginId(), EXTENSION_POINT);
111 for (int i= 0; i < elements.length; i++) {
112 JavaFoldingStructureProviderDescriptor desc= new JavaFoldingStructureProviderDescriptor(elements[i]);
113 map.put(desc.getId(), desc);
117 fDescriptors= Collections.unmodifiableMap(map);