Skip to content

Commit

Permalink
Add validation rule on invalid extension by inheritance.
Browse files Browse the repository at this point in the history
  • Loading branch information
peransin-obeo committed Jun 19, 2024
1 parent a862da0 commit 4c091b7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 35 deletions.
6 changes: 3 additions & 3 deletions parent/tpd/sdk.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="Capella Viewpoint Extension tools - SDK" sequenceNumber="1718724612">
<target name="Capella Viewpoint Extension tools - SDK" sequenceNumber="1718819781">
<locations>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.gmf.runtime.notation.sdk.feature.group" version="1.13.1.202211151334"/>
Expand Down Expand Up @@ -68,8 +68,8 @@
<repository id="sirius" location="https://download.eclipse.org/sirius/updates/releases/7.1.0/2021-06/"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.mypsycho.emf.modit_feature.feature.group" version="1.3.0.v20240612-0934"/>
<unit id="org.mypsycho.emf.modit.sirius_feature.feature.group" version="1.3.0.v20240612-0934"/>
<unit id="org.mypsycho.emf.modit_feature.feature.group" version="1.3.0.v20240619-1707"/>
<unit id="org.mypsycho.emf.modit.sirius_feature.feature.group" version="1.3.0.v20240619-1707"/>
<repository id="modit" location="https://mypsycho.github.io/ModIt/releases/v1.3"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<edgeMappings name="emdeExtension" deletionDescription="//@ownedViewpoints[name='CapellaVp']/@ownedRepresentationExtensions[name='EntitiesDiagramExtension']/@layers[name='Capella%20Extension']/@toolSections.1/@ownedTools[name='emdeExtensionDel']" targetFinderExpression="aql:self.eAnnotations ->select(it | it.source = 'http://www.polarsys.org/kitalpha/emde/1.0.0/constraintMapping') .getEmdeAnnotationElement()">
<sourceMapping xsi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/>
<targetMapping xsi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/>
<style targetArrow="OutputFillClosedArrow" routingStyle="manhattan" endsCentering="Both">
<style targetArrow="OutputFillClosedArrow" routingStyle="manhattan">
<strokeColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</style>
</edgeMappings>
Expand Down Expand Up @@ -82,6 +82,9 @@
<decorationDescriptions xsi:type="description_1:MappingBasedDecoration" name="ExtensionHint" position="NORTH_EAST" distributionDirection="HORIZONTAL" preconditionExpression="aql:self.isEmdeExtensionClass()" imageExpression="/com.obeonetwork.mbse.capella.vpx.design/icons/extension.png">
<mappings xsi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/>
</decorationDescriptions>
<decorationDescriptions xsi:type="description_1:MappingBasedDecoration" name="HiddenExtensions" position="NORTH_EAST" distributionDirection="HORIZONTAL" preconditionExpression="aql:self.containHiddenExtensions()" imageExpression="/org.eclipse.jface/org/eclipse/jface/dialogs/images/message_error.png" tooltipExpression="aql:'EMDE only consider extension of first superclass.\n Change supertypes order or add explicit extension.'">
<mappings xsi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/>
</decorationDescriptions>
</decorationDescriptionsSet>
<customization>
<vsmElementCustomizations xsi:type="description:VSMElementCustomization" predicateExpression="aql:self.isCapellaEcore(null)">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* *
/* * *
* Copyright (c) 2013 Obeo.
* 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:
* Obeo - initial API and implementation */
* Obeo - initial API and implementation
* * */
package com.obeonetwork.mbse.capella.vpx.design;

