blob: a552e5a5e64f501c8bfcc4f7a95f398d22e8dca8 (
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
|
/*****************************************************************************
* Copyright (c) 2008 CEA LIST.
*
*
* 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:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.extension.diagrameditor;
import static org.eclipse.papyrus.infra.core.Activator.log;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.papyrus.infra.core.extension.BadNameExtensionException;
import org.eclipse.papyrus.infra.core.extension.ExtensionException;
import org.eclipse.papyrus.infra.core.extension.ExtensionUtils;
import org.eclipse.papyrus.infra.ui.Activator;
/**
* A factory used to create editor descriptor object from Eclipse extensions points elements.
*
* @author Cedric Dumoulin
* @author Patrick Tessier
* @since 1.2
*/
public class EditorDescriptorExtensionFactory extends ExtensionUtils {
/** singleton eINSTANCE of this class */
public static final EditorDescriptorExtensionFactory eINSTANCE = new EditorDescriptorExtensionFactory();
/** constant for the editor diagram **/
public static final String EDITOR_DIAGRAM_EXTENSIONPOINT = "editorDiagram";
/** constant for the attribute factoryClass **/
public static final String FACTORYCLASS_ATTRIBUTE = "factoryClass";
/** constant for the attribute contextId **/
public static final String ACTIONBARCONTRIBUTORID_ATTRIBUTE = "actionBarContributorId";
/** constant for the attribute icon **/
public static final String ICON_ATTRIBUTE = "icon";
/** constant for the order attribute */
public static final String ORDER_ATTRIBUTE = "order";
/**
* @return the eINSTANCE
*/
public static EditorDescriptorExtensionFactory getInstance() {
return eINSTANCE;
}
/**
* Create a descriptor instance corresponding to the ConfigurationElement.
*
* @param element
* an {@link IConfigurationElement} see eclipse extension point
* @return a nestedEditorDescriptor structure that contains information to create diagrams
* @throws BadNameExtensionException
*/
@SuppressWarnings("unchecked")
public EditorDescriptor createNestedEditorDescriptor(IConfigurationElement element) throws ExtensionException {
EditorDescriptor res;
checkTagName(element, EDITOR_DIAGRAM_EXTENSIONPOINT);
res = new EditorDescriptor();
res.setEditorFactoryClass((Class<IPluggableEditorFactory>) parseClass(element, FACTORYCLASS_ATTRIBUTE, EDITOR_DIAGRAM_EXTENSIONPOINT));
res.setActionBarContributorId(element.getAttribute(ACTIONBARCONTRIBUTORID_ATTRIBUTE));
int order = 0; // Default
try {
String orderAttribute = element.getAttribute(ORDER_ATTRIBUTE);
if (orderAttribute != null) {
order = Integer.parseInt(orderAttribute);
}
} catch (NumberFormatException ex) {
Activator.log.warn("Invalid order provided by " + element.getContributor() + ". Order should be an integer value"); //$NON-NLS-1$ //$NON-NLS-2$
}
res.setOrder(order);
String iconPath = element.getAttribute(ICON_ATTRIBUTE);
if (iconPath != null) {
/** Implementation which set the icon and register the complete URL of the icon : Bug eclipse 358732 */
res.setIcon(element, iconPath, Activator.PLUGIN_ID);
}
if (log.isDebugEnabled()) {
log.debug("Read editor descriptor " + res); //$NON-NLS-1$
}
return res;
}
}
|