1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.concept.graph;
|
5
|
|
6
|
import java.util.Set;
|
7
|
import java.util.HashMap;
|
8
|
import java.util.Map;
|
9
|
|
10
|
import org.eclipse.jface.viewers.Viewer;
|
11
|
import org.eclipse.zest.core.viewers.IGraphContentProvider;
|
12
|
|
13
|
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
16
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
18
|
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
|
19
|
|
20
|
/**
|
21
|
* @author andreas
|
22
|
*
|
23
|
*/
|
24
|
public class ConceptGraphContentProvider implements IGraphContentProvider {
|
25
|
|
26
|
/* (non-Javadoc)
|
27
|
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
28
|
*/
|
29
|
@Override
|
30
|
public void dispose() {
|
31
|
// TODO Auto-generated method stub
|
32
|
|
33
|
}
|
34
|
|
35
|
/* (non-Javadoc)
|
36
|
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
37
|
*/
|
38
|
@Override
|
39
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
40
|
// TODO Auto-generated method stub
|
41
|
|
42
|
}
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.zest.core.viewers.IGraphContentProvider#getSource(java.lang.Object)
|
46
|
*/
|
47
|
@Override
|
48
|
public Object getSource(Object taxonRelationship) {
|
49
|
return ((TaxonRelationship)taxonRelationship).getFromTaxon();
|
50
|
}
|
51
|
|
52
|
/* (non-Javadoc)
|
53
|
* @see org.eclipse.zest.core.viewers.IGraphContentProvider#getDestination(java.lang.Object)
|
54
|
*/
|
55
|
@Override
|
56
|
public Object getDestination(Object taxonRelationship) {
|
57
|
return ((TaxonRelationship)taxonRelationship).getToTaxon();
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see org.eclipse.zest.core.viewers.IGraphContentProvider#getElements(java.lang.Object)
|
62
|
*/
|
63
|
@Override
|
64
|
public Object[] getElements(Object inputElement) {
|
65
|
if(inputElement instanceof TaxonEditorInput){
|
66
|
Taxon taxon = ((TaxonEditorInput) inputElement).getTaxon();
|
67
|
|
68
|
Map<String, TaxonRelationship> filteredTaxonRelations = new HashMap<String, TaxonRelationship>();
|
69
|
getTaxonRelationshipsRecursive(filteredTaxonRelations, taxon);
|
70
|
|
71
|
return filteredTaxonRelations.values().toArray();
|
72
|
}
|
73
|
return new Object[0];
|
74
|
}
|
75
|
|
76
|
private void getTaxonRelationshipsRecursive(Map<String, TaxonRelationship> filteredTaxonRelations, Taxon taxon) {
|
77
|
// TODO extract method into new class TaxonHelper in
|
78
|
// eu.etaxonomy.taxeditor.model;
|
79
|
// see also ConceptContentProvider
|
80
|
for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
|
81
|
|
82
|
if (!relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
|
83
|
&& !relationship.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())
|
84
|
&& !relationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
|
85
|
|
86
|
if(!relationship.getToTaxon().equals(taxon)){
|
87
|
continue;
|
88
|
}
|
89
|
|
90
|
String key = relationship.getFromTaxon().getUuid().toString() + relationship.getType().getUuid();
|
91
|
if(!filteredTaxonRelations.containsKey(key)) {
|
92
|
filteredTaxonRelations.put(key, relationship);
|
93
|
Taxon toTaxon = relationship.getToTaxon();
|
94
|
if(toTaxon != null){
|
95
|
getTaxonRelationshipsRecursive(filteredTaxonRelations, toTaxon);
|
96
|
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
|
101
|
|
102
|
}
|
103
|
|
104
|
|
105
|
}
|
106
|
|
107
|
}
|