Skip to main content
summaryrefslogtreecommitdiffstats
blob: efa8e0a8f5022ffdae972d500f76b00f40c462c0 (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*******************************************************************************
 * Copyright (c) 2015 Obeo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.eef.core.internal;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.eef.EEFGroupDescription;
import org.eclipse.eef.EEFPageDescription;
import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.EEFGroup;
import org.eclipse.eef.core.api.EEFPage;
import org.eclipse.eef.core.api.EEFView;
import org.eclipse.eef.core.api.IVariableManager;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.sirius.common.interpreter.api.IEvaluationResult;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;

/**
 * The implementation of the {@link EEFPage}.
 *
 * @author sbegaudeau
 */
public class EEFPageImpl implements EEFPage {
	/**
	 * The variable manager.
	 */
	private IVariableManager variableManager;

	/**
	 * The interpreter.
	 */
	private IInterpreter interpreter;

	/**
	 * The containing {@link EEFView}.
	 */
	private EEFView eefView;

	/**
	 * The description.
	 */
	private EEFPageDescription eefPageDescription;

	/**
	 * The {@link EEFGroup}.
	 */
	private List<EEFGroup> eefGroups = new ArrayList<EEFGroup>();

	/**
	 * The editing domain.
	 */
	private TransactionalEditingDomain editingDomain;

	/**
	 * The constructor.
	 *
	 * @param eefView
	 *            The containing {@link EEFView}
	 * @param eefPageDescription
	 *            The description
	 * @param variableManager
	 *            The variable manager
	 * @param interpreter
	 *            The interpreter
	 * @param editingDomain
	 *            The editing domain
	 */
	public EEFPageImpl(EEFView eefView, EEFPageDescription eefPageDescription, IVariableManager variableManager, IInterpreter interpreter,
			TransactionalEditingDomain editingDomain) {
		this.variableManager = variableManager;
		this.interpreter = interpreter;
		this.eefView = eefView;
		this.eefPageDescription = eefPageDescription;
		this.editingDomain = editingDomain;
	}

	/**
	 * Initialize the variables of the EEFPage.
	 */
	public void initialize() {
		List<EEFGroupDescription> eefGroupDescriptions = this.eefPageDescription.getGroups();
		for (EEFGroupDescription eefGroupDescription : eefGroupDescriptions) {
			String semanticCandidatesExpression = eefGroupDescription.getSemanticCandidateExpression();
			if (semanticCandidatesExpression != null && semanticCandidatesExpression.trim().length() > 0) {
				IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.getVariableManager().getVariables(),
						semanticCandidatesExpression);
				if (evaluationResult.getValue() instanceof Iterable<?>) {
					@SuppressWarnings("unchecked")
					Iterable<Object> groupSemanticCandidates = (Iterable<Object>) evaluationResult.getValue();
					for (Object groupSemanticCandidate : groupSemanticCandidates) {
						IVariableManager childVariableManager = this.getVariableManager().createChild();
						childVariableManager.put(EEFExpressionUtils.SELF, groupSemanticCandidate);
						EEFGroupImpl eefGroupImpl = new EEFGroupImpl(this, eefGroupDescription, childVariableManager, this.interpreter,
								this.editingDomain);
						eefGroups.add(eefGroupImpl);
					}
				} else {
					Object groupSemanticCandidate = evaluationResult.getValue();
					IVariableManager childVariableManager = this.getVariableManager().createChild();
					childVariableManager.put(EEFExpressionUtils.SELF, groupSemanticCandidate);
					EEFGroupImpl eefGroupImpl = new EEFGroupImpl(this, eefGroupDescription, childVariableManager, this.interpreter,
							this.editingDomain);
					eefGroups.add(eefGroupImpl);
				}
			} else {
				IVariableManager childVariableManager = this.getVariableManager().createChild();
				EEFGroupImpl eefGroupImpl = new EEFGroupImpl(this, eefGroupDescription, childVariableManager, this.interpreter, this.editingDomain);
				eefGroups.add(eefGroupImpl);
			}
		}
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.eef.core.api.EEFPage#getLabel()
	 */
	@Override
	public String getLabel() {
		String labelExpression = this.eefPageDescription.getLabelExpression();
		if (labelExpression != null) {
			IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.getVariableManager().getVariables(), labelExpression);
			if (evaluationResult.getValue() != null) {
				return evaluationResult.getValue().toString();
			}
		}
		return labelExpression;
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.eef.core.api.EEFPage#getGroups()
	 */
	@Override
	public List<EEFGroup> getGroups() {
		return this.eefGroups;
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.eef.core.api.EEFPage#getDescription()
	 */
	@Override
	public EEFPageDescription getDescription() {
		return this.eefPageDescription;
	}

	@Override
	public EEFView getView() {
		return this.eefView;
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.eef.core.api.EEFPage#getVariableManager()
	 */
	@Override
	public IVariableManager getVariableManager() {
		return this.variableManager;
	}

}

Back to the top