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
.Viewer
;
17 import org
.eclipse
.zest
.core
.viewers
.IGraphContentProvider
;
19 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
21 import eu
.etaxonomy
.taxeditor
.model
.PolytomousKeyRelationship
;
26 * @created Mar 30, 2011
29 class PolytomousKeyGraphContentProvider
implements IGraphContentProvider
{
31 private List
<PolytomousKeyRelationship
> relations
;
34 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
39 public void dispose() {
44 public Object
[] getElements(Object inputElement
) {
45 relations
= new ArrayList
<PolytomousKeyRelationship
>();
47 if (inputElement
instanceof PolytomousKey
) {
48 getTreeRecursively(relations
, inputElement
);
50 return relations
.toArray();
53 private void getTreeRecursively(List
<PolytomousKeyRelationship
> relations
,
55 List
<PolytomousKeyNode
> children
;
57 if (parent
instanceof PolytomousKeyNode
) {
58 children
= ((PolytomousKeyNode
) parent
).getChildren();
59 } else if (parent
instanceof PolytomousKey
) {
60 children
= new ArrayList
<PolytomousKeyNode
>();
61 children
.add(((PolytomousKey
) parent
).getRoot());
63 throw new RuntimeException(
64 "Parent element has to be PolytomousKeyNode or PolytomousKey, but was: "
68 for (PolytomousKeyNode childNode
: children
) {
69 relations
.add(new PolytomousKeyRelationship(parent
, childNode
));
70 getTreeRecursively(relations
, childNode
);
75 public Object
getSource(Object relationship
) {
76 return ((PolytomousKeyRelationship
) relationship
).getSource();
80 public Object
getDestination(Object relationship
) {
81 return ((PolytomousKeyRelationship
) relationship
).getDestination();