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