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>
44 * describing all extension to the <code>foldingProviders</code> extension
47 * @return the list of extensions to the
48 * <code>quickDiffReferenceProvider</code> extension point.
50 public JavaFoldingStructureProviderDescriptor[] getFoldingProviderDescriptors() {
53 return (JavaFoldingStructureProviderDescriptor[]) fDescriptors
56 new JavaFoldingStructureProviderDescriptor[fDescriptors
62 * Returns the folding provider with identifier <code>id</code> or
63 * <code>null</code> if no such provider is registered.
66 * the identifier for which a provider is wanted
67 * @return the corresponding provider, or <code>null</code> if none can be
70 public JavaFoldingStructureProviderDescriptor getFoldingProviderDescriptor(
74 return (JavaFoldingStructureProviderDescriptor) fDescriptors
80 * Instantiates and returns the provider that is currently configured in the
83 * @return the current provider according to the preferences
85 public IJavaFoldingStructureProvider getCurrentFoldingProvider() {
86 String id = PHPeclipsePlugin.getDefault().getPreferenceStore()
87 .getString(PreferenceConstants.EDITOR_FOLDING_PROVIDER);
88 JavaFoldingStructureProviderDescriptor desc = getFoldingProviderDescriptor(id);
91 return desc.createProvider();
92 } catch (CoreException e) {
93 PHPeclipsePlugin.log(e);
100 * Ensures that the extensions are read and stored in
101 * <code>fDescriptors</code>.
103 private void ensureRegistered() {
104 if (fDescriptors == null)
109 * Reads all extensions.
111 * This method can be called more than once in order to reload from a
112 * changed extension registry.
115 public void reloadExtensions() {
116 IExtensionRegistry registry = Platform.getExtensionRegistry();
117 Map map = new HashMap();
119 IConfigurationElement[] elements = registry
120 .getConfigurationElementsFor(PHPeclipsePlugin.getPluginId(),
122 for (int i = 0; i < elements.length; i++) {
123 JavaFoldingStructureProviderDescriptor desc = new JavaFoldingStructureProviderDescriptor(
125 map.put(desc.getId(), desc);
128 synchronized (this) {
129 fDescriptors = Collections.unmodifiableMap(map);