KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > quickdiff > ReferenceProviderDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.texteditor.quickdiff;
12
13 import org.osgi.framework.Bundle;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.Platform;
19
20
21
22
23 /**
24  * Describes an extension to the <code>quickdiff.referenceprovider</code> extension point.
25  *
26  * @see org.eclipse.ui.internal.texteditor.quickdiff.ReferenceSelectionAction
27  * @see QuickDiff
28  * @since 3.0
29  */

30 public class ReferenceProviderDescriptor {
31
32     /** Name of the <code>label</code> attribute. */
33     private static final String JavaDoc LABEL_ATTRIBUTE= "label"; //$NON-NLS-1$
34
/** Name of the <code>class</code> attribute. */
35     private static final String JavaDoc CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
36
/** Name of the <code>id</code> attribute. */
37     private static final String JavaDoc ID_ATTRIBUTE= "id"; //$NON-NLS-1$
38
/** Name of the <code>default</code> attribute. */
39     private static final String JavaDoc DEFAULT_ATTRIBUTE= "default"; //$NON-NLS-1$
40

41     /** The configuration element describing this extension. */
42     private IConfigurationElement fConfiguration;
43     /** The value of the <code>label</code> attribute, if read. */
44     private String JavaDoc fLabel;
45     /** The value of the <code>id</code> attribute, if read. */
46     private String JavaDoc fId;
47     /** The value of the <code>default</code> attribute, if read. */
48     private Boolean JavaDoc fDefault;
49     /** The bundle where this extension was defined. */
50     private Bundle fBundle;
51
52     /**
53      * Creates a new descriptor for <code>element</code>.
54      * <p>
55      * This method is for internal use only.
56      * </p>
57      *
58      * @param element the extension point element to be described.
59      */

60     public ReferenceProviderDescriptor(IConfigurationElement element) {
61         Assert.isLegal(element != null);
62         fConfiguration= element;
63     }
64
65     /**
66      * Reads (if needed) and returns the label of this extension.
67      *
68      * @return the label for this extension.
69      */

70     public String JavaDoc getLabel() {
71         if (fLabel == null) {
72             fLabel= fConfiguration.getAttribute(LABEL_ATTRIBUTE);
73             Assert.isNotNull(fLabel);
74         }
75         return fLabel;
76     }
77
78     /**
79      * Reads (if needed) and returns the id of this extension.
80      *
81      * @return the id for this extension.
82      */

83     public String JavaDoc getId() {
84         if (fId == null) {
85             fId= fConfiguration.getAttribute(ID_ATTRIBUTE);
86             Assert.isNotNull(fId);
87         }
88         return fId;
89     }
90
91     /**
92      * Creates a reference provider as described in the extension's xml. Sets the id on the provider.
93      * @return a new instance of the reference provider described by this descriptor.
94      */

95     public IQuickDiffReferenceProvider createProvider() {
96         try {
97             IQuickDiffReferenceProvider impl= (IQuickDiffReferenceProvider)fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE);
98             impl.setId(getId());
99             return impl;
100         } catch (CoreException e) {
101             return null;
102         }
103     }
104
105     /**
106      * States whether the plug-in declaring this extension has been loaded already.
107      *
108      * @return <code>true</code> if the extension point's plug-in has been loaded, <code>false</code> otherwise.
109      */

110     public boolean isPluginLoaded() {
111         if (fBundle == null)
112             fBundle= Platform.getBundle(fConfiguration.getContributor().getName());
113         return (fBundle != null && fBundle.getState() == Bundle.ACTIVE);
114     }
115
116     /**
117      * Reads (if needed) and returns the default attribute value of this extension.
118      *
119      * @return the default attribute value for this extension.
120      * @deprecated as of 3.2, the default flag should not be used any longer
121      */

122     public boolean getDefault() {
123         if (fDefault == null) {
124             String JavaDoc def= fConfiguration.getAttribute(DEFAULT_ATTRIBUTE);
125             if ("true".equalsIgnoreCase(def)) //$NON-NLS-1$
126
fDefault= Boolean.TRUE;
127             else
128                 fDefault= Boolean.FALSE;
129         }
130         return fDefault.booleanValue();
131     }
132
133 }
134
Popular Tags