Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 794c8c900d5b987f6e66db56455df18fd2950cf1 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*******************************************************************************
 * Copyright (c) 2015 Obeo.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.eef.properties.ui.legacy.internal.extension.impl;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.eef.properties.ui.legacy.internal.EEFPropertiesUiLegacyPlugin;
import org.eclipse.eef.properties.ui.legacy.internal.Messages;
import org.eclipse.eef.properties.ui.legacy.internal.extension.IItemDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.ui.views.properties.tabbed.IActionProvider;
import org.eclipse.ui.views.properties.tabbed.ISectionDescriptorProvider;
import org.eclipse.ui.views.properties.tabbed.ITabDescriptorProvider;
import org.eclipse.ui.views.properties.tabbed.ITypeMapper;

/**
 * The property contributor descriptor.
 *
 * @author mbats
 */
public class LegacyPropertyContributorItemDescriptor implements IItemDescriptor {
	/**
	 * The configuration element.
	 */
	private IConfigurationElement configurationElement;

	/**
	 * The constructor.
	 *
	 * @param configurationElement
	 *            The configuration element
	 */
	public LegacyPropertyContributorItemDescriptor(IConfigurationElement configurationElement) {
		this.configurationElement = configurationElement;
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see IItemDescriptor#getId()
	 */
	@Override
	public String getId() {
		if (configurationElement != null) {
			return configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.CONTRIBUTOR_ID_ATTR);

		}
		return null;
	}

	/**
	 * Return the labelProvider.
	 *
	 * @return the labelProvider
	 */
	public ILabelProvider getLabelProvider() {
		ILabelProvider labelProvider = null;
		if (configurationElement != null
				&& configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.LABEL_PROVIDER_ATTR) != null) {
			try {
				labelProvider = (ILabelProvider) configurationElement
						.createExecutableExtension(LegacyPropertyContributorRegistryEventListener.LABEL_PROVIDER_ATTR);
			} catch (CoreException e) {
				String message = MessageFormat.format(Messages.RegistryEventListener_cannotInstantiateExtension, getId());
				EEFPropertiesUiLegacyPlugin.getImplementation().logError(message, e);
			}
		}
		return labelProvider;
	}

	/**
	 * Return the actionProvider.
	 *
	 * @return the actionProvider
	 */
	public IActionProvider getActionProvider() {
		IActionProvider actionProvider = null;
		if (configurationElement != null
				&& configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.ACTION_PROVIDER_ATTR) != null) {
			try {
				actionProvider = (IActionProvider) configurationElement
						.createExecutableExtension(LegacyPropertyContributorRegistryEventListener.ACTION_PROVIDER_ATTR);
			} catch (CoreException e) {
				String message = MessageFormat.format(Messages.RegistryEventListener_cannotInstantiateExtension, getId());
				EEFPropertiesUiLegacyPlugin.getImplementation().logError(message, e);
			}
		}
		return actionProvider;
	}

	/**
	 * Return the typeMapper.
	 *
	 * @return the typeMapper
	 */
	public ITypeMapper getTypeMapper() {
		ITypeMapper typeMapper = null;
		if (configurationElement != null
				&& configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.TYPE_MAPPER_ATTR) != null) {
			try {
				typeMapper = (ITypeMapper) configurationElement
						.createExecutableExtension(LegacyPropertyContributorRegistryEventListener.TYPE_MAPPER_ATTR);
			} catch (CoreException e) {
				String message = MessageFormat.format(Messages.RegistryEventListener_cannotInstantiateExtension, getId());
				EEFPropertiesUiLegacyPlugin.getImplementation().logError(message, e);
			}
		}
		return typeMapper;
	}

	/**
	 * Return the sectionDescriptorProvider.
	 *
	 * @return the sectionDescriptorProvider
	 */
	public ISectionDescriptorProvider getSectionDescriptorProvider() {
		ISectionDescriptorProvider sectionDescriptorProvider = null;
		if (configurationElement != null
				&& configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.SECTION_DESCRIPTOR_PROVIDER_ATTR) != null) {
			try {
				sectionDescriptorProvider = (ISectionDescriptorProvider) configurationElement
						.createExecutableExtension(LegacyPropertyContributorRegistryEventListener.SECTION_DESCRIPTOR_PROVIDER_ATTR);
			} catch (CoreException e) {
				String message = MessageFormat.format(Messages.RegistryEventListener_cannotInstantiateExtension, getId());
				EEFPropertiesUiLegacyPlugin.getImplementation().logError(message, e);
			}
		}
		return sectionDescriptorProvider;
	}

	/**
	 * Return the tabDescriptorProvider.
	 *
	 * @return the tabDescriptorProvider
	 */
	public ITabDescriptorProvider getTabDescriptorProvider() {
		ITabDescriptorProvider tabDescriptorProvider = null;
		if (configurationElement != null
				&& configurationElement.getAttribute(LegacyPropertyContributorRegistryEventListener.TAB_DESCRIPTOR_PROVIDER_ATTR) != null) {
			try {
				tabDescriptorProvider = (ITabDescriptorProvider) configurationElement
						.createExecutableExtension(LegacyPropertyContributorRegistryEventListener.TAB_DESCRIPTOR_PROVIDER_ATTR);
			} catch (CoreException e) {
				String message = MessageFormat.format(Messages.RegistryEventListener_cannotInstantiateExtension, getId());
				EEFPropertiesUiLegacyPlugin.getImplementation().logError(message, e);
			}
		}
		return tabDescriptorProvider;
	}

	/**
	 * Return the overridableTabListContentProvider.
	 *
	 * @return the overridableTabListContentProvider
	 */
	public boolean isOverridableTabListContentProvider() {
		if (configurationElement != null && configurationElement
				.getAttribute(LegacyPropertyContributorRegistryEventListener.OVERRIDABLE_TAB_LIST_CONTENT_PROVIDER_ATTR) != null) {
			String attributeBoolean = configurationElement
					.getAttribute(LegacyPropertyContributorRegistryEventListener.OVERRIDABLE_TAB_LIST_CONTENT_PROVIDER_ATTR);
			return "true".equals(attributeBoolean); //$NON-NLS-1$
		}
		return false;
	}

	/**
	 * Get categories.
	 *
	 * @return The categories
	 */
	public List<String> getCategories() {
		List<String> categories = new ArrayList<String>();
		if (configurationElement != null) {
			for (IConfigurationElement element : configurationElement
					.getChildren(LegacyPropertyContributorRegistryEventListener.TAG_PROPERTY_CATEGORY)) {
				categories.add(element.getAttribute(LegacyPropertyContributorRegistryEventListener.CATEGORY_ATTR));
			}
		}
		return categories;
	}
}

Back to the top