|
Lines 1-11
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others. |
2 |
* Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others. |
| 3 |
* |
3 |
* |
| 4 |
* All rights reserved. This program and the accompanying materials |
4 |
* All rights reserved. This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 6 |
* which accompanies this distribution, and is available at |
6 |
* which accompanies this distribution, and is available at |
| 7 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* http://www.eclipse.org/legal/epl-v10.html |
| 8 |
* |
8 |
* |
| 9 |
* Contributors: |
9 |
* Contributors: |
| 10 |
* Eugen Neufeld - initial API and implementation |
10 |
* Eugen Neufeld - initial API and implementation |
| 11 |
******************************************************************************/ |
11 |
******************************************************************************/ |
|
Lines 32-62
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Link Here
|
| 32 |
import org.osgi.framework.Bundle; |
32 |
import org.osgi.framework.Bundle; |
| 33 |
|
33 |
|
| 34 |
/** |
34 |
/** |
| 35 |
* The ControlFactoryImpl is a Singelton which reads the org.eclipse.emf.ecp.editor.widgets ExtensionPoint and provides a |
35 |
* The ControlFactoryImpl is a Singleton which reads the org.eclipse.emf.ecp.editor.widgets ExtensionPoint and provides |
| 36 |
* method ({@link #createControl(T, IItemPropertyDescriptor, ECPControlContext)}) for creating a suitable |
36 |
* a method ({@link #createControl(T, IItemPropertyDescriptor, ECPControlContext)}) for creating a suitable |
| 37 |
* control for with the known widgets. |
37 |
* control for with the known widgets. |
| 38 |
* |
38 |
* |
| 39 |
* @author Eugen Neufeld |
39 |
* @author Eugen Neufeld |
| 40 |
* |
40 |
* |
| 41 |
*/ |
41 |
*/ |
| 42 |
public final class ControlFactoryImpl implements ECPControlFactory{ |
42 |
public final class ControlFactoryImpl implements ECPControlFactory{ |
| 43 |
|
43 |
|
| 44 |
private static final String CONTROL_EXTENSION = "org.eclipse.emf.ecp.edit.controls"; //$NON-NLS-1$ |
44 |
private static final String CONTROL_EXTENSION = "org.eclipse.emf.ecp.edit.controls"; //$NON-NLS-1$ |
| 45 |
|
45 |
|
| 46 |
private static final String CLASS_ATTRIBUTE = "class";//$NON-NLS-1$ |
46 |
private static final String CLASS_ATTRIBUTE = "class";//$NON-NLS-1$ |
| 47 |
private static final String CONTROL_ID = "id";//$NON-NLS-1$ |
47 |
private static final String CONTROL_ID = "id";//$NON-NLS-1$ |
| 48 |
private static final String LABEL_ATTRIBUTE = "showLabel";//$NON-NLS-1$ |
48 |
private static final String LABEL_ATTRIBUTE = "showLabel";//$NON-NLS-1$ |
| 49 |
|
49 |
|
| 50 |
private static final String TEST_DYNAMIC = "dynamicTest";//$NON-NLS-1$ |
50 |
private static final String TEST_DYNAMIC = "dynamicTest";//$NON-NLS-1$ |
| 51 |
private static final String CONTROL_TESTER = "testClass";//$NON-NLS-1$ |
51 |
private static final String CONTROL_TESTER = "testClass";//$NON-NLS-1$ |
| 52 |
|
52 |
|
| 53 |
private static final String TEST_STATIC = "staticTest";//$NON-NLS-1$ |
53 |
private static final String TEST_STATIC = "staticTest";//$NON-NLS-1$ |
| 54 |
private static final String TESTER_PRIORITY = "priority";//$NON-NLS-1$ |
54 |
private static final String TESTER_PRIORITY = "priority";//$NON-NLS-1$ |
| 55 |
private static final String TESTER_CLASSTYPE = "supportedClassType";//$NON-NLS-1$ |
55 |
private static final String TESTER_CLASSTYPE = "supportedClassType";//$NON-NLS-1$ |
| 56 |
private static final String TESTER_EOBJECT = "supportedEObject";//$NON-NLS-1$ |
56 |
private static final String TESTER_EOBJECT = "supportedEObject";//$NON-NLS-1$ |
| 57 |
private static final String TESTER_FEATURE = "supportedFeature";//$NON-NLS-1$ |
57 |
private static final String TESTER_FEATURE = "supportedFeature";//$NON-NLS-1$ |
| 58 |
private static final String TESTER_SINGLEVALUE = "singleValue";//$NON-NLS-1$ |
58 |
private static final String TESTER_SINGLEVALUE = "singleValue";//$NON-NLS-1$ |
| 59 |
|
59 |
|
| 60 |
private Set<ECPControlDescription> controlDescriptors = new HashSet<ECPControlDescription>(); |
60 |
private Set<ECPControlDescription> controlDescriptors = new HashSet<ECPControlDescription>(); |
| 61 |
|
61 |
|
| 62 |
/** |
62 |
/** |
|
Lines 77-83
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 77 |
String clazz = e.getAttribute(CLASS_ATTRIBUTE); |
77 |
String clazz = e.getAttribute(CLASS_ATTRIBUTE); |
| 78 |
Class<? extends ECPAbstractControl> resolvedClass = loadClass(e.getContributor().getName(), clazz); |
78 |
Class<? extends ECPAbstractControl> resolvedClass = loadClass(e.getContributor().getName(), clazz); |
| 79 |
boolean showLabel = Boolean.parseBoolean(e.getAttribute(LABEL_ATTRIBUTE)); |
79 |
boolean showLabel = Boolean.parseBoolean(e.getAttribute(LABEL_ATTRIBUTE)); |
| 80 |
|
80 |
|
| 81 |
// ECPApplicableTester tester=null; |
81 |
// ECPApplicableTester tester=null; |
| 82 |
Set<ECPApplicableTester> tester=new HashSet<ECPApplicableTester>(); |
82 |
Set<ECPApplicableTester> tester=new HashSet<ECPApplicableTester>(); |
| 83 |
for(IConfigurationElement testerExtension: e.getChildren()){ |
83 |
for(IConfigurationElement testerExtension: e.getChildren()){ |
|
Lines 87-105
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 87 |
else if(TEST_STATIC.equals(testerExtension.getName())){ |
87 |
else if(TEST_STATIC.equals(testerExtension.getName())){ |
| 88 |
boolean singleValue = Boolean.parseBoolean(testerExtension.getAttribute(TESTER_SINGLEVALUE)); |
88 |
boolean singleValue = Boolean.parseBoolean(testerExtension.getAttribute(TESTER_SINGLEVALUE)); |
| 89 |
int priority = Integer.parseInt(testerExtension.getAttribute(TESTER_PRIORITY)); |
89 |
int priority = Integer.parseInt(testerExtension.getAttribute(TESTER_PRIORITY)); |
| 90 |
|
90 |
|
| 91 |
String type = testerExtension.getAttribute(TESTER_CLASSTYPE); |
91 |
String type = testerExtension.getAttribute(TESTER_CLASSTYPE); |
| 92 |
Class<?> supportedClassType = loadClass(testerExtension.getContributor().getName(), type); |
92 |
Class<?> supportedClassType = loadClass(testerExtension.getContributor().getName(), type); |
| 93 |
//Class.forName(type); |
93 |
//Class.forName(type); |
| 94 |
|
94 |
|
| 95 |
String eObject = testerExtension.getAttribute(TESTER_EOBJECT); |
95 |
String eObject = testerExtension.getAttribute(TESTER_EOBJECT); |
| 96 |
if (eObject == null) { |
96 |
if (eObject == null) { |
| 97 |
eObject = "org.eclipse.emf.ecore.EObject";//$NON-NLS-1$ |
97 |
eObject = "org.eclipse.emf.ecore.EObject";//$NON-NLS-1$ |
| 98 |
} |
98 |
} |
| 99 |
Class<? extends EObject> supportedEObject = loadClass(testerExtension.getContributor().getName(), eObject); |
99 |
Class<? extends EObject> supportedEObject = loadClass(testerExtension.getContributor().getName(), eObject); |
| 100 |
|
100 |
|
| 101 |
String supportedFeature = testerExtension.getAttribute(TESTER_FEATURE); |
101 |
String supportedFeature = testerExtension.getAttribute(TESTER_FEATURE); |
| 102 |
|
102 |
|
| 103 |
tester.add(new ECPStaticApplicableTester(singleValue, priority, supportedClassType, supportedEObject, supportedFeature)); |
103 |
tester.add(new ECPStaticApplicableTester(singleValue, priority, supportedClassType, supportedEObject, supportedFeature)); |
| 104 |
} |
104 |
} |
| 105 |
} |
105 |
} |
|
Lines 117-125
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 117 |
private static <T> Class<T> loadClass(String bundleName, String clazz) throws ClassNotFoundException { |
117 |
private static <T> Class<T> loadClass(String bundleName, String clazz) throws ClassNotFoundException { |
| 118 |
Bundle bundle = Platform.getBundle(bundleName); |
118 |
Bundle bundle = Platform.getBundle(bundleName); |
| 119 |
if (bundle == null) { |
119 |
if (bundle == null) { |
| 120 |
//TODO externalize strings |
120 |
throw new ClassNotFoundException(clazz + EditMessages.ControlFactoryImpl_CannotBeLoadedBecauseBundle + bundleName |
| 121 |
throw new ClassNotFoundException(clazz + " cannot be loaded because bundle " + bundleName //$NON-NLS-1$ |
121 |
+ EditMessages.ControlFactoryImpl_CannotBeResolved); |
| 122 |
+ " cannot be resolved"); //$NON-NLS-1$ |
|
|
| 123 |
} |
122 |
} |
| 124 |
return (Class<T>) bundle.loadClass(clazz); |
123 |
return (Class<T>) bundle.loadClass(clazz); |
| 125 |
|
124 |
|
|
Lines 137-151
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 137 |
} |
136 |
} |
| 138 |
T control = getControlInstance(controlDescription,itemPropertyDescriptor,context); |
137 |
T control = getControlInstance(controlDescription,itemPropertyDescriptor,context); |
| 139 |
|
138 |
|
| 140 |
|
|
|
| 141 |
return control; |
139 |
return control; |
| 142 |
} |
140 |
} |
|
|
141 |
|
| 143 |
/** |
142 |
/** |
| 144 |
* {@inheritDoc} |
143 |
* {@inheritDoc} |
| 145 |
*/ |
144 |
*/ |
| 146 |
public <T extends ECPControl> T createControl(IItemPropertyDescriptor itemPropertyDescriptor, |
145 |
public <T extends ECPControl> T createControl(IItemPropertyDescriptor itemPropertyDescriptor, |
| 147 |
ECPControlContext context, String controlId) { |
146 |
ECPControlContext context, String controlId) { |
| 148 |
|
147 |
|
| 149 |
ECPControlDescription controlDescription = null; |
148 |
ECPControlDescription controlDescription = null; |
| 150 |
for(ECPControlDescription desc:controlDescriptors){ |
149 |
for(ECPControlDescription desc:controlDescriptors){ |
| 151 |
if(desc.getId().equals(controlId)){ |
150 |
if(desc.getId().equals(controlId)){ |
|
Lines 158-164
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 158 |
} |
157 |
} |
| 159 |
T control = getControlInstance(controlDescription,itemPropertyDescriptor,context); |
158 |
T control = getControlInstance(controlDescription,itemPropertyDescriptor,context); |
| 160 |
|
159 |
|
| 161 |
|
160 |
|
| 162 |
return control; |
161 |
return control; |
| 163 |
} |
162 |
} |
| 164 |
|
163 |
|
|
Lines 198-217
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 198 |
int highestPriority = -1; |
197 |
int highestPriority = -1; |
| 199 |
ECPControlDescription bestCandidate = null; |
198 |
ECPControlDescription bestCandidate = null; |
| 200 |
for (ECPControlDescription description : controlDescriptors) { |
199 |
for (ECPControlDescription description : controlDescriptors) { |
| 201 |
|
200 |
|
| 202 |
if(!controlClass.isAssignableFrom(description.getControlClass())){ |
201 |
if(!controlClass.isAssignableFrom(description.getControlClass())){ |
| 203 |
continue; |
202 |
continue; |
| 204 |
} |
203 |
} |
| 205 |
int currentPriority=-1; |
204 |
int currentPriority=-1; |
| 206 |
|
205 |
|
| 207 |
for(ECPApplicableTester tester:description.getTester()){ |
206 |
for(ECPApplicableTester tester:description.getTester()){ |
| 208 |
int testerPriority=tester.isApplicable(itemPropertyDescriptor, modelElement); |
207 |
int testerPriority=tester.isApplicable(itemPropertyDescriptor, modelElement); |
| 209 |
if(testerPriority>currentPriority){ |
208 |
if(testerPriority>currentPriority){ |
| 210 |
currentPriority=testerPriority; |
209 |
currentPriority=testerPriority; |
| 211 |
} |
210 |
} |
| 212 |
|
211 |
|
| 213 |
} |
212 |
} |
| 214 |
|
213 |
|
| 215 |
if(currentPriority>highestPriority){ |
214 |
if(currentPriority>highestPriority){ |
| 216 |
highestPriority=currentPriority; |
215 |
highestPriority=currentPriority; |
| 217 |
bestCandidate=description; |
216 |
bestCandidate=description; |
|
Lines 220-226
public final class ControlFactoryImpl implements ECPControlFactory{
Link Here
|
| 220 |
return bestCandidate; |
219 |
return bestCandidate; |
| 221 |
} |
220 |
} |
| 222 |
|
221 |
|
| 223 |
|
|
|
| 224 |
|
| 225 |
|
| 226 |
} |
222 |
} |