|
24 | 24 | import org.eclipse.emf.common.util.EList; |
25 | 25 | import org.eclipse.emf.ecore.EClass; |
26 | 26 | import org.eclipse.emf.ecore.EObject; |
27 | | -import org.eclipse.emf.ecore.EStructuralFeature; |
28 | 27 | import org.eclipse.sirius.components.collaborative.diagrams.DiagramContext; |
29 | 28 | import org.eclipse.sirius.components.collaborative.diagrams.DiagramService; |
30 | 29 | import org.eclipse.sirius.components.collaborative.diagrams.DiagramServices; |
@@ -315,41 +314,38 @@ public Node revealCompartment(Node node, Element targetElement, DiagramContext d |
315 | 314 | } |
316 | 315 |
|
317 | 316 | /** |
318 | | - * Check if the compartment associated to the given {@link Element} and reference should be hidden by default. |
| 317 | + * Check if the compartment associated to the given {@link Element} should be hidden by default. |
319 | 318 | * |
320 | 319 | * @param self |
321 | 320 | * the {@link Element} associated to the compartment node. |
322 | | - * @param referenceName |
323 | | - * the name of the reference associated to the compartment node. |
| 321 | + * @param compartmentName |
| 322 | + * the name of the compartment to display/hide by default |
| 323 | + * @param ancestors |
| 324 | + * the list of ancestors of the element (semantic elements corresponding to graphical ancestors). It |
| 325 | + * corresponds to a variable accessible from the variable manager. |
| 326 | + * @param editingContext |
| 327 | + * the {@link IEditingContext} of the element. It corresponds to a variable accessible from the variable |
| 328 | + * manager. |
| 329 | + * @param diagramContext |
| 330 | + * the {@link DiagramContext} of the element. It corresponds to a variable accessible from the variable |
| 331 | + * manager. |
324 | 332 | * @return <code>true</code> if the compartment should be hidden by default, <code>false</code> otherwise |
325 | 333 | */ |
326 | | - public boolean isHiddenByDefault(Element self, String referenceName) { |
| 334 | + public boolean isHiddenByDefault(Element self, String compartmentName, List<Object> ancestors, IEditingContext editingContext, DiagramContext diagramContext) { |
327 | 335 | boolean isHiddenByDefault = true; |
328 | | - EStructuralFeature eStructuralFeature = self.eClass().getEStructuralFeature(referenceName); |
329 | | - if (eStructuralFeature != null && eStructuralFeature != SysmlPackage.eINSTANCE.getDefinition_OwnedPort()) { |
330 | | - Object referenceValue = self.eGet(eStructuralFeature); |
331 | | - if (referenceValue instanceof List<?> referenceListValue) { |
332 | | - isHiddenByDefault = referenceListValue.isEmpty(); |
333 | | - } else { |
334 | | - isHiddenByDefault = referenceValue == null; |
| 336 | + // @technical-debt we should find a way to compute this compartment name here and in |
| 337 | + // InterconnectionCompartmentNodeDescriptionProvider only once. |
| 338 | + if ("GV Compartment interconnection FreeForm".equals(compartmentName)) { |
| 339 | + var exposedParts = this.getExposedElements(self, SysmlPackage.eINSTANCE.getPartUsage(), ancestors, editingContext, diagramContext); |
| 340 | + var exposedActions = this.getExposedElements(self, SysmlPackage.eINSTANCE.getActionUsage(), ancestors, editingContext, diagramContext); |
| 341 | + var exposedSatisfyRequirements = this.getExposedElements(self, SysmlPackage.eINSTANCE.getSatisfyRequirementUsage(), ancestors, editingContext, diagramContext); |
| 342 | + if (!exposedParts.isEmpty() || !exposedActions.isEmpty() || !exposedSatisfyRequirements.isEmpty()) { |
| 343 | + isHiddenByDefault = false; |
335 | 344 | } |
336 | 345 | } |
337 | 346 | return isHiddenByDefault; |
338 | 347 | } |
339 | 348 |
|
340 | | - /** |
341 | | - * Check if the compartment associated to the given {@link Element} and references should be hidden by default. |
342 | | - * |
343 | | - * @param self |
344 | | - * the {@link Element} associated to the compartment node. |
345 | | - * @param referenceNames |
346 | | - * the name of the references associated to the compartment node. |
347 | | - * @return <code>true</code> if the compartment should be hidden by default, <code>false</code> otherwise |
348 | | - */ |
349 | | - public boolean isHiddenByDefault(Element self, List<String> referenceNames) { |
350 | | - return referenceNames.stream().allMatch(referenceName -> this.isHiddenByDefault(self, referenceName)); |
351 | | - } |
352 | | - |
353 | 349 | /** |
354 | 350 | * Returns {@code true} if {@code parentNodeElement} is an ancestor of {@code childNodeElement}. |
355 | 351 | * <p> |
|
0 commit comments