blob: 5333a5ce5d142c1856b2441380a315227dea8145 (
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
|
/*****************************************************************************
* Copyright (c) 2010 CEA LIST.
*
* 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.emf.providers;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
/**
* An IStaticContentProvider for EMF enumerators.
*
* @author Camille Letavernier
*/
public class EMFEnumeratorContentProvider extends AbstractStaticContentProvider {
/**
* The feature representing the Enumerator for this ContentProvider
*/
protected EStructuralFeature feature;
/**
* Constructs an EcoreEnumerator for the given Structural Feature
*
* @param feature
*/
public EMFEnumeratorContentProvider(EStructuralFeature feature) {
this.feature = feature;
}
public Object[] getElements() {
EClassifier type = feature.getEType();
EEnum enumerated = (EEnum) type;
EEnumLiteral[] literals = enumerated.getELiterals().toArray(new EEnumLiteral[0]);
Enumerator[] values = new Enumerator[literals.length];
int i = 0;
for (EEnumLiteral literal : literals) {
Enumerator value = literal.getInstance();
values[i++] = value;
}
return values;
}
}
|