Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6d9d8dc11faade698173bac4a891a3d34e235391 (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
/**
 * Copyright (c) 2012 Mia-Software.
 * 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:
 *    Nicolas Bros (Mia-Software) - Bug 379683 - customizable Tree content provider
 *    Gregoire Dupe (Mia-Software) - Bug 386387 - [CustomizedTreeContentProvider] The TreeElements are not preserved between two calls to getElements()
 */
package org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.impl;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EStructuralFeatureTreeElement;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.TreeElement;

/**
 * An implementation of the model object '<em><b>EStructural Feature Tree Element</b></em>'.
 * <p>
 * The following features are implemented:
 * <ul>
 * <li>{@link org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.impl.EStructuralFeatureTreeElementImpl#getParent <em>Parent
 * </em>}</li>
 * <li>{@link org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.impl.EStructuralFeatureTreeElementImpl#getReferedEObjectTE <em>
 * Refered EObject TE</em>}</li>
 * </ul>
 * </p>
 *
 */
public class EStructuralFeatureTreeElementImpl extends TreeElementImpl implements EStructuralFeatureTreeElement {

	/**
	 * The cached value of the '{@link #getReferedEObjectTE() <em>Refered EObject TE</em>}' containment reference list.
	 *
	 * @see #getReferedEObjectTE()
	 */
	protected List<EObjectTreeElement> referedEObjectTE;

	protected EStructuralFeatureTreeElementImpl() {
		super();
	}

	public List<EObjectTreeElement> getReferedEObjectTE() {
		if(referedEObjectTE == null) {
			referedEObjectTE = new LinkedList<EObjectTreeElement>();
		}
		return referedEObjectTE;
	}

	/**
	 * Try to adapt this object to the requested type.
	 * Check if the underlying EObject ({@link #getEObject()}) can be adapted to the requested type.
	 *
	 * @param key
	 * @return
	 */
	public Object getAdapter(Class key) {
		if(key == EStructuralFeature.Setting.class) { //Metamodel element
			EStructuralFeature.Setting result = new EStructuralFeature.Setting() {

				public void unset() {
					getEObject().eUnset(getEStructuralFeature());
				}

				public void set(Object newValue) {
					getEObject().eSet(getEStructuralFeature(), newValue);
				}

				public boolean isSet() {
					return getEObject().eIsSet(getEStructuralFeature());
				}

				public EStructuralFeature getEStructuralFeature() {
					return getEStructuralFeature();
				}

				public EObject getEObject() {
					return getEObject();
				}

				public Object get(boolean resolve) {
					return getEObject().eGet(getEStructuralFeature(), resolve);
				}
			};
		}

		//Semantic element
		// Check if the underlying EObject can request to the adaptation
		// The semantic EObject of a EReferenceTreeElement is the semantic EObject of it's parent (Which is an EObjectTreeElement)
		final EObject model = getEObject();

		if(key.isInstance(model)) {
			return model;
		}

		return null;
	}

	// The semantic EObject of a EReferenceTreeElement is the semantic EObject of it's parent (Which is an EObjectTreeElement)
	protected EObject getEObject() {
		TreeElement parent = getParent();
		if(parent instanceof EObjectTreeElement) { //Should always be true
			return ((EObjectTreeElement)parent).getEObject();
		}
		return null;
	}

} //EStructuralFeatureTreeElementImpl

Back to the top