/
domainSpecificationDiagram.mtl
103 lines (91 loc) · 4.84 KB
/
domainSpecificationDiagram.mtl
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
[comment encoding = UTF-8 /]
[comment
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 1.0
* which is available at http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Simple
*/
/]
[module domainSpecificationDiagram ('http://org.eclipse.lyo/oslc4j/adaptorInterface', 'http://www.eclipse.org/sirius/diagram/1.1.0')/]
[query public visibleResources (diagram : DSemanticDiagram) : Sequence(Resource) =
(diagram.containers->select(c : DDiagramElementContainer | (Sequence{'Specification.DomainSpecification.Resource', 'DomainSpecification.Resource'}->includes(c.actualMapping.name))._and(c.visible)))
.target.oclAsType(Resource)
/]
[query public isLiteral(aResourceProperty : ResourceProperty) : Boolean =
not Sequence{ResourcePropertyValueType::Resource, ResourcePropertyValueType::LocalResource}->includes(aResourceProperty.valueType)
/]
[query public literalResourceProperties(aResource : Resource) : Set(ResourceProperty) =
aResource.resourceProperties->select(p : ResourceProperty | p.isLiteral())
/]
[query public referenceResourceProperties(aResource : Resource) : Set(ResourceProperty) =
aResource.resourceProperties->select(p : ResourceProperty | not p.isLiteral())
/]
[comment We want to list all literal properties. We also want to list reference properties whose range is not set (since they cannot be shown as an arrow, pointing to nowhere) /]
[query public propertiesAsSubnodes(aResource : Resource) : Set(ResourceProperty) =
aResource.resourceProperties->select(p : ResourceProperty |
(p.isLiteral())
or ((not p.isLiteral()) and (p.range->size() = 0)))
/]
[comment We want to list reference properties that have range resources not visible in the diagram (since they cannot be shown as an arrow, pointing to nowhere) /]
[query public referencePropertiesAsSubnodes(aResource : Resource, diagram : DSemanticDiagram) : Set(ResourceProperty) =
aResource.referenceResourceProperties()
->select(p : ResourceProperty | not visibleResources(diagram)->includesAll(p.range))
/]
[query public labelAsResourceSubnode(aResourceProperty : ResourceProperty, propertyView : DDiagramElement) : String =
(if (aResourceProperty.eContainer(DomainSpecification) = propertyView.eContainer().oclAsType(DNodeList).target.oclAsType(Resource).eContainer(DomainSpecification))
then ''
else aResourceProperty.eContainer(DomainSpecification).namespacePrefix.name + ':'
endif)
+ aResourceProperty.labelInDomainSpecification()
/]
[query public labelInDomainSpecification(aResourceProperty : ResourceProperty) : String =
name
+ ': '
+ (if (aResourceProperty.isLiteral())
then valueType
else (if (range->size() = 0) then 'Resource' else range->first().name + (if (range->size() > 1) then '++' else '' endif) endif)
endif)
+ (if (Sequence{ResourcePropertyOccurs::oneOrMany, ResourcePropertyOccurs::zeroOrMany}->includes(occurs)) then ' []' else '' endif)
/]
[query public labelAtArrowCenter(aResourceProperty : ResourceProperty, propertyView : DEdge) : String =
(if (aResourceProperty.valueType = ResourcePropertyValueType::LocalResource) then 'Local: ' else '' endif)
+
(if (aResourceProperty.eContainer(DomainSpecification) = propertyView.sourceNode.oclAsType(DNodeList).target.oclAsType(Resource).eContainer(DomainSpecification))
then ''
else aResourceProperty.eContainer(DomainSpecification).namespacePrefix.name + ':'
endif)
+ aResourceProperty.name
/]
[query public labelAtArrowEnd(aResourceProperty : ResourceProperty) : String =
(if (aResourceProperty.occurs = ResourcePropertyOccurs::exactlyOne)
then '1'
else if (aResourceProperty.occurs = ResourcePropertyOccurs::zeroOrOne)
then '0..1'
else if (aResourceProperty.occurs = ResourcePropertyOccurs::zeroOrMany)
then '0..*'
else if (aResourceProperty.occurs = ResourcePropertyOccurs::oneOrMany)
then '1..*'
else '???'
endif endif endif endif)
/]
[comment If at least one parent resource is not visible in the diagram, show textually the parent resources.
Show at least the first invisible parent resource./]
[query public labelInDomainSpecification(aResource : Resource, diagram : DSemanticDiagram) : String =
let invisibleParentResources : OrderedSet(Resource) = aResource.extends->select(parent : Resource | not(visibleResources(diagram)->includes(parent))) in
aResource.name +
(if (invisibleParentResources->size() = 0)
then
''
else
(lineSeparator() + 'extends: ' + invisibleParentResources->first().name) +
(if (invisibleParentResources->size() > 1) then ' & ...' else '' endif)
endif)
/]