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
|
/*****************************************************************************
* Copyright (c) 2010, 2014 CEA LIST 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 417409
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.modelelement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.uml.properties.Activator;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement;
import org.eclipse.papyrus.views.properties.modelelement.EMFModelElementFactory;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
/**
* A Factory for building {@link StereotypeModelElement}s
*
* Problem : There may be conflicts when more than one stereotype is applied, when
* retrieving properties of a common sub-stereotype. There is currently no way to
* distinguish the two stereotypes, as it is the name of the subtype that is used
* in such a case.
* For example, if B inherits A and C inherits A, and A has a property "name", the
* propertyPath in the XWT File will be : A:name
* If the UML Element has both stereotypes B and C, we don't know if A:name corresponds
* to B:name or C:name
*
* TODO : enable the framework to handle B:name and C:name (Currently not possible,
* as "name" is not directly a property of B nor C)
* The problem probably comes from the Stereotype generator, which uses the same
* inheritance mechanism as the Ecore generator, and not from the framework itself
*
* @author Camille Letavernier
*/
public class StereotypeModelElementFactory extends EMFModelElementFactory {
@Override
protected EMFModelElement doCreateFromSource(Object source, DataContextElement context) {
Element umlElement = UMLUtil.resolveUMLElement(source);
if(umlElement != null) {
Stereotype stereotype = UMLUtil.getAppliedStereotype(umlElement, getQualifiedName(context), false);
EObject stereotypeApplication = umlElement.getStereotypeApplication(stereotype);
if(stereotypeApplication == null) {
Activator.log.warn("Stereotype " + getQualifiedName(context) + " is not applied on " + umlElement); //$NON-NLS-1$ //$NON-NLS-2$
} else {
EditingDomain domain = EMFHelper.resolveEditingDomain(stereotypeApplication);
return new StereotypeModelElement(stereotypeApplication, stereotype, domain);
}
}
return null;
}
/**
* Returns the DataContextElement's qualified name (Which should correspond
* to the stereotype's qualified name)
*
* @param context
* The DataContextElement representing the Stereotype
* @return
* The DataContextElement's name, which is also the Stereotype's qualified name
*/
protected String getQualifiedName(DataContextElement context) {
if(context.getPackage() == null) {
return context.getName();
} else {
return getQualifiedName(context.getPackage()) + "::" + context.getName(); //$NON-NLS-1$
}
}
}
|