001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.texteditor.quickdiff;
011:
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.List;
015:
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExtensionRegistry;
018: import org.eclipse.core.runtime.Platform;
019:
020: import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
021: import org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor;
022:
023: /**
024: * Access class for the quick diff reference provider extension point.
025: *
026: * @since 3.0
027: */
028: public class QuickDiffExtensionsRegistry {
029:
030: /** The default reference provider's descriptor. */
031: private ReferenceProviderDescriptor fDefaultDescriptor;
032: /** The list returned to callers of <code>getExtensions</code>. */
033: private List fDescriptors;
034:
035: /**
036: * Creates a new instance.
037: */
038: public QuickDiffExtensionsRegistry() {
039: }
040:
041: /**
042: * Returns the default provider, which is the last saved version.
043: *
044: * @return the descriptor of the default reference provider.
045: */
046: public synchronized ReferenceProviderDescriptor getDefaultProvider() {
047: ensureRegistered();
048: return fDefaultDescriptor;
049: }
050:
051: /**
052: * Returns a non-modifiable list of <code>ReferenceProviderDescriptor</code> describing all extension
053: * to the <code>quickDiffReferenceProvider</code> extension point.
054: *
055: * @return the list of extensions to the <code>quickDiffReferenceProvider</code> extension point.
056: */
057: public synchronized List getReferenceProviderDescriptors() {
058: ensureRegistered();
059: return fDescriptors;
060: }
061:
062: /**
063: * Ensures that the extensions are read and stored in <code>fDescriptors</code>.
064: */
065: private void ensureRegistered() {
066: if (fDescriptors == null)
067: reloadExtensions();
068: }
069:
070: /**
071: * Reads all extensions.
072: * <p>
073: * This method can be called more than once in
074: * order to reload from a changed extension registry.
075: * </p>
076: */
077: public synchronized void reloadExtensions() {
078: fDefaultDescriptor = null;
079: IExtensionRegistry registry = Platform.getExtensionRegistry();
080: List list = new ArrayList();
081:
082: IConfigurationElement[] elements = registry
083: .getConfigurationElementsFor(
084: TextEditorPlugin.PLUGIN_ID,
085: TextEditorPlugin.REFERENCE_PROVIDER_EXTENSION_POINT);
086: for (int i = 0; i < elements.length; i++) {
087: ReferenceProviderDescriptor desc = new ReferenceProviderDescriptor(
088: elements[i]);
089: if (desc
090: .getId()
091: .equals(
092: "org.eclipse.ui.internal.editors.quickdiff.LastSaveReferenceProvider")) //$NON-NLS-1$
093: fDefaultDescriptor = desc;
094: list.add(desc);
095: }
096:
097: // make sure the default is the first one in the list
098: if (fDefaultDescriptor != null) {
099: list.remove(fDefaultDescriptor);
100: list.add(0, fDefaultDescriptor);
101: }
102:
103: fDescriptors = Collections.unmodifiableList(list);
104: }
105: }
|