Project

General

Profile

Download (2 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.editor.key.polytomous;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.eclipse.jface.viewers.IStructuredContentProvider;
16
import org.eclipse.jface.viewers.Viewer;
17

    
18
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
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 == null){
73
	        return;
74
	    }
75
		if (!node.getChildren().isEmpty()) {
76
			result.addAll(node.getChildren());
77
			HHH_9751_Util.removeAllNull(result);
78
			for (PolytomousKeyNode internalNode : node.getChildren()) {
79
				getChildrenBreadthFirst(result, internalNode);
80
			}
81
		}
82
	}
83
}
(7-7/11)