Search in sources :

Example 1 with RepresentationMetadata

use of org.eclipse.sirius.components.core.RepresentationMetadata in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method getImageURL.

private String getImageURL(VariableManager variableManager) {
    Object self = variableManager.getVariables().get(VariableManager.SELF);
    String imageURL = null;
    if (self instanceof EObject) {
        imageURL = this.objectService.getImagePath(self);
    } else if (self instanceof RepresentationMetadata) {
        RepresentationMetadata representationMetadata = (RepresentationMetadata) self;
        // @formatter:off
        imageURL = this.representationImageProviders.stream().map(representationImageProvider -> representationImageProvider.getImageURL(representationMetadata.getKind())).flatMap(Optional::stream).findFirst().orElse(ImageConstants.RESOURCE_SVG);
    // @formatter:on
    } else if (self instanceof Resource) {
        imageURL = ImageConstants.RESOURCE_SVG;
    }
    return Optional.ofNullable(imageURL).orElse(ImageConstants.DEFAULT_SVG);
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IRenameTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IRenameTreeItemHandler) IKindParser(org.eclipse.sirius.components.core.api.IKindParser) TreeRenderer(org.eclipse.sirius.components.trees.renderer.TreeRenderer) ArrayList(java.util.ArrayList) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IExplorerDescriptionProvider(org.eclipse.sirius.components.collaborative.trees.api.IExplorerDescriptionProvider) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) IDeleteTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler) Service(org.springframework.stereotype.Service) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) SemanticKindConstants(org.eclipse.sirius.components.core.api.SemanticKindConstants) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) EObject(org.eclipse.emf.ecore.EObject) TreeItem(org.eclipse.sirius.components.trees.TreeItem) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IRepresentationService(org.eclipse.sirius.web.services.api.representations.IRepresentationService) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Resource(org.eclipse.emf.ecore.resource.Resource) ImageConstants(org.eclipse.sirius.components.compatibility.services.ImageConstants) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IRepresentationImageProvider(org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider) Optional(java.util.Optional) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with RepresentationMetadata

use of org.eclipse.sirius.components.core.RepresentationMetadata in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method isEditable.

