Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / folding / JavaFoldingStructureProviderDescriptor.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.folding;
12
13 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingPreferenceBlock;
14 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.jface.text.Assert;
19
20 /**
21  * Describes a contribution to the folding provider extension point.
22  * 
23  * @since 3.0
24  */
25 public final class JavaFoldingStructureProviderDescriptor {
26
27         /* extension point attribute names */
28         
29         private static final String PREFERENCES_CLASS= "preferencesClass"; //$NON-NLS-1$
30         private static final String CLASS= "class"; //$NON-NLS-1$
31         private static final String NAME= "name"; //$NON-NLS-1$
32         private static final String ID= "id"; //$NON-NLS-1$
33         
34         /** The identifier of the extension. */
35         private String fId;
36         /** The name of the extension. */
37         private String fName;
38         /** The class name of the provided <code>IJavaFoldingStructureProvider</code>. */
39         private String fClass;
40         /**
41          * <code>true</code> if the extension specifies a custom
42          * <code>IJavaFoldingPreferenceBlock</code>.
43          */
44         private boolean fHasPreferences;
45         /** The configuration element of this extension. */
46         private IConfigurationElement fElement;
47         
48         /**
49          * Creates a new descriptor.
50          * 
51          * @param element the configuration element to read
52          */
53         JavaFoldingStructureProviderDescriptor(IConfigurationElement element) {
54                 fElement= element;
55                 fId= element.getAttributeAsIs(ID);
56                 Assert.isLegal(fId != null);
57                 
58                 fName= element.getAttribute(NAME);
59                 if (fName == null)
60                         fName= fId;
61                 
62                 fClass= element.getAttributeAsIs(CLASS);
63                 Assert.isLegal(fClass != null);
64                 
65                 if (element.getAttributeAsIs(PREFERENCES_CLASS) == null)
66                         fHasPreferences= false;
67                 else
68                         fHasPreferences= true;
69         }
70         
71         /**
72          * Creates a folding provider as described in the extension's xml.
73          * 
74          * @return a new instance of the folding provider described by this
75          *         descriptor
76          * @throws CoreException if creation fails
77          */
78         public IJavaFoldingStructureProvider createProvider() throws CoreException {
79                 IJavaFoldingStructureProvider prov= (IJavaFoldingStructureProvider) fElement.createExecutableExtension(CLASS);
80                 return prov;
81         }
82
83         /**
84          * Creates a preferences object as described in the extension's xml.
85          * 
86          * @return a new instance of the reference provider described by this
87          *         descriptor
88          * @throws CoreException if creation fails
89          */
90         public IJavaFoldingPreferenceBlock createPreferences() throws CoreException {
91                 if (fHasPreferences) {
92                         IJavaFoldingPreferenceBlock prefs= (IJavaFoldingPreferenceBlock) fElement.createExecutableExtension(PREFERENCES_CLASS);
93                         return prefs;
94                 } else {
95                         return new EmptyJavaFoldingPreferenceBlock();
96                 }
97         }
98         
99         /**
100          * Returns the identifier of the described extension.
101          * 
102          * @return Returns the id
103          */
104         public String getId() {
105                 return fId;
106         }
107         
108         /**
109          * Returns the name of the described extension.
110          * 
111          * @return Returns the name
112          */
113         public String getName() {
114                 return fName;
115         }
116 }