diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 56c25c9..e644e32 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -1,5 +1,16 @@ = Changelog +== v2026.5.0 + +=== Dependency update + +=== New features + +=== Improvements + +=== Bug fixes +- https://github.com/ObeoNetwork/pepper/issues/50[#50] Stop extending DefaultLabelService + == v2026.3.0 === Dependency update diff --git a/backend/pepper-starter/src/main/java/pepper/starter/services/PepperMMLabelServiceDelegate.java b/backend/pepper-starter/src/main/java/pepper/starter/services/PepperMMLabelServiceDelegate.java index 662189b..c2e4b79 100644 --- a/backend/pepper-starter/src/main/java/pepper/starter/services/PepperMMLabelServiceDelegate.java +++ b/backend/pepper-starter/src/main/java/pepper/starter/services/PepperMMLabelServiceDelegate.java @@ -16,13 +16,18 @@ import java.util.List; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider; +import org.eclipse.sirius.components.core.CoreImageConstants; import org.eclipse.sirius.components.core.api.ILabelServiceDelegate; import org.eclipse.sirius.components.core.api.IObjectSearchService; import org.eclipse.sirius.components.core.api.labels.StyledString; +import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; import org.eclipse.sirius.components.emf.services.api.IEMFLabelService; -import org.eclipse.sirius.web.application.object.services.DefaultLabelService; import org.eclipse.sirius.ext.emf.edit.EditingDomainServices; +import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationIconURL; +import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationMetadata; import org.springframework.stereotype.Service; /** @@ -31,12 +36,17 @@ * @author Laurent Fasani */ @Service -public class PepperMMLabelServiceDelegate extends DefaultLabelService implements ILabelServiceDelegate { +public class PepperMMLabelServiceDelegate implements ILabelServiceDelegate { private final EditingDomainServices editingDomainServices = new EditingDomainServices(); - public PepperMMLabelServiceDelegate(List iRepresentationImageProviders, IEMFLabelService iemfLabelService) { - super(iRepresentationImageProviders, iemfLabelService); + private final List representationImageProviders; + + private final IEMFLabelService emfLabelService; + + public PepperMMLabelServiceDelegate(IEMFLabelService iemfLabelService, List representationImageProviders) { + this.representationImageProviders = representationImageProviders; + this.emfLabelService = iemfLabelService; } @Override @@ -49,8 +59,41 @@ public StyledString getStyledLabel(Object object) { if (object instanceof TaskTag tag) { return StyledString.of(this.editingDomainServices.getLabelProviderText(tag)); } else { - return super.getStyledLabel(object); + StyledString label = StyledString.of(""); + if (object instanceof RepresentationMetadata representationMetadata) { + label = StyledString.of(representationMetadata.getLabel()); + } else if (object instanceof Resource resource) { + label = resource.eAdapters().stream() + .filter(ResourceMetadataAdapter.class::isInstance) + .map(ResourceMetadataAdapter.class::cast).findFirst() + .map(ResourceMetadataAdapter::getName) + .map(StyledString::of) + .orElse(StyledString.of(resource.getURI().lastSegment())); + } else if (object instanceof EObject eObject) { + label = this.emfLabelService.getStyledLabel(eObject); + } + return label; } } + @Override + public List getImagePaths(Object self) { + List imagePaths = List.of(CoreImageConstants.DEFAULT_SVG); + if (self instanceof RepresentationMetadata representationMetadata) { + if (!representationMetadata.getIconURLs().isEmpty()) { + imagePaths = representationMetadata.getIconURLs().stream() + .map(RepresentationIconURL::url) + .toList(); + } else { + imagePaths = this.representationImageProviders.stream() + .flatMap(provider -> provider.getImageURL(representationMetadata.getKind()).stream()) + .toList(); + } + } else if (self instanceof Resource) { + imagePaths = List.of("/icons/Resource.svg"); + } else if (self instanceof EObject eObject) { + imagePaths = this.emfLabelService.getImagePaths(eObject); + } + return imagePaths; + } }