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
;
15 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
17 public class DerivateContentProvider
implements ITreeContentProvider
{
20 public void dispose() {
21 // TODO Auto-generated method stub
26 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
30 public Object
[] getElements(Object inputElement
) {
31 FieldUnit fieldUnit
= null;
32 if(inputElement
instanceof DerivateViewEditorInput
){
33 fieldUnit
= ((DerivateViewEditorInput
) inputElement
).getFieldUnit();
35 // return the parent FieldUnit if element is a DerivedUnit
36 else if(inputElement
instanceof DerivedUnit
){
37 fieldUnit
= EditorUtil
.getFieldUnit((DerivedUnit
)inputElement
);
39 else if(inputElement
instanceof FieldUnit
){
40 fieldUnit
= (FieldUnit
) inputElement
;
41 // fieldUnit.getTitleCache();
44 return Collections
.singleton(fieldUnit
).toArray();
47 return Collections
.EMPTY_LIST
.toArray();
52 public Object
[] getChildren(Object parentElement
) {
53 if(parentElement
instanceof DerivateViewEditorInput
){
54 parentElement
= ((DerivateViewEditorInput
) parentElement
).getFieldUnit();
56 if(parentElement
instanceof SpecimenOrObservationBase
){
57 return getDerivates((SpecimenOrObservationBase
) parentElement
).toArray();
63 public Object
getParent(Object element
) {
64 if(element
instanceof DerivateViewEditorInput
){
65 element
= ((DerivateViewEditorInput
) element
).getFieldUnit();
67 if(element
instanceof DerivedUnit
){
68 DerivedUnit derivedUnit
= (DerivedUnit
)element
;
69 return derivedUnit
.getOriginalUnit();
75 public boolean hasChildren(Object element
) {
76 if(element
instanceof DerivateViewEditorInput
){
77 element
= ((DerivateViewEditorInput
) element
).getFieldUnit();
79 if(element
instanceof SpecimenOrObservationBase
){
80 SpecimenOrObservationBase specimenOrObservation
= (SpecimenOrObservationBase
)element
;
81 for(DerivationEvent event
:(Set
<DerivationEvent
>)specimenOrObservation
.getDerivationEvents()){
82 if(!event
.getDerivatives().isEmpty()){
90 private List
<DerivedUnit
> getDerivates(SpecimenOrObservationBase specimenOrObservation
){
91 List
<DerivedUnit
> derivates
= new ArrayList
<DerivedUnit
>();
92 for(DerivationEvent derivationEvent
:(Set
<DerivationEvent
>)specimenOrObservation
.getDerivationEvents()){
93 derivates
.addAll(derivationEvent
.getDerivatives());