1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.key.polytomous;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
17
|
import org.eclipse.jface.viewers.Viewer;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
20
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
21
|
|
22
|
/**
|
23
|
* @author n.hoffmann
|
24
|
* @created Apr 4, 2011
|
25
|
* @version 1.0
|
26
|
*/
|
27
|
public class PolytomousKeyListContentProvider implements
|
28
|
IStructuredContentProvider {
|
29
|
|
30
|
/*
|
31
|
* (non-Javadoc)
|
32
|
*
|
33
|
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
34
|
*/
|
35
|
@Override
|
36
|
public void dispose() {
|
37
|
}
|
38
|
|
39
|
/*
|
40
|
* (non-Javadoc)
|
41
|
*
|
42
|
* @see
|
43
|
* org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
|
44
|
* .viewers.Viewer, java.lang.Object, java.lang.Object)
|
45
|
*/
|
46
|
@Override
|
47
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
48
|
}
|
49
|
|
50
|
/*
|
51
|
* (non-Javadoc)
|
52
|
*
|
53
|
* @see
|
54
|
* org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
|
55
|
* .lang.Object)
|
56
|
*/
|
57
|
@Override
|
58
|
public Object[] getElements(Object inputElement) {
|
59
|
if (inputElement instanceof PolytomousKey) {
|
60
|
List<PolytomousKeyNode> result = new ArrayList<PolytomousKeyNode>();
|
61
|
|
62
|
PolytomousKeyNode root = ((PolytomousKey) inputElement).getRoot();
|
63
|
|
64
|
getChildrenBreadthFirst(result, root);
|
65
|
return result.toArray();
|
66
|
}
|
67
|
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
private void getChildrenBreadthFirst(List<PolytomousKeyNode> result,
|
72
|
PolytomousKeyNode node) {
|
73
|
if (!node.getChildren().isEmpty()) {
|
74
|
result.addAll(node.getChildren());
|
75
|
for (PolytomousKeyNode internalNode : node.getChildren()) {
|
76
|
getChildrenBreadthFirst(result, internalNode);
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
}
|