blob: 158a543698c7ffbbd66d906543a9fe925828cd6f (
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
|
/*****************************************************************************
* Copyright (c) 2010 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:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.views.properties.runtime.controller;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.papyrus.views.properties.runtime.Activator;
import org.eclipse.papyrus.views.properties.runtime.controller.descriptor.IPropertyEditorControllerDescriptor;
import org.osgi.framework.Bundle;
import org.w3c.dom.Node;
/**
* Provider for property editors
*/
public class PropertyEditorControllerProvider extends AbstractProvider {
/** map that stores the mapping id -> editor class */
private Map<String, PropertyEditorControllerConfiguration> controllers = new HashMap<String, PropertyEditorControllerConfiguration>();
private Bundle bundle;
/**
* Creates the property editor managed by this provider
*
* @param controllerIdentifier
* identifier of the controller
*
* @return the property editor managed by this provider
*/
public IPropertyEditorController createPropertyEditorController(String controllerIdentifier) {
// retrieve property class managed by this provider
try {
PropertyEditorControllerConfiguration configuration = controllers.get(controllerIdentifier);
if(configuration == null) {
Activator.log.error("impossible to find the configuration for controller " + controllerIdentifier, null);
return null;
}
Object controller = configuration.instanciateController();
return (IPropertyEditorController)controller;
} catch (CoreException e) {
e.printStackTrace();
Activator.log.error(e);
}
return null;
}
/**
* Configures the provider, given the {@link IConfigurationElement}
*
* @param providerConfiguration
* the configuration element from the xml plugin file
*/
public void configure(IConfigurationElement providerConfiguration) {
try {
bundle = Platform.getBundle(providerConfiguration.getContributor().getName());
// for each property editors defined in the provider, retrieves important information
for(IConfigurationElement element : providerConfiguration.getChildren()) {
// check this child is really configuring editors (not a Priority child...)
if("PropertyEditorController".equals(element.getName())) {
// parse this editor configuration
PropertyEditorControllerConfiguration configuration = PropertyEditorControllerConfiguration.parse(element);
controllers.put(configuration.getId(), configuration);
}
}
} catch (CoreException e) {
e.printStackTrace();
Activator.log.error(e);
}
}
/**
* {@inheritDoc}
*/
public boolean provides(IOperation operation) {
if(operation instanceof CreatePropertyEditorControllerOperation) {
CreatePropertyEditorControllerOperation createPropertyEditorOperation = (CreatePropertyEditorControllerOperation)operation;
// test if the configuration corresponds to the feature or the id of the operation
// first test the id (specific editor)
// then test the feature
String operationIdentifier = createPropertyEditorOperation.getControllerIdentifier();
return controllers.containsKey(operationIdentifier);
}
if(operation instanceof CreatePropertyEditorControllerDescriptorOperation) {
CreatePropertyEditorControllerDescriptorOperation controllerDescriptorOperation = (CreatePropertyEditorControllerDescriptorOperation)operation;
return controllers.containsKey(controllerDescriptorOperation.getControllerID());
}
return false;
}
/**
* Generates the {@link IPropertyEditorControllerDescriptor} that configures the controller
*
* @param controllerID
* the id of the controller to configure
* @param contentNode
* the content node that configures the controller
* @return the created {@link IPropertyEditorControllerDescriptor}
*/
public IPropertyEditorControllerDescriptor generateDescriptor(String controllerID, Node contentNode) {
PropertyEditorControllerConfiguration configuration = controllers.get(controllerID);
return configuration.createControllerDescriptor(contentNode, bundle);
}
}
|