67c826f0da6976847e107c9780f582fc3596912d
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / TaxonNodeComparator.java
1 package eu.etaxonomy.taxeditor.navigation.navigator;
2
3 import java.util.Arrays;
4 import java.util.Comparator;
5
6
7 import org.eclipse.jface.viewers.Viewer;
8 import org.eclipse.jface.viewers.ViewerComparator;
9
10
11 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
12 import eu.etaxonomy.cdm.model.taxon.Classification;
13 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14 import eu.etaxonomy.cdm.model.taxon.TaxonComparatorSearch;
15 import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
16 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
17 import eu.etaxonomy.taxeditor.ui.section.supplemental.IdentifiableSourceElement;
18
19 public class TaxonNodeComparator extends ViewerComparator{
20
21
22 public TaxonNodeComparator(Comparator<TaxonBase> comparator){
23 super(comparator);
24 }
25
26
27
28 @Override
29 public int compare(Viewer viewer, Object e1, Object e2){
30 if (e1 instanceof Classification && e2 instanceof Classification){
31 return ((Classification)e1).getTitleCache().compareTo(((Classification)e2).getTitleCache());
32 } else{
33 if (this.getComparator() instanceof TaxonNaturalComparator){
34 return this.getComparator().compare((TaxonNode)e1, (TaxonNode)e2);
35 }else{
36 return this.getComparator().compare(((TaxonNode)e1).getTaxon(),((TaxonNode)e2).getTaxon());
37 }
38 }
39 }
40 }