-
Notifications
You must be signed in to change notification settings - Fork 45
/
RepresentationDescriptionSearchService.java
51 lines (45 loc) · 1.93 KB
/
RepresentationDescriptionSearchService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.services.editingcontext;
import java.util.Map;
import java.util.Optional;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.springframework.stereotype.Service;
/**
* Service used to search the representation descriptions available.
*
* @author sbegaudeau
* @author hmarchadour
*/
@Service
public class RepresentationDescriptionSearchService implements IRepresentationDescriptionSearchService {
@Override
public Map<String, IRepresentationDescription> findAll(IEditingContext editingContext) {
if (editingContext instanceof EditingContext emfEditingContext) {
return emfEditingContext.getRepresentationDescriptions();
}
return Map.of();
}
@Override
public Optional<IRepresentationDescription> findById(IEditingContext editingContext, String representationDescriptionId) {
// @formatter:off
return Optional.of(editingContext)
.filter(EditingContext.class::isInstance)
.map(EditingContext.class::cast)
.map(EditingContext::getRepresentationDescriptions)
.map(representationDescriptions -> representationDescriptions.get(representationDescriptionId));
// @formatter:on
}
}