-
Notifications
You must be signed in to change notification settings - Fork 45
/
PageDescriptionConverter.java
81 lines (68 loc) · 3.88 KB
/
PageDescriptionConverter.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
* Copyright (c) 2019, 2024 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.components.compatibility.forms;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.eclipse.sirius.components.compatibility.api.IIdentifierProvider;
import org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory;
import org.eclipse.sirius.components.interpreter.StringValueProvider;
import org.eclipse.sirius.components.forms.description.GroupDescription;
import org.eclipse.sirius.components.forms.description.PageDescription;
import org.eclipse.sirius.components.interpreter.AQLInterpreter;
import org.eclipse.sirius.components.representations.VariableManager;
/**
* This class is used to convert a Sirius PageDescription to an Sirius Web PageDescription.
*
* @author fbarbin
*/
public class PageDescriptionConverter {
private final AQLInterpreter interpreter;
private final IIdentifierProvider identifierProvider;
private final ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory;
public PageDescriptionConverter(AQLInterpreter interpreter, IIdentifierProvider identifierProvider, ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory) {
this.interpreter = Objects.requireNonNull(interpreter);
this.identifierProvider = Objects.requireNonNull(identifierProvider);
this.semanticCandidatesProviderFactory = Objects.requireNonNull(semanticCandidatesProviderFactory);
}
public PageDescription convert(org.eclipse.sirius.properties.PageDescription siriusPageDescription,
Map<org.eclipse.sirius.properties.GroupDescription, GroupDescription> siriusGroup2SiriusWebGroup) {
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, siriusPageDescription.getLabelExpression());
String domainClass = Optional.ofNullable(siriusPageDescription.getDomainClass()).orElse("");
String semanticCandidatesExpression = Optional.ofNullable(siriusPageDescription.getSemanticCandidateExpression()).orElse("");
String preconditionExpression = Optional.ofNullable(siriusPageDescription.getPreconditionExpression()).orElse("");
var semanticCandidatesProvider = this.semanticCandidatesProviderFactory.getSemanticCandidatesProvider(this.interpreter, domainClass, semanticCandidatesExpression, preconditionExpression);
Predicate<VariableManager> canCreatePredicate = (variableManager) -> {
Object object = variableManager.getVariables().get(VariableManager.SELF);
if (object != null) {
return !semanticCandidatesProvider.apply(variableManager).isEmpty();
}
return false;
};
// @formatter:off
List<GroupDescription> groupDescriptions = siriusPageDescription.getGroups().stream()
.map(siriusGroup2SiriusWebGroup::get)
.collect(Collectors.toUnmodifiableList());
return PageDescription.newPageDescription(this.identifierProvider.getIdentifier(siriusPageDescription))
.idProvider(labelProvider)
.labelProvider(labelProvider)
.semanticElementsProvider(semanticCandidatesProvider)
.groupDescriptions(groupDescriptions)
.canCreatePredicate(canCreatePredicate)
.build();
// @formatter:on
}
}