1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.preference.wizard;
|
10
|
|
11
|
import org.eclipse.jface.viewers.Viewer;
|
12
|
import org.eclipse.jface.viewers.ViewerComparator;
|
13
|
|
14
|
/**
|
15
|
* @author k.luther
|
16
|
* @since 04.10.2018
|
17
|
*
|
18
|
*/
|
19
|
public class AreaViewerComparator extends ViewerComparator {
|
20
|
|
21
|
/**
|
22
|
* Returns a negative, zero, or positive number depending on whether
|
23
|
* the first element is less than, equal to, or greater than
|
24
|
* the second element.
|
25
|
* <p>
|
26
|
* The default implementation of this method is based on
|
27
|
* comparing the elements' categories as computed by the <code>category</code>
|
28
|
* framework method. Elements within the same category are further
|
29
|
* subjected to a case insensitive compare of their label strings, either
|
30
|
* as computed by the content viewer's label provider, or their
|
31
|
* <code>toString</code> values in other cases. Subclasses may override.
|
32
|
* </p>
|
33
|
*
|
34
|
* @param viewer the viewer
|
35
|
* @param e1 the first element
|
36
|
* @param e2 the second element
|
37
|
* @return a negative number if the first element is less than the
|
38
|
* second element; the value <code>0</code> if the first element is
|
39
|
* equal to the second element; and a positive number if the first
|
40
|
* element is greater than the second element
|
41
|
*/
|
42
|
@Override
|
43
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
44
|
int cat1 = category(e1);
|
45
|
int cat2 = category(e2);
|
46
|
|
47
|
if (cat1 != cat2) {
|
48
|
return cat1 - cat2;
|
49
|
}
|
50
|
|
51
|
if (e1 instanceof NamedAreaWrapper && e2 instanceof NamedAreaWrapper){
|
52
|
NamedAreaWrapper wrapper1 = (NamedAreaWrapper)e1;
|
53
|
NamedAreaWrapper wrapper2 = (NamedAreaWrapper)e2;
|
54
|
|
55
|
if (wrapper1.isBaseElement == wrapper2.isBaseElement){
|
56
|
return super.compare(viewer, e1, e2);
|
57
|
}else if (wrapper1.isBaseElement){
|
58
|
return -1;
|
59
|
}else{
|
60
|
return 1;
|
61
|
}
|
62
|
}else{
|
63
|
return super.compare(viewer, e1, e2);
|
64
|
}
|
65
|
|
66
|
}
|
67
|
|
68
|
|
69
|
}
|