Skip to content

Commit 80781d4

Browse files
flatombeAxelRICHARD
authored andcommitted
[960] Display possible 'stakeholder' PartUsages in a tree
In the General View diagram, the creation tool for StakeholderParameter now shows possible candidate PartUsages in a tree instead of a flat list. Bug: #960 Signed-off-by: Florent Latombe <florent.latombe@obeo.fr>
1 parent 359b339 commit 80781d4

File tree

5 files changed

+87
-10
lines changed

5 files changed

+87
-10
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The changes are:
4747
- https://github.com/eclipse-syson/syson/issues/946[#946] [libraries] All standard libraries have been updated to comply with the SysML Beta 2.3 specification.
4848
- https://github.com/eclipse-syson/syson/issues/982[#982] [metamodel] `Membership#isDistinguishableFrom` derived attribute has been implemented.
4949
- https://github.com/eclipse-syson/syson/issues/992[#992] [export] Implement SysML export of `ConcernDefinition`, `ConcernUsage` and `StakeholderMembership`
50+
- https://github.com/eclipse-syson/syson/issues/960[#960] [general-view] In the selection dialog of the creation tool for 'StakeholderParameter', display possible PartUsage candidates in a tree instead of a list.
5051

5152
=== New features
5253

backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/services/ViewToolService.java

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import java.text.MessageFormat;
1616
import java.util.ArrayList;
17+
import java.util.Comparator;
1718
import java.util.HashSet;
19+
import java.util.Iterator;
1820
import java.util.List;
1921
import java.util.Map;
2022
import java.util.Map.Entry;
@@ -23,8 +25,8 @@
2325
import java.util.Set;
2426
import java.util.stream.Stream;
2527

26-
import org.eclipse.emf.common.util.TreeIterator;
2728
import org.eclipse.emf.ecore.EClass;
29+
import org.eclipse.emf.ecore.EClassifier;
2830
import org.eclipse.emf.ecore.EObject;
2931
import org.eclipse.emf.ecore.resource.Resource;
3032
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -1129,11 +1131,11 @@ public List<Resource> getNamespaceImportSelectionDialogElements(IEditingContext
11291131
.map(IEMFEditingContext.class::cast)
11301132
.map(IEMFEditingContext::getDomain)
11311133
.map(EditingDomain::getResourceSet);
1132-
var resouces = optionalResourceSet.map(resourceSet -> resourceSet.getResources().stream()
1133-
.filter(this::containsPackage)
1134+
var resources = optionalResourceSet.map(resourceSet -> resourceSet.getResources().stream()
1135+
.filter(resource -> containsDirectlyOrIndirectlyInstancesOf(resource, SysmlPackage.eINSTANCE.getPackage()))
11341136
.toList())
11351137
.orElseGet(ArrayList::new);
1136-
return resouces.stream().sorted((r1, r2) -> this.getResourceName(r1).compareTo(this.getResourceName(r2))).toList();
1138+
return resources.stream().sorted((r1, r2) -> getResourceName(r1).compareTo(getResourceName(r2))).toList();
11371139
}
11381140

11391141
/**
@@ -1159,16 +1161,25 @@ public List<Package> getNamespaceImportSelectionDialogChildren(Object self) {
11591161
return result;
11601162
}
11611163

1162-
private boolean containsPackage(Resource resource) {
1164+
private static boolean containsDirectlyOrIndirectlyInstancesOf(Resource resource, EClassifier eClassifier) {
11631165
boolean found = false;
1164-
TreeIterator<EObject> allContents = resource.getAllContents();
1166+
final Iterator<EObject> allContents = resource.getAllContents();
11651167
while (!found && allContents.hasNext()) {
1166-
found = allContents.next() instanceof Package;
1168+
found = eClassifier.isInstance(allContents.next());
11671169
}
11681170
return found;
11691171
}
11701172

1171-
private String getResourceName(Resource resource) {
1173+
private static boolean containsDirectlyOrIndirectlyInstancesOf(EObject eObject, EClassifier eClassifier) {
1174+
boolean found = false;
1175+
final Iterator<EObject> allContents = eObject.eAllContents();
1176+
while (!found && allContents.hasNext()) {
1177+
found = eClassifier.isInstance(allContents.next());
1178+
}
1179+
return found;
1180+
}
1181+
1182+
private static String getResourceName(Resource resource) {
11721183
return resource.eAdapters().stream()
11731184
.filter(ResourceMetadataAdapter.class::isInstance)
11741185
.map(ResourceMetadataAdapter.class::cast)
@@ -1192,4 +1203,63 @@ private List<Package> findClosestPackageInChildren(Element element) {
11921203
}
11931204
return result;
11941205
}
1206+
1207+
/**
1208+
* Provides the root elements in the tree of the selection dialog for the StakeholderParameter creation tool.
1209+
*
1210+
* @param editingContext
1211+
* the (non-{@code null}) {@link IEditingContext}.
1212+
* @return the (non-{@code null}) {@link List} of all {@link Resource} that contain at least one {@link PartUsage}.
1213+
*/
1214+
public List<Resource> getStakeholderSelectionDialogElements(IEditingContext editingContext) {
1215+
return getAllResourcesWithInstancesOf(editingContext, SysmlPackage.eINSTANCE.getPartUsage());
1216+
}
1217+
1218+
/**
1219+
* Provides the children of element in the tree of the selection dialog for the StakeholderParameter creation tool.
1220+
*
1221+
* @param selectionDialogTreeElement
1222+
* a (non-{@code null}) selection dialog tree element.
1223+
* @return the (non-{@code null}) {@link List} of all children that contain (possibly indirectly) or are
1224+
* {@link PartUsage}.
1225+
*/
1226+
public List<? extends Object> getStakeholderSelectionDialogChildren(Object selectionDialogTreeElement) {
1227+
return getChildrenWithInstancesOf(selectionDialogTreeElement, SysmlPackage.eINSTANCE.getPartUsage());
1228+
}
1229+
1230+
private static List<Resource> getAllResourcesWithInstancesOf(IEditingContext editingContext, EClassifier eClassifier) {
1231+
Objects.requireNonNull(editingContext);
1232+
1233+
var maybeResourceSet = Optional.of(editingContext)
1234+
.filter(IEMFEditingContext.class::isInstance)
1235+
.map(IEMFEditingContext.class::cast)
1236+
.map(IEMFEditingContext::getDomain)
1237+
.map(EditingDomain::getResourceSet);
1238+
var resourcesContainingPartUsage = maybeResourceSet.map(resourceSet -> resourceSet.getResources().stream()
1239+
.filter(resource -> containsDirectlyOrIndirectlyInstancesOf(resource, eClassifier))
1240+
.toList())
1241+
.orElseGet(ArrayList::new);
1242+
return resourcesContainingPartUsage.stream().sorted(Comparator.comparing(ViewToolService::getResourceName)).toList();
1243+
}
1244+
1245+
private static List<? extends Object> getChildrenWithInstancesOf(Object selectionDialogTreeElement, EClassifier eClassifier) {
1246+
Objects.requireNonNull(selectionDialogTreeElement);
1247+
1248+
final List<? extends Object> result;
1249+
1250+
if (selectionDialogTreeElement instanceof Resource resource) {
1251+
result = resource.getContents().stream()
1252+
.filter(content -> eClassifier.isInstance(content) || containsDirectlyOrIndirectlyInstancesOf(content, eClassifier)).toList();
1253+
} else if (selectionDialogTreeElement instanceof Element sysmlElement) {
1254+
return sysmlElement.getOwnedRelationship().stream()
1255+
.filter(Membership.class::isInstance)
1256+
.map(Membership.class::cast)
1257+
.map(Membership::getOwnedRelatedElement).flatMap(List::stream)
1258+
.filter(content -> eClassifier.isInstance(content) || containsDirectlyOrIndirectlyInstancesOf(content, eClassifier)).toList();
1259+
} else {
1260+
result = new ArrayList<>();
1261+
}
1262+
1263+
return result;
1264+
}
11951265
}

backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/StakeholdersCompartmentNodeToolProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ protected String getServiceCallExpression() {
3333
@Override
3434
protected SelectionDialogDescription getSelectionDialogDescription() {
3535
var selectionDialogTree = this.diagramBuilderHelper.newSelectionDialogTreeDescription()
36-
.elementsExpression(AQLUtils.getSelfServiceCallExpression("getAllReachableItems"))
36+
.elementsExpression(AQLUtils.getServiceCallExpression("editingContext", "getStakeholderSelectionDialogElements"))
37+
.childrenExpression(AQLUtils.getSelfServiceCallExpression("getStakeholderSelectionDialogChildren"))
38+
.isSelectableExpression("aql:self.oclIsKindOf(sysml::PartUsage)")
3739
.build();
3840
return this.diagramBuilderHelper.newSelectionDialogDescription()
3941
.selectionDialogTreeDescription(selectionDialogTree)
40-
.selectionMessage("Select an existing Item as stakeholder:")
42+
.selectionMessage("Select an existing Part as stakeholder:")
4143
.build();
4244
}
4345

39.4 KB
Loading

doc/content/modules/user-manual/pages/release-notes/2025.2.0.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ image::release-notes-gv-concern-usage.png[Concern Usage node creation tool, widt
8989

9090
image::release-notes-gv-stakeholders.png['stakeholders' compartment, width=50%, height=50%]
9191

92+
- In the `General View` diagram, the stakeholder creation tool displays available `Part Usage` in a tree instead of a list.
93+
94+
image::release-notes-gv-stakeholder-creation-selection-dialog-tree.png['stakeholder creation tool selection dialog tree' compartment, width=50%, height=50%]
95+
9296
- Prevent the edition of imported user libraries from the details view.
9397
- Align metamodel to SysMLv2 and KerML Beta 2.3 specifications.
9498
The changes are:

0 commit comments

Comments
 (0)