KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > quickdiff > QuickDiffExtensionsRegistry


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.texteditor.quickdiff;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExtensionRegistry;
19 import org.eclipse.core.runtime.Platform;
20
21 import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
22 import org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor;
23
24 /**
25  * Access class for the quick diff reference provider extension point.
26  *
27  * @since 3.0
28  */

29 public class QuickDiffExtensionsRegistry {
30
31     /** The default reference provider's descriptor. */
32     private ReferenceProviderDescriptor fDefaultDescriptor;
33     /** The list returned to callers of <code>getExtensions</code>. */
34     private List JavaDoc fDescriptors;
35
36     /**
37      * Creates a new instance.
38      */

39     public QuickDiffExtensionsRegistry() {
40     }
41
42     /**
43      * Returns the default provider, which is the last saved version.
44      *
45      * @return the descriptor of the default reference provider.
46      */

47     public synchronized ReferenceProviderDescriptor getDefaultProvider() {
48         ensureRegistered();
49         return fDefaultDescriptor;
50     }
51
52     /**
53      * Returns a non-modifiable list of <code>ReferenceProviderDescriptor</code> describing all extension
54      * to the <code>quickDiffReferenceProvider</code> extension point.
55      *
56      * @return the list of extensions to the <code>quickDiffReferenceProvider</code> extension point.
57      */

58     public synchronized List JavaDoc getReferenceProviderDescriptors() {
59         ensureRegistered();
60         return fDescriptors;
61     }
62
63     /**
64      * Ensures that the extensions are read and stored in <code>fDescriptors</code>.
65      */

66     private void ensureRegistered() {
67         if (fDescriptors == null)
68             reloadExtensions();
69     }
70
71     /**
72      * Reads all extensions.
73      * <p>
74      * This method can be called more than once in
75      * order to reload from a changed extension registry.
76      * </p>
77      */

78     public synchronized void reloadExtensions() {
79         fDefaultDescriptor= null;
80         IExtensionRegistry registry= Platform.getExtensionRegistry();
81         List JavaDoc list= new ArrayList JavaDoc();
82
83         IConfigurationElement[] elements= registry.getConfigurationElementsFor(TextEditorPlugin.PLUGIN_ID, TextEditorPlugin.REFERENCE_PROVIDER_EXTENSION_POINT);
84         for (int i= 0; i < elements.length; i++) {
85             ReferenceProviderDescriptor desc= new ReferenceProviderDescriptor(elements[i]);
86             if (desc.getId().equals("org.eclipse.ui.internal.editors.quickdiff.LastSaveReferenceProvider")) //$NON-NLS-1$
87
fDefaultDescriptor= desc;
88             list.add(desc);
89         }
90         
91         // make sure the default is the first one in the list
92
if (fDefaultDescriptor != null) {
93             list.remove(fDefaultDescriptor);
94             list.add(0, fDefaultDescriptor);
95         }
96
97         fDescriptors= Collections.unmodifiableList(list);
98     }
99 }
100
Popular Tags