Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / PolytomousKeyListContentProvider.java
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.PolytomousKeyNode;
20
21 /**
22 * @author n.hoffmann
23 * @created Apr 4, 2011
24 * @version 1.0
25 */
26 public class PolytomousKeyListContentProvider implements
27 IStructuredContentProvider {
28
29 /*
30 * (non-Javadoc)
31 *
32 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
33 */
34 @Override
35 public void dispose() {
36 }
37
38 /*
39 * (non-Javadoc)
40 *
41 * @see
42 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
43 * .viewers.Viewer, java.lang.Object, java.lang.Object)
44 */
45 @Override
46 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
47 }
48
49 /*
50 * (non-Javadoc)
51 *
52 * @see
53 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
54 * .lang.Object)
55 */
56 @Override
57 public Object[] getElements(Object inputElement) {
58 if (inputElement instanceof PolytomousKeyEditorInput) {
59 List<PolytomousKeyNode> result = new ArrayList<PolytomousKeyNode>();
60
61 PolytomousKeyNode root = ((PolytomousKeyEditorInput) inputElement).getKey().getRoot();
62
63 getChildrenBreadthFirst(result, root);
64 return result.toArray();
65 }
66
67 return null;
68 }
69
70 private void getChildrenBreadthFirst(List<PolytomousKeyNode> result,
71 PolytomousKeyNode node) {
72 if (!node.getChildren().isEmpty()) {
73 result.addAll(node.getChildren());
74 for (PolytomousKeyNode internalNode : node.getChildren()) {
75 getChildrenBreadthFirst(result, internalNode);
76 }
77 }
78 }
79 }