private boolean isEditable(VariableManager variableManager) {
    Object self = variableManager.getVariables().get(VariableManager.SELF);
    boolean editable = false;
    if (self instanceof RepresentationMetadata) {
        editable = true;
    } else if (self instanceof Resource) {
        editable = true;
    } else if (self instanceof EObject) {
        editable = this.objectService.isLabelEditable(self);
    }
    return editable;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with RepresentationMetadata

use of org.eclipse.sirius.components.core.RepresentationMetadata in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method getTreeItemId.

private String getTreeItemId(VariableManager variableManager) {
    Object self = variableManager.getVariables().get(VariableManager.SELF);
    String id = null;
    if (self instanceof RepresentationMetadata) {
        id = ((RepresentationMetadata) self).getId();
    } else if (self instanceof Resource) {
        Resource resource = (Resource) self;
        id = resource.getURI().toString();
    } else if (self instanceof EObject) {
        id = this.objectService.getId(self);
    }
    return id;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with RepresentationMetadata

use of org.eclipse.sirius.components.core.RepresentationMetadata in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method getLabel.

private String getLabel(VariableManager variableManager) {
    Object self = variableManager.getVariables().get(VariableManager.SELF);
    // $NON-NLS-1$
    String label = "";
    if (self instanceof RepresentationMetadata) {
        label = ((RepresentationMetadata) self).getLabel();
    } else if (self instanceof Resource) {
        Resource resource = (Resource) self;
        // @formatter:off
        label = resource.eAdapters().stream().filter(DocumentMetadataAdapter.class::isInstance).map(DocumentMetadataAdapter.class::cast).findFirst().map(DocumentMetadataAdapter::getName).orElse(resource.getURI().lastSegment());
    // @formatter:on
    } else if (self instanceof EObject) {
        label = this.objectService.getLabel(self);
        if (label.isBlank()) {
            var kind = this.objectService.getKind(self);
            label = this.kindParser.getParameterValues(kind).get(SemanticKindConstants.ENTITY_ARGUMENT).get(0);
        }
    }
    return label;
}
Also used : DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) EObject(org.eclipse.emf.ecore.EObject)

Example 5 with RepresentationMetadata

use of org.eclipse.sirius.components.core.RepresentationMetadata in project sirius-web by eclipse-sirius.

the class EditingContextRepresentationsDataFetcher method get.

@Override
public Connection<RepresentationMetadata> get(DataFetchingEnvironment environment) throws Exception {
    String editingContextId = environment.getSource();
    // @formatter:off
    List<RepresentationMetadata> representations = this.representationService.getRepresentationDescriptorsForProjectId(editingContextId).stream().map(RepresentationDescriptor::getRepresentation).map(this::toRepresentationMetadata).collect(Collectors.toList());
    // @formatter:on
    // @formatter:off
    List<Edge<RepresentationMetadata>> representationEdges = representations.stream().map(representation -> {
        String value = Base64.getEncoder().encodeToString(representation.getId().getBytes());
        ConnectionCursor cursor = new DefaultConnectionCursor(value);
        return new DefaultEdge<>(representation, cursor);
    }).collect(Collectors.toList());
    // @formatter:on
    ConnectionCursor startCursor = representationEdges.stream().findFirst().map(Edge::getCursor).orElse(null);
    ConnectionCursor endCursor = null;
    if (!representationEdges.isEmpty()) {
        endCursor = representationEdges.get(representationEdges.size() - 1).getCursor();
    }
    PageInfo pageInfo = new DefaultPageInfo(startCursor, endCursor, false, false);
    return new DefaultConnection<>(representationEdges, pageInfo);
}
Also used : PageInfo(graphql.relay.PageInfo) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) QueryDataFetcher(org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher) ISemanticRepresentation(org.eclipse.sirius.components.representations.ISemanticRepresentation) RepresentationDescriptor(org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor) DefaultEdge(graphql.relay.DefaultEdge) IDataFetcherWithFieldCoordinates(org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates) Collectors(java.util.stream.Collectors) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor) IRepresentationService(org.eclipse.sirius.web.services.api.representations.IRepresentationService) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) DefaultPageInfo(graphql.relay.DefaultPageInfo) Connection(graphql.relay.Connection) DefaultConnection(graphql.relay.DefaultConnection) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) Edge(graphql.relay.Edge) Optional(java.util.Optional) ConnectionCursor(graphql.relay.ConnectionCursor) EditingContextTypeProvider(org.eclipse.sirius.web.graphql.schema.EditingContextTypeProvider) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor) ConnectionCursor(graphql.relay.ConnectionCursor) RepresentationDescriptor(org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor) PageInfo(graphql.relay.PageInfo) DefaultPageInfo(graphql.relay.DefaultPageInfo) DefaultConnection(graphql.relay.DefaultConnection) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) DefaultEdge(graphql.relay.DefaultEdge) Edge(graphql.relay.Edge) DefaultPageInfo(graphql.relay.DefaultPageInfo) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor)

Aggregations

RepresentationMetadata (org.eclipse.sirius.components.core.RepresentationMetadata)7 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 IRepresentationService (org.eclipse.sirius.web.services.api.representations.IRepresentationService)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Predicate (java.util.function.Predicate)2 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)2 IRepresentationImageProvider (org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider)2 IExplorerDescriptionProvider (org.eclipse.sirius.components.collaborative.trees.api.IExplorerDescriptionProvider)2 ImageConstants (org.eclipse.sirius.components.compatibility.services.ImageConstants)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IKindParser (org.eclipse.sirius.components.core.api.IKindParser)2 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)2 SemanticKindConstants (org.eclipse.sirius.components.core.api.SemanticKindConstants)2 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)2