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