Skip to main content
summaryrefslogtreecommitdiffstats
blob: dbbec780faf73c9cce2c7170f41305262bdba0d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.properties.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor;
import org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptorProvider;

/**
 * The DesignerTagPropertySectionDescriptorProvider will provide the section
 * descriptiors. Now section descriptor come from two sources.
 * 
 * One is reading from the "org.eclipse.jst.pagedesigner.propertyContributor"
 * extension point. This extension point will contribute additional section
 * providers, which provides a set of sections.
 * 
 * One is reading from the "org.eclipse.jst.pagedesigner.propertySections"
 * extension point. This extension provide a single section.
 * 
 * @author mengbo
 * @version 1.5
 */
public class DesignerTabPropertySectionDescriptorProvider implements
		ISectionDescriptorProvider {
	private static final String EXTPT_SECTIONS = "propertySections"; //$NON-NLS-1$

	private static final String ELEMENT_SECTION = "propertySection"; //$NON-NLS-1$

	private static final String EXTPT_SECTIONDESCRIPTORPROVIDER = "propertyContributor";

	private static final String ELEMENT_PROPERTYCONTRIBUTOR = "propertyContributor";

	private static final String ATTR_SECTIONDESCRIPTORPROVIDER = "sectionDescriptorProvider";

	ISectionDescriptor[] _descriptors = null;

	/**
	 * 
	 */
	public DesignerTabPropertySectionDescriptorProvider() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptorProvider#getSectionDescriptors()
	 */
	public ISectionDescriptor[] getSectionDescriptors() {
		if (_descriptors == null) {
			List result = new ArrayList();
			List contributedSections = readSectionDescriptors();
			result.addAll(contributedSections);

			List providers = readAdditionalSectionDescriptorProviders();
			for (int i = 0, size = providers.size(); i < size; i++) {
				try {
					ISectionDescriptorProvider provider = (ISectionDescriptorProvider) providers
							.get(i);
					ISectionDescriptor[] sections = provider
							.getSectionDescriptors();
					if (sections != null) {
						result.addAll(Arrays.asList(sections));
					}
				} catch (Exception ex) {
					// ignore
					ex.printStackTrace();
				}
			}
			_descriptors = new ISectionDescriptor[result.size()];
			result.toArray(_descriptors);
		}
		return _descriptors;
	}

	/**
	 * @return the providers
	 */
	protected List readAdditionalSectionDescriptorProviders() {
		List result = new ArrayList();
		IConfigurationElement[] extensions = getConfigurationElements(EXTPT_SECTIONDESCRIPTORPROVIDER);
		for (int i = 0; i < extensions.length; i++) {
			IConfigurationElement extension = extensions[i];
			if (ELEMENT_PROPERTYCONTRIBUTOR.equals(extension.getName())) {
				IConfigurationElement contributor = extension;
				try {
					Object obj = contributor
							.createExecutableExtension(ATTR_SECTIONDESCRIPTORPROVIDER);
					if (obj instanceof ISectionDescriptorProvider) {
						result.add(obj);
					}
				} catch (CoreException ex) {
					ex.printStackTrace();
				}
			}
		}
		return result;
	}

	/**
	 * @return the descriptors
	 */
	protected List readSectionDescriptors() {
		List result = new ArrayList();
		IConfigurationElement[] extensions = getConfigurationElements(EXTPT_SECTIONS);
		for (int i = 0; i < extensions.length; i++) {
			IConfigurationElement extension = extensions[i];
			IConfigurationElement[] sections = extension
					.getChildren(ELEMENT_SECTION);
			for (int j = 0; j < sections.length; j++) {
				IConfigurationElement section = sections[j];
				ISectionDescriptor descriptor = new DesignerSectionDescriptor(
						section);
				result.add(descriptor);
			}
		}
		return result;
	}

	/**
	 * @param extensionPointId
	 * @return the configuration element
	 */
	public static IConfigurationElement[] getConfigurationElements(
			String extensionPointId) {
		IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
				.getExtensionPoint(PDPlugin.getPluginId(), extensionPointId);

		if (extensionPoint == null) {
			return null;
		}
		return extensionPoint.getConfigurationElements();
	}
}

Back to the top