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;
20 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
21 import net.sourceforge.phpeclipse.ui.WebUI;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.IConfigurationElement;
25 import org.eclipse.core.runtime.IExtensionRegistry;
26 import org.eclipse.core.runtime.Platform;
31 public class JavaFoldingStructureProviderRegistry {
33 private static final String EXTENSION_POINT = "foldingStructureProviders"; //$NON-NLS-1$
35 /** The map of descriptors, indexed by their identifiers. */
36 private Map fDescriptors;
39 * Creates a new instance.
41 public JavaFoldingStructureProviderRegistry() {
45 * Returns an array of <code>IJavaFoldingProviderDescriptor</code>
46 * describing all extension to the <code>foldingProviders</code> extension
49 * @return the list of extensions to the
50 * <code>quickDiffReferenceProvider</code> extension point.
52 public JavaFoldingStructureProviderDescriptor[] getFoldingProviderDescriptors() {
55 return (JavaFoldingStructureProviderDescriptor[]) fDescriptors
58 new JavaFoldingStructureProviderDescriptor[fDescriptors
64 * Returns the folding provider with identifier <code>id</code> or
65 * <code>null</code> if no such provider is registered.
68 * the identifier for which a provider is wanted
69 * @return the corresponding provider, or <code>null</code> if none can be
72 public JavaFoldingStructureProviderDescriptor getFoldingProviderDescriptor(
76 return (JavaFoldingStructureProviderDescriptor) fDescriptors
82 * Instantiates and returns the provider that is currently configured in the
85 * @return the current provider according to the preferences
87 public IJavaFoldingStructureProvider getCurrentFoldingProvider() {
88 String id = WebUI.getDefault().getPreferenceStore()
89 .getString(PreferenceConstants.EDITOR_FOLDING_PROVIDER);
90 JavaFoldingStructureProviderDescriptor desc = getFoldingProviderDescriptor(id);
93 return desc.createProvider();
94 } catch (CoreException e) {
102 * Ensures that the extensions are read and stored in
103 * <code>fDescriptors</code>.
105 private void ensureRegistered() {
106 if (fDescriptors == null)
111 * Reads all extensions.
113 * This method can be called more than once in order to reload from a
114 * changed extension registry.
117 public void reloadExtensions() {
118 IExtensionRegistry registry = Platform.getExtensionRegistry();
119 Map map = new HashMap();
121 IConfigurationElement[] elements = registry
122 .getConfigurationElementsFor(PHPeclipsePlugin.getPluginId(),
124 for (int i = 0; i < elements.length; i++) {
125 JavaFoldingStructureProviderDescriptor desc = new JavaFoldingStructureProviderDescriptor(
127 map.put(desc.getId(), desc);
130 synchronized (this) {
131 fDescriptors = Collections.unmodifiableMap(map);