blob: 60d8aa9d0343745cfa15462aefea364560a93a93 (
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
|
/*******************************************************************************
* Copyright (c) 2012 THALES GLOBAL SERVICES.
* 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.sirius.editor.tools.internal.property.section;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.sirius.description.DiagramDescription;
import org.eclipse.sirius.description.DiagramImportDescription;
/**
* Helper for AbstractSiriusPropertySection generated class.
*
* @author fbarbin
*
*/
public class AbstractSiriusPropertySectionHelper {
/**
* Check if the given eObject is a child of the diagram description.
*
* @param eObject
* the eObject.
* @param diagramDescription
* the diagram description.
* @return true if eObject is a child or is equals to diagram description
* otherwise false.
*/
public static boolean isChildOfDiagramDescription(EObject eObject, DiagramDescription diagramDescription) {
EObject current = eObject;
while (current != null) {
if ((current instanceof DiagramDescription)) {
if (current.equals(diagramDescription)) {
return true;
} else {
return false;
}
} else {
current = current.eContainer();
}
}
return false;
}
/**
* Provides the first DiagramImportDescription found into given selection.
*
* @param selection
* the selection.
* @return the diagram import description or <code>null</code> if not found.
*/
public static DiagramImportDescription getDiagramImportDescriptionInSelection(ISelection selection) {
if (selection instanceof ITreeSelection) {
TreePath treePath = ((ITreeSelection) selection).getPaths()[0];
for (int i = 0; i < treePath.getSegmentCount(); i++) {
if (treePath.getSegment(i) instanceof DiagramImportDescription) {
return (DiagramImportDescription) treePath.getSegment(i);
}
}
}
return null;
}
}
|