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