Skip to content

Commit f4650fa

Browse files
flatombeAxelRICHARD
authored andcommitted
[1357] Make read-only predicate support Resource and EAnnotation
* SysONReadOnlyObjectPredicateDelegate now supports Resource and EAnnotation. * Add unit tests for SysONReadOnlyObjectPredicateDelegate. * Update changelog and release notes accordingly. Bug: #1357 Signed-off-by: Florent Latombe <florent.latombe@obeo.fr>
1 parent fb70cbc commit f4650fa

File tree

4 files changed

+402
-13
lines changed

4 files changed

+402
-13
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ All existing SysON _DiagramDescriptions_ (i.g. _General View_, _Interconnection
9999
- https://github.com/eclipse-syson/syson/issues/1359[#1359] [export] Implement textual export of `ViewUsage`.
100100
- https://github.com/eclipse-syson/syson/issues/1350[#1350] [general-view] Improve _direct edit_ tool on `Feature` to be able to edit `FeatureValue` with basic expressions.
101101
- https://github.com/eclipse-syson/syson/issues/1363[#1363] [general-view] Add a reveal only valued content action on the manage visibility node action that will hide empty graphical compartments and will reveal the others.
102+
- https://github.com/eclipse-syson/syson/issues/1357[#1357] [syson] Add support for `Resource` and `EAnnotation` in `SysONReadOnlyObjectPredicateDelegate`.
102103

103104
=== New features
104105

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/services/SysONReadOnlyObjectPredicateDelegate.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import java.util.Objects;
1616

17+
import org.eclipse.emf.ecore.EAnnotation;
18+
import org.eclipse.emf.ecore.EObject;
1719
import org.eclipse.emf.ecore.resource.Resource;
1820
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicate;
1921
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicateDelegate;
@@ -26,12 +28,13 @@
2628
/**
2729
* {@link IReadOnlyObjectPredicateDelegate} implementation for SysON.
2830
* <p>
29-
* It ensures that the following {@link Element SysML elements} are considered read-only by the
30-
* {@link IReadOnlyObjectPredicate} implementation (used for the <i>Explorer</i> and <i>Details</i> views):
31+
* It ensures that a {@link Resource}, an {@link EAnnotation} or a {@link Element SysML element} is considered read-only
32+
* by the {@link IReadOnlyObjectPredicate} implementation (used for the <i>Explorer</i> and <i>Details</i> views) when
33+
* it is (or belongs to) a {@link Resource} matching at least one of the following criterias:
3134
* <ul>
32-
* <li>All elements from the SysML and KerML standard libraries</li>
33-
* <li>All elements from an {@link org.eclipse.syson.services.api.ISysONResourceService#isImported(Resource) imported
34-
* resource} containing {@link org.eclipse.syson.sysml.LibraryPackage libraries}.</li>
35+
* <li>From the SysML and KerML standard libraries</li>
36+
* <li>From an {@link org.eclipse.syson.services.api.ISysONResourceService#isImported(Resource) imported resource}
37+
* containing {@link org.eclipse.syson.sysml.LibraryPackage libraries}.</li>
3538
* </ul>
3639
*
3740
* @author flatombe
@@ -47,19 +50,25 @@ public SysONReadOnlyObjectPredicateDelegate(final ISysONResourceService sysONRes
4750

4851
@Override
4952
public boolean canHandle(Object candidate) {
50-
return candidate instanceof Element;
53+
return candidate instanceof Element || candidate instanceof Resource || candidate instanceof EAnnotation;
5154
}
5255

5356
@Override
5457
public boolean test(Object candidate) {
55-
if (candidate instanceof Element element) {
56-
final Resource resource = element.eResource();
57-
return ElementUtil.isStandardLibraryResource(resource)
58-
|| (resource != null && this.sysONResourceService.isImported(resource) && !new UtilService().getLibraries(resource, false).isEmpty());
59-
} else {
60-
// In general, elements are not read-only.
61-
return false;
58+
// In general, elements are not read-only.
59+
boolean isReadOnly = false;
60+
61+
if (candidate instanceof Resource resource) {
62+
isReadOnly = ElementUtil.isStandardLibraryResource(resource)
63+
|| this.sysONResourceService.isImported(resource) && !new UtilService().getLibraries(resource, false).isEmpty();
64+
} else if (candidate instanceof Element || candidate instanceof EAnnotation) {
65+
// Derive editability from the editability of the containing resource.
66+
final EObject eObject = (EObject) candidate;
67+
final Resource resource = eObject.eResource();
68+
isReadOnly = this.test(resource);
6269
}
70+
71+
return isReadOnly;
6372
}
6473

6574
}

0 commit comments

Comments
 (0)