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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations