1 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collections
;
8 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
9 import org
.eclipse
.jface
.viewers
.Viewer
;
11 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
12 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
13 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
14 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
16 public class DerivateContentProvider
implements ITreeContentProvider
{
19 public void dispose() {
20 // TODO Auto-generated method stub
25 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
29 public Object
[] getElements(Object inputElement
) {
30 // return the parent FieldUnit if element is a DerivedUnit
31 if(inputElement
instanceof DerivedUnit
){
32 DerivedUnit derivedUnit
= (DerivedUnit
)inputElement
;
33 for(SpecimenOrObservationBase original
:derivedUnit
.getOriginals()){
34 if(original
instanceof FieldUnit
){
35 return Collections
.singletonList(original
).toArray();
38 return getElements(original
);
42 // return the FieldUnit itself if element is a FieldUnit (used clone() due to recursion issues -> see javadoc of this method)
43 else if(inputElement
instanceof FieldUnit
){
44 FieldUnit fieldUnit
= ((FieldUnit
) inputElement
).clone();
45 fieldUnit
.getTitleCache();
46 return Collections
.singleton(fieldUnit
).toArray();
48 return Collections
.EMPTY_LIST
.toArray();
52 public Object
[] getChildren(Object parentElement
) {
53 if(parentElement
instanceof SpecimenOrObservationBase
){
54 return getDerivates((SpecimenOrObservationBase
) parentElement
).toArray();
60 public Object
getParent(Object element
) {
61 if(element
instanceof DerivedUnit
){
62 DerivedUnit derivedUnit
= (DerivedUnit
)element
;
63 return derivedUnit
.getOriginalUnit();
69 public boolean hasChildren(Object element
) {
70 if(element
instanceof SpecimenOrObservationBase
){
71 SpecimenOrObservationBase specimenOrObservation
= (SpecimenOrObservationBase
)element
;
72 for(DerivationEvent event
:(Set
<DerivationEvent
>)specimenOrObservation
.getDerivationEvents()){
73 if(!event
.getDerivatives().isEmpty()){
81 private List
<DerivedUnit
> getDerivates(SpecimenOrObservationBase specimenOrObservation
){
82 List
<DerivedUnit
> derivates
= new ArrayList
<DerivedUnit
>();
83 for(DerivationEvent derivationEvent
:(Set
<DerivationEvent
>)specimenOrObservation
.getDerivationEvents()){
84 derivates
.addAll(derivationEvent
.getDerivatives());