merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / PolytomousKeyContentProvider.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.navigation.key.polytomous;
5
6 import java.util.Collections;
7 import java.util.Comparator;
8 import java.util.List;
9
10 import org.eclipse.jface.viewers.IStructuredContentProvider;
11 import org.eclipse.jface.viewers.Viewer;
12
13 /**
14 * @author n.hoffmann
15 *
16 */
17 public class PolytomousKeyContentProvider implements IStructuredContentProvider{
18
19 @Override
20 public void dispose() {
21
22 }
23
24 @Override
25 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
26
27 }
28
29 @Override
30 public Object[] getElements(Object inputElement) {
31 if(inputElement instanceof List){
32
33 Collections.sort((List)inputElement,new PolytomousKeyComparator());
34 return ((List) inputElement).toArray();
35 }
36 return null;
37 }
38
39 public class PolytomousKeyComparator implements Comparator<Object> {
40
41 @Override
42 public int compare(Object o1, Object o2) {
43 if(o1 == null && o2 == null) {
44 return 0;
45 } else if (o1 == null) {
46 return -1;
47 } else if(o2 == null) {
48 return +1;
49 } else {
50 return o1.toString().compareTo(o2.toString());
51 }
52 }
53
54 }
55
56 }