Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ All existing SysON _DiagramDescriptions_ (i.g. _General View_, _Interconnection
- https://github.com/eclipse-syson/syson/issues/1359[#1359] [export] Implement textual export of `ViewUsage`.
- 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.
- 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.
- https://github.com/eclipse-syson/syson/issues/1357[#1357] [syson] Add support for `Resource` and `EAnnotation` in `SysONReadOnlyObjectPredicateDelegate`.

=== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Objects;

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

@Override
public boolean canHandle(Object candidate) {
return candidate instanceof Element;
return candidate instanceof Element || candidate instanceof Resource || candidate instanceof EAnnotation;
}

@Override
public boolean test(Object candidate) {
if (candidate instanceof Element element) {
final Resource resource = element.eResource();
return ElementUtil.isStandardLibraryResource(resource)
|| (resource != null && this.sysONResourceService.isImported(resource) && !new UtilService().getLibraries(resource, false).isEmpty());
} else {
// In general, elements are not read-only.
return false;
// In general, elements are not read-only.
boolean isReadOnly = false;

if (candidate instanceof Resource resource) {
isReadOnly = ElementUtil.isStandardLibraryResource(resource)
|| this.sysONResourceService.isImported(resource) && !new UtilService().getLibraries(resource, false).isEmpty();
} else if (candidate instanceof Element || candidate instanceof EAnnotation) {
// Derive editability from the editability of the containing resource.
final EObject eObject = (EObject) candidate;
final Resource resource = eObject.eResource();
isReadOnly = this.test(resource);
}

return isReadOnly;
}

}
Loading