Initialize
[sdk/ide/product.git] / org.eclipse.jst.pagedesigner / src / org / eclipse / jst / pagedesigner / properties / internal / WPETabPropertySectionDescriptorProvider.java
1 /*******************************************************************************\r
2  * Copyright (c) 2006 Sybase, Inc. and others.\r
3  *\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Sybase, Inc. - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.eclipse.jst.pagedesigner.properties.internal;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.List;\r
16 \r
17 import org.eclipse.core.runtime.IConfigurationElement;\r
18 import org.eclipse.core.runtime.IExtensionPoint;\r
19 import org.eclipse.core.runtime.Platform;\r
20 import org.eclipse.jst.pagedesigner.editors.HTMLEditor;\r
21 import org.eclipse.ui.views.properties.tabbed.ISectionDescriptor;\r
22 import org.eclipse.ui.views.properties.tabbed.ISectionDescriptorProvider;\r
23 \r
24 /**\r
25  * Provides sections registered for the Web Page Editor whose contributor ID is,\r
26  * "org.eclipse.jst.pagedesigner.tabPropertyContributor" using the\r
27  * org.eclipse.ui.views.properties.tabbed.propertyTabs extension-points.  \r
28  * \r
29  * The sections declared using the org.eclipse.ui.views.properties.tabbed.propertySections extension-point \r
30  * for the WPE will only be displayed by the Quick Edit tab is the selected tag has metadata to choose \r
31  * the section.  TypeMappers/filters, etc. are ignored by this sectionDescriptorProvider.\r
32  * \r
33  * See jsf_html.xml in the org.eclipse.jst.jsf.standard.tagsupport plugin for examples on how to use.  \r
34  */\r
35 public class WPETabPropertySectionDescriptorProvider implements\r
36                 ISectionDescriptorProvider {\r
37         \r
38         private static final String EXTPT_SECTIONS = "propertySections"; //$NON-NLS-1$\r
39         private static final String ELEMENT_SECTION = "propertySection"; //$NON-NLS-1$\r
40         private ISectionDescriptor[] _descriptors = null;\r
41 \r
42         /**\r
43          * Constructor\r
44          */\r
45         public WPETabPropertySectionDescriptorProvider() {\r
46                 super();\r
47         }\r
48 \r
49         public ISectionDescriptor[] getSectionDescriptors() {\r
50                 if (_descriptors == null) {\r
51                         List result = new ArrayList();\r
52                         List contributedSections = readSectionDescriptors();\r
53                         result.addAll(contributedSections);\r
54 \r
55 //                      if (1 == 0){ //disabled for now... do we want to allow other mechanisms to add sections?\r
56 //                              List providers = readAdditionalSectionDescriptorProviders();\r
57 //                              for (int i = 0, size = providers.size(); i < size; i++) {\r
58 //                                      try {\r
59 //                                              ISectionDescriptorProvider provider = (ISectionDescriptorProvider) providers\r
60 //                                                              .get(i);\r
61 //                                              ISectionDescriptor[] sections = provider\r
62 //                                                              .getSectionDescriptors();\r
63 //                                              if (sections != null) {\r
64 //                                                      result.addAll(Arrays.asList(sections));\r
65 //                                              }\r
66 //                                      } catch (Exception ex) {\r
67 //                                              // ignore\r
68 //                                              ex.printStackTrace();\r
69 //                                      }\r
70 //                              }\r
71 //                      }\r
72                         _descriptors = new ISectionDescriptor[result.size()];\r
73                         result.toArray(_descriptors);\r
74                 }\r
75                 return _descriptors;\r
76         }\r
77 \r
78         /**\r
79          * @return registered section descriptors for the WPE QuickEdit tab\r
80          */\r
81         protected List<QuickEditTabSectionDescriptor> readSectionDescriptors() {\r
82                 List result = new ArrayList();\r
83                         \r
84                 IConfigurationElement[] extensions = getConfigurationElements(EXTPT_SECTIONS);\r
85                 for (int i = 0; i < extensions.length; i++) {\r
86                         IConfigurationElement extension = extensions[i];\r
87                         if (extension.getAttribute("contributorId").equals(HTMLEditor.TABBED_PROPERTIES_CONTRIBUTOR_ID)){ //$NON-NLS-1$\r
88                                 IConfigurationElement[] sections = extension\r
89                                                 .getChildren(ELEMENT_SECTION);\r
90                                 for (int j = 0; j < sections.length; j++) {\r
91                                         IConfigurationElement section = sections[j];\r
92                                         ISectionDescriptor descriptor = new QuickEditTabSectionDescriptor(\r
93                                                         section, null);//ITypeMapper set to null\r
94                                         result.add(descriptor);\r
95                                 }\r
96                         }\r
97                 }\r
98                 return result;\r
99         }\r
100 \r
101         /**\r
102          * @param extensionPointId\r
103          * @return IConfigurationElement[] \r
104          */\r
105         private static IConfigurationElement[] getConfigurationElements(\r
106                         String extensionPointId) {\r
107                 IExtensionPoint extensionPoint = Platform.getExtensionRegistry()\r
108                                 .getExtensionPoint("org.eclipse.ui.views.properties.tabbed", extensionPointId); //$NON-NLS-1$\r
109                 if (extensionPoint == null) {\r
110                         return null;\r
111                 }\r
112                 return extensionPoint.getConfigurationElements();\r
113         }\r
114         \r
115         /**\r
116          * @param name of section\r
117          * @return {@link QuickEditTabSectionDescriptor} or null if not located\r
118          */\r
119         public QuickEditTabSectionDescriptor getNamedSectionDescriptor(String name) {\r
120                 for (int i=0;i<getSectionDescriptors().length;i++){\r
121                         QuickEditTabSectionDescriptor sd = (QuickEditTabSectionDescriptor)getSectionDescriptors()[i];\r
122                         if (name.equals(sd.getId()))\r
123                                 return sd;\r
124                 }\r
125                 return null;\r
126         }\r
127 }\r