Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7e0ba9887c5122e4cd0e0615c9c32554ee2abf51 (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
/*****************************************************************************
 * Copyright (c) 2010 Atos Origin.
 *
 *    
 * 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:
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.navigation;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * This class represents an element which can be accessed from an other element
 * throught a feature using defined navigation rules.
 * 
 * @author mvelten
 * 
 */
public abstract class NavigableElement implements Comparable<NavigableElement> {

	private EObject element = null;

	private EStructuralFeature feature = null;

	private int depth = 0;

	public NavigableElement(EObject element, EStructuralFeature feature) {
		this.element = element;
		this.feature = feature;
	}

	public NavigableElement(EObject element, NavigableElement previousNavigableElement, EStructuralFeature feature) {
		this(element, feature);
		if(previousNavigableElement != null) {
			this.depth = previousNavigableElement.getDepth() + 1;
		}
	}

	public EObject getElement() {
		return element;
	}

	public EStructuralFeature getFeature() {
		return feature;
	}

	/**
	 * Retrieve the navigation depth.
	 * 
	 * @return the navigation depth
	 */
	public int getDepth() {
		return depth;
	}

	public int compareTo(NavigableElement o) {
		return getDepth() - o.getDepth();
	}
}

Back to the top