Skip to content

Commit

Permalink
[261] Change InterfaceUsage container in Interconnection View
Browse files Browse the repository at this point in the history
The InterfaceUsage created by the New interface edge tool in the
Interconnection View diagram are now created under closest containing
Definition/Package.

Bug: #261
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD committed Jul 19, 2024
1 parent ac7cc09 commit 47c97ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
}

0 comments on commit 47c97ad

Please sign in to comment.