import java.lang.reflect.InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@
public class VpToolsServices {

private static final String CP_MODEL_PLUGIN = "org.polarsys.capella.core.data.gen";

private static final String URI_BASE = "platform:/plugin/" + CP_MODEL_PLUGIN + "/model/";
public static final String EXT_ANNOTATION =
"http://www.polarsys.org/kitalpha/emde/1.0.0/constraintMapping";
public static final String EXT_CLASS_KEY = "Mapping";

public static final String EXT_ANNOTATION2 =
"http://www.polarsys.org/kitalpha/emde/1.0.0/constraint";
public static final String EXT_CLASS_KEY2 = "ExtendedElement";
// Ecore
public static final String ECORE_ANNOTATION = "http://www.polarsys.org/kitalpha/emde/1.0.0/constraintMapping";

public static final String ECORE_CLASS_KEY = "Mapping";

// Qualified
public static final String QN_ANNOTATION = "http://www.polarsys.org/kitalpha/emde/1.0.0/constraint";

public static final String QN_CLASS_KEY = "ExtendedElement";

public static final String EMDE_ECORE = "org.polarsys.kitalpha.emde/model/eMDE.ecore";

public static final URI EMDE_EXTENSION_URI = URI // appendFragment avoids '#' encoding
.createPlatformPluginURI(EMDE_ECORE, false)
.appendFragment("//ElementExtension");
Expand Down Expand Up @@ -98,7 +103,7 @@ public static boolean isCapellaEcore(EClass it, String module) {
* @return associated EClass
*/
public static EClass getEmdeAnnotationElement(EAnnotation it) {
String classUri = it.getDetails().get(EXT_CLASS_KEY);
String classUri = it.getDetails().get(ECORE_CLASS_KEY);
if (classUri == null) {
return null;
}
Expand Down Expand Up @@ -136,10 +141,10 @@ public static boolean isInLibrary(EModelElement it) {
* @return extension
*/
public static EClass addEmdeExtensions(EClass extension, EClass extended) {
createEAnnotation(extension, EXT_ANNOTATION2).getDetails()
.put(EXT_CLASS_KEY2, getQualifiedName(extended));
createEAnnotation(extension, EXT_ANNOTATION).getDetails()
.put(EXT_CLASS_KEY, EcoreUtil.getURI(extended).toString());
createEAnnotation(extension, QN_ANNOTATION).getDetails()
.put(QN_CLASS_KEY, getQualifiedName(extended));
createEAnnotation(extension, ECORE_ANNOTATION).getDetails()
.put(ECORE_CLASS_KEY, EcoreUtil.getURI(extended).toString());

EClass extensionClass = getEClass(extension, EMDE_EXTENSION_URI);
if (!extension.getEAllSuperTypes().contains(extensionClass)) {
Expand Down Expand Up @@ -170,7 +175,7 @@ private static EAnnotation createEAnnotation(EClass target, String source) {
* @return true if is expected annotation
*/
public static boolean isEmdeConstraintExtensionOf(EAnnotation it, EClass target) {
return isEmdeExtensionOf(it, EXT_ANNOTATION2, EXT_CLASS_KEY2,
return isEmdeExtensionOf(it, QN_ANNOTATION, QN_CLASS_KEY,
getQualifiedName(target));
}

Expand All @@ -184,7 +189,7 @@ public static boolean isEmdeConstraintExtensionOf(EAnnotation it, EClass target)
* @return true if is expected annotation
*/
public static boolean isEmdeMappingExtensionOf(EAnnotation it, EClass target) {
return isEmdeExtensionOf(it, EXT_ANNOTATION, EXT_CLASS_KEY,
return isEmdeExtensionOf(it, ECORE_ANNOTATION, ECORE_CLASS_KEY,
EcoreUtil.getURI(target).toString());
}

Expand Down Expand Up @@ -226,4 +231,33 @@ static <T extends EObject> T eAncestor(EObject it, Class<T> type) {
: eAncestor(it.eContainer(), type);
}

public static boolean containHiddenExtensions(EClass it) {
if (it.getESuperTypes().size() < 2
|| containExtension(it, false)) { // Nothing hidden if explicit
return false;
}
return it.getESuperTypes()
.stream()
.skip(1)
.anyMatch(type -> containExtension(type, true));
}

static boolean containExtension(EClass it, boolean withParent) {
if (it.getEAnnotations()
.stream()
.anyMatch(ann -> Objects.equals(ann.getSource(), QN_ANNOTATION))) {
return true;
}
// Only first inheritance:
// https://github.com/eclipse/kitalpha/
// blob/v6.2.0/
// emde/plugins/org.polarsys.kitalpha.emde.model.edit/
// src/org/polarsys/kitalpha/emde/model/edit/provider/helpers/EMDEHelper.java#L187

// If a supertype is wrong, it will be displayed.
return withParent
&& !it.getESuperTypes().isEmpty()
&& containExtension(it.getESuperTypes().get(0), true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.eclipse.sirius.diagram.DiagramPackage
import org.eclipse.sirius.diagram.EdgeArrows
import org.eclipse.sirius.diagram.HideFilter
import org.eclipse.sirius.diagram.description.AdditionalLayer
import org.eclipse.sirius.diagram.description.CenteringStyle
import org.eclipse.sirius.diagram.description.ContainerMapping
import org.eclipse.sirius.diagram.description.DiagramDescription
import org.eclipse.sirius.diagram.description.DiagramExtensionDescription
Expand All @@ -25,7 +26,6 @@ import org.eclipse.sirius.diagram.description.style.StylePackage
import org.eclipse.sirius.diagram.description.tool.DeleteElementDescription
import org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription
import org.eclipse.sirius.diagram.description.tool.ToolSection
import org.eclipse.sirius.viewpoint.description.DecorationDescriptionsSet
import org.eclipse.sirius.viewpoint.description.DecorationDistributionDirection
import org.eclipse.sirius.viewpoint.description.Position
import org.eclipse.sirius.viewpoint.description.UserFixedColor
Expand All @@ -49,21 +49,40 @@ class EntitiesDiagramExtension extends SiriusDiagramExtension {

static val TO_EMDE_CLASSES = '''
.eAnnotations
->select(it | it.source = '«VpToolsServices.EXT_ANNOTATION»')
->select(it | it.source = '«VpToolsServices.ECORE_ANNOTATION»')
.getEmdeAnnotationElement()
'''

val ContainerMapping eClassMapping

new(extension CapellaVpDesign parent) {
super(parent, DiagramDescription.extraRef("etools§EntitiesDiagram"))
eClassMapping = ContainerMapping.extraRef("node:etools§EntitiesDiagram#EC EClass")
}

override initContent(DiagramExtensionDescription it) {

// Validation is not live unlike decorators ...
// (kind of useless)

// ownedValidations += ViewValidationRule.create("Lost Extensions") [
// level = ERROR_LEVEL.ERROR_LITERAL
// // https://github.com/eclipse/kitalpha/
// // blob/v6.2.0/
// // emde/plugins/org.polarsys.kitalpha.emde.model.edit/
// // src/org/polarsys/kitalpha/emde/model/edit/provider/helpers/EMDEHelper.java#L187
// message = ''' 'EMDE only consider extension of first superclass' '''.trimAql
// targets += eClassMapping
// validFor('''not self.target.containHiddenExtensions()'''.trimAql)
// ]


layers += AdditionalLayer.create("Capella Extension") [
label = "%capellavp.entities.layer"
activeByDefault = true
icon = CapellaVpDesign.ICONS + "Viewpoint.gif"

val eClassNode = ContainerMapping.extraRef("node:etools§EntitiesDiagram#EC EClass")
val eClassNode = eClassMapping

val colorCustoms = #[ "null" -> CapellaVpDesign.COMMON_ID ]
+ VpToolsServices.MODULE_NAMES
Expand All @@ -78,16 +97,26 @@ class EntitiesDiagramExtension extends SiriusDiagramExtension {
)
]

decorationDescriptionsSet = DecorationDescriptionsSet.create [
decorationDescriptions += MappingBasedDecoration.create [
name = "ExtensionHint"
position = Position.NORTH_EAST_LITERAL
distributionDirection = DecorationDistributionDirection.HORIZONTAL
preconditionExpression = '''self.isEmdeExtensionClass()'''.trimAql
imageExpression = CapellaVpDesign.ICONS + "extension.png"
mappings += eClassNode
]
decorations += MappingBasedDecoration.create [
name = "ExtensionHint"
position = Position.NORTH_EAST_LITERAL
distributionDirection = DecorationDistributionDirection.HORIZONTAL
preconditionExpression = '''self.isEmdeExtensionClass()'''.trimAql
imageExpression = CapellaVpDesign.ICONS + "extension.png"
mappings += eClassNode
]
decorations += MappingBasedDecoration.create [
name = "HiddenExtensions"
position = Position.NORTH_EAST_LITERAL
distributionDirection = DecorationDistributionDirection.HORIZONTAL
preconditionExpression = '''self.containHiddenExtensions()'''.trimAql
imageExpression = "/org.eclipse.jface/org/eclipse/jface/dialogs/images/message_error.png"
tooltipExpression = '''
'EMDE only consider extension of first superclass.\n
Change supertypes order or add explicit extension.' '''.trimAql
mappings += eClassNode
]


edgeMappings += EdgeMapping.createAs(Ns.edge, "emdeExtension") [
// domainClass = EAnnotation
Expand All @@ -100,9 +129,10 @@ class EntitiesDiagramExtension extends SiriusDiagramExtension {

targetFinderExpression = '''self«TO_EMDE_CLASSES»'''.trimAql

style = [
targetArrow = EdgeArrows.OUTPUT_FILL_CLOSED_ARROW_LITERAL
]
style = [
endsCentering = CenteringStyle.NONE
targetArrow = EdgeArrows.OUTPUT_FILL_CLOSED_ARROW_LITERAL
]
]

toolSections += createExistingElementsTools
Expand Down Expand Up @@ -181,7 +211,7 @@ class EntitiesDiagramExtension extends SiriusDiagramExtension {
'''.trimAql.letDo("classes",
'''classes«TO_EMDE_CLASSES» - classes'''.trimAql.forDo(
"service:markForAutosize".toContext(
ContainerMapping.extraRef("node:etools§EntitiesDiagram#EC EClass")
eClassMapping
.viewDo("diagram")
)
)
Expand Down

0 comments on commit 4c091b7

Please sign in to comment.