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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
modeltype XML uses "http://www.eclipse.org/papyrus/xwt/XML";
modeltype UI uses "http://www.eclipse.org/papyrus/properties/ui/0.9";
modeltype PropertiesRoot uses "http://www.eclipse.org/papyrus/properties/root";
modeltype Context uses "http://www.eclipse.org/papyrus/properties/contexts/0.9";
modeltype Environment uses "http://www.eclipse.org/papyrus/properties/environment/0.9";
transformation XMLToUI(in xml : XML, in root : PropertiesRoot, in ctx : Context, out ui : UI);
main() {
xml.rootObjects()[Node]->map toUIElement();
}
mapping Node::toAttribute() : WidgetAttribute
disjuncts
Namespace::toValueAttribute,
Attribute::toValueAttribute,
XML::Element::toReferenceAttribute{
}
mapping Attribute::toValueAttribute() : ValueAttribute
when {not self.isProperty()} {
result.name := self.name;
result.value := self.value;
}
query Attribute::isProperty() : Boolean {
return self.parent.isPropertyEditor() and self.name = "property";
}
mapping XML::Namespace::toValueAttribute() : ValueAttribute{
result.name := if self.name.oclIsUndefined() or self.name = ""
then "xmlns"
else "xmlns:"+self.name
endif;
result.value := self.value;
}
//layout is a ReferenceAttribute but is computed differently
mapping XML::Element::toReferenceAttribute() : ReferenceAttribute
when {self.isReferenceAttribute() and not self.isLayoutAttribute()}{
result.name := self.getName();
result.value := self.children->select(e | e.oclIsKindOf(XML::Element))
->first().oclAsType(XML::Element).map toUIComponent();
}
query XML::Element::isReferenceAttribute() : Boolean {
return self.name.startsWith(self.parent.name+".");
}
query XML::Element::getName() : String {
var parentPrefix := self.parent.name+".";
if self.name.startsWith(parentPrefix) then
return self.name.replace(parentPrefix, "")
endif;
return self.name;
}
mapping Node::toUIElement() : UI::Element
disjuncts
XML::Element::toUIComponent,
XML::Node::toAttribute {
}
mapping XML::Element::toUIComponent() : UIComponent
disjuncts
XML::Element::toWidget,
XML::Element::toLayout{
}
mapping XML::Element::toWidget() : Widget
disjuncts
XML::Element::toComposite,
XML::Element::toPropertyEditor,
XML::Element::toStandardWidget,
XML::Element::toUnknownComponent{
}
abstract mapping XML::Element::toAbstractUIComponent() : UIComponent {
var allChildren : Set(Node) := self.children;
if self.oclIsKindOf(Root) then
allChildren := allChildren->union(self.oclAsType(Root).namespaces)
endif;
attributes := allChildren->map toAttribute();
}
mapping XML::Element::toComposite() : CompositeWidget inherits XML::Element::toAbstractUIComponent
when {self.isComposite()} {
widgetType := self.getCompositeType();
var elements := self.children->select(e | e.oclIsKindOf(XML::Element))
.oclAsType(XML::Element);
layout := elements->select(e | e.isLayoutAttribute()).children
->select(e | e.oclIsKindOf(XML::Element)).oclAsType(XML::Element)
->select(e | e.isLayout())->first().map toLayout();
widgets := elements->select(e | e.isWidget())->map toWidget();
}
mapping XML::Element::toLayout() : Layout inherits XML::Element::toAbstractUIComponent
when {self.isLayout()} {
layoutType := self.getLayoutType();
}
mapping XML::Element::toStandardWidget() : StandardWidget inherits XML::Element::toAbstractUIComponent
when {self.isStandardWidget() and not self.getWidgetType().oclIsUndefined()}{
widgetType := self.getWidgetType();
}
mapping XML::Element::toUnknownComponent() : UnknownComponent inherits XML::Element::toAbstractUIComponent
when {self.getWidgetType().oclIsUndefined()}{
typeName := self.name;
}
mapping XML::Element::toPropertyEditor() : PropertyEditor inherits XML::Element::toAbstractUIComponent
when {self.isPropertyEditor()}{
widgetType := self.getPropertyEditorType();
var prop := findProperty(self.getPropertyName());
if prop.oclIsUndefined() then
prop := object UnknownProperty {
name := self.getPropertyName();
}
endif;
_property := prop;
//Remove the readOnly and showLabel Attributes, as they are actual properties (i.e. not generic) in the UI Model
//Avoids dupplication of the attribute
var readOnlyAttribute := result.attributes->any(e | e.name = "readOnly");
var showLabelAttribute := result.attributes->any(e | e.name = "showLabel");
var customLabelAttribute := result.attributes->any(e | e.name = "customLabel");
result.attributes := result.attributes->excluding(readOnlyAttribute)->excluding(showLabelAttribute)->excluding(customLabelAttribute);
unresolvedProperty := prop.oclAsType(UnknownProperty);
readOnly := self.children->exists(e | e.oclIsKindOf(XML::Attribute) and e.oclAsType(XML::Attribute).name = 'readOnly' and e.oclAsType(XML::Attribute).value='true');
showLabel := not self.children->exists(e | e.oclIsKindOf(XML::Attribute) and e.oclAsType(XML::Attribute).name = 'showLabel' and e.oclAsType(XML::Attribute).value='false');
customLabel := self.children->any(e | e.oclIsKindOf(XML::Attribute) and e.oclAsType(XML::Attribute).name = 'customLabel').oclAsType(XML::Attribute).value;
}
query XML::Element::getPropertyName() : String {
var attributes := self.children->select(e | e.oclIsKindOf(Attribute)).oclAsType(Attribute);
var propertyName := attributes->any(e | e.name = "property").value;
return propertyName;
}
query findProperty(propertyName : String) : Property {
var prefix := propertyName.substring(1, propertyName.indexOf(":")-1);
var allContexts := ctx.rootObjects()[Context::Context];
var validDataContexts := allContexts.dataContexts->select(f | f.name = prefix);
var prop := findProperty(propertyName.substring(propertyName.indexOf(":")+1, propertyName.size()), validDataContexts->any(e | true));
return prop;
}
query findProperty(propertyName : String, element : DataContextElement) : Property{
if propertyName.indexOf(":") > 0
then {
var packageName := propertyName.substring(1, propertyName.indexOf(":")-1);
var propertyNameSuffix := propertyName.substring(propertyName.indexOf(":")+1, propertyName.size());
var package := element.oclAsType(DataContextPackage).elements->any(e | e.name = packageName);
return findProperty(propertyNameSuffix, package);
} else {
return element.properties->any(e | e.name = propertyName);
} endif;
return null;
}
query XML::Element::match(widgetClass : String, namespace : Environment::Namespace) : Boolean{
return self.name.getSimpleName() = widgetClass
and ((self.name.getNamespace() = '' and namespace.oclIsUndefined())
or self.name.getNamespace() = namespace.name
)
}
query XML::Element::isWidget() : Boolean {
return not (self.isLayout() or self.isReferenceAttribute());
}
query XML::Element::isComposite() : Boolean {
var composites = root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.compositeWidgetTypes;
return composites->exists(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::isStandardWidget() : Boolean {
var stdWidgets := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.widgetTypes;
return stdWidgets->exists(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::isPropertyEditor() : Boolean {
var editors := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.propertyEditorTypes;
return editors->exists(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::isLayout() : Boolean {
var layouts := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.layoutTypes;
return layouts->exists(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::isLayoutAttribute() : Boolean {
var res := self.name = self.parent.name+".layout";
return res;
}
/*
Returns the simple name from the given String
The namespace is truncated
ppe:StringEditor -> StringEditor
*/
query String::getSimpleName() : String {
var simpleName := if self.indexOf(':') < 1 then
self
else
self.substring(self.indexOf(':')+1, self.length())
endif;
return simpleName;
}
/*
Returns the namespace prefix from the given String, if any
ppe:StringEditor -> ppe
*/
query String::getNamespace() : String {
var namespace := if self.indexOf(':') < 1 then
''
else
self.substring(1, self.indexOf(':') - 1)
endif;
return namespace;
}
query XML::Element::getWidgetType() : StandardWidgetType {
var stdWidgets := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.widgetTypes;
return stdWidgets->any(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::getCompositeType() : CompositeWidgetType {
var composites := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.compositeWidgetTypes;
return composites->any(e | self.match(e.widgetClass, e.namespace));
}
query XML::Element::getPropertyEditorType() : PropertyEditorType {
var editors := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.propertyEditorTypes;
var type := editors->any(e | self.match(e.widgetClass, e.namespace));
return type;
}
query XML::Element::getLayoutType() : LayoutType {
var layouts := root.rootObjects()[PropertiesRoot::PropertiesRoot].environments.layoutTypes;
return layouts->any(e | self.match(e.widgetClass, e.namespace));
}
|