3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
17 import org
.eclipse
.jface
.viewers
.Viewer
;
19 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
23 * @created Apr 4, 2011
26 public class PolytomousKeyListContentProvider
implements
27 IStructuredContentProvider
{
32 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
35 public void dispose() {
42 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
43 * .viewers.Viewer, java.lang.Object, java.lang.Object)
46 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
53 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
57 public Object
[] getElements(Object inputElement
) {
58 if (inputElement
instanceof PolytomousKeyEditorInput
) {
59 List
<PolytomousKeyNode
> result
= new ArrayList
<PolytomousKeyNode
>();
61 PolytomousKeyNode root
= ((PolytomousKeyEditorInput
) inputElement
).getKey().getRoot();
63 getChildrenBreadthFirst(result
, root
);
64 return result
.toArray();
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
);