From 47c97ada3bddd5bb4bf9c90c792852d4c25e8fd3 Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Fri, 19 Jul 2024 14:10:20 +0200 Subject: [PATCH] [261] Change InterfaceUsage container in Interconnection View The InterfaceUsage created by the New interface edge tool in the Interconnection View diagram are now created under closest containing Definition/Package. Bug: https://github.com/eclipse-syson/syson/issues/261 Signed-off-by: Axel RICHARD --- CHANGELOG.adoc | 9 ++++---- .../InterconnectionViewCreateService.java | 23 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 79c5bbb4b..e50909dd7 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -31,11 +31,12 @@ The changes are: === Improvements -- https://github.com/eclipse-syson/syson/issues/538[#538] [general-view] Add actions in PartUsage and PartDefinition -- https://github.com/eclipse-syson/syson/issues/554[#554] [general-view] Add states in PartUsage and PartDefinition +- https://github.com/eclipse-syson/syson/issues/538[#538] [general-view] Add actions in _PartUsage_ and _PartDefinition_ +- https://github.com/eclipse-syson/syson/issues/554[#554] [general-view] Add states in _PartUsage_ and _PartDefinition_ - https://github.com/eclipse-syson/syson/issues/393[#393] [general-view] Add exhibit states on General View diagram -- https://github.com/eclipse-syson/syson/issues/557[#557] [state-transition-view] Allow the creation of a StateTransitionView diagram on a PartUsage/PartDefinition -- https://github.com/eclipse-syson/syson/issues/558[#558] [state-transition-view] Allow the creation of a StateTransitionView diagram on a StateUsage/StateDefinition +- https://github.com/eclipse-syson/syson/issues/557[#557] [state-transition-view] Allow the creation of a StateTransitionView diagram on a _PartUsage_/_PartDefinition_ +- https://github.com/eclipse-syson/syson/issues/558[#558] [state-transition-view] Allow the creation of a StateTransitionView diagram on a _StateUsage_/_StateDefinition_ +- https://github.com/eclipse-syson/syson/issues/261[#261] [interconnection-view] The _InterfaceUsage_ created by the New Interface edge tool in the Interconnection View diagram are now created under closest containing Definition/Package. === New features diff --git a/backend/views/syson-diagram-interconnection-view/src/main/java/org/eclipse/syson/diagram/interconnection/view/services/InterconnectionViewCreateService.java b/backend/views/syson-diagram-interconnection-view/src/main/java/org/eclipse/syson/diagram/interconnection/view/services/InterconnectionViewCreateService.java index a5e25c154..b960cb5d8 100644 --- a/backend/views/syson-diagram-interconnection-view/src/main/java/org/eclipse/syson/diagram/interconnection/view/services/InterconnectionViewCreateService.java +++ b/backend/views/syson-diagram-interconnection-view/src/main/java/org/eclipse/syson/diagram/interconnection/view/services/InterconnectionViewCreateService.java @@ -17,11 +17,14 @@ import org.eclipse.syson.diagram.common.view.services.ViewCreateService; import org.eclipse.syson.diagram.interconnection.view.InterconnectionViewForUsageDiagramDescriptionProvider; import org.eclipse.syson.sysml.BindingConnectorAsUsage; +import org.eclipse.syson.sysml.Definition; +import org.eclipse.syson.sysml.Element; import org.eclipse.syson.sysml.EndFeatureMembership; import org.eclipse.syson.sysml.Feature; import org.eclipse.syson.sysml.FeatureMembership; import org.eclipse.syson.sysml.InterfaceUsage; import org.eclipse.syson.sysml.Namespace; +import org.eclipse.syson.sysml.Package; import org.eclipse.syson.sysml.PortUsage; import org.eclipse.syson.sysml.ReferenceSubsetting; import org.eclipse.syson.sysml.SysmlFactory; @@ -38,12 +41,12 @@ public InterconnectionViewCreateService(IViewDiagramDescriptionSearchService vie } public BindingConnectorAsUsage createBindingConnectorAsUsage(PortUsage sourcePort, PortUsage targetPort) { - Namespace owningNamespace = sourcePort.getOwningNamespace(); - if (owningNamespace == null) { + Namespace bindingContainer = this.getClosestContainingDefinitionOrPackageFrom(sourcePort); + if (bindingContainer == null) { return null; } FeatureMembership featureMembership = SysmlFactory.eINSTANCE.createFeatureMembership(); - owningNamespace.getOwnedRelationship().add(featureMembership); + bindingContainer.getOwnedRelationship().add(featureMembership); BindingConnectorAsUsage bindingConnectorAsUsage = SysmlFactory.eINSTANCE.createBindingConnectorAsUsage(); bindingConnectorAsUsage.setDeclaredName("bind"); @@ -71,12 +74,12 @@ public BindingConnectorAsUsage createBindingConnectorAsUsage(PortUsage sourcePor } public InterfaceUsage createInterfaceUsage(PortUsage sourcePort, PortUsage targetPort) { - Namespace owningNamespace = sourcePort.getOwningNamespace(); - if (owningNamespace == null) { + Namespace interfaceContainer = this.getClosestContainingDefinitionOrPackageFrom(sourcePort); + if (interfaceContainer == null) { return null; } FeatureMembership featureMembership = SysmlFactory.eINSTANCE.createFeatureMembership(); - owningNamespace.getOwnedRelationship().add(featureMembership); + interfaceContainer.getOwnedRelationship().add(featureMembership); InterfaceUsage interfaceUsage = SysmlFactory.eINSTANCE.createInterfaceUsage(); interfaceUsage.setDeclaredName("connect"); @@ -102,4 +105,12 @@ public InterfaceUsage createInterfaceUsage(PortUsage sourcePort, PortUsage targe return interfaceUsage; } + + private Namespace getClosestContainingDefinitionOrPackageFrom(Element element) { + var owner = element.eContainer(); + while (!(owner instanceof Package || owner instanceof Definition) && owner != null) { + owner = owner.eContainer(); + } + return (Namespace) owner; + } }