|
Lines 24-31
Link Here
|
| 24 |
* Static instance of this class. |
24 |
* Static instance of this class. |
| 25 |
* @since 3.2 |
25 |
* @since 3.2 |
| 26 |
*/ |
26 |
*/ |
| 27 |
public static WorkingSetComparator INSTANCE = new WorkingSetComparator(); |
27 |
public static WorkingSetComparator INSTANCE_NAMES_ONLY = new WorkingSetComparator(false); |
| 28 |
|
28 |
|
|
|
29 |
public static WorkingSetComparator INSTANCE_LABELS_NAMES = new WorkingSetComparator(); |
| 30 |
|
| 31 |
private boolean useLabels; |
| 32 |
|
| 33 |
public WorkingSetComparator(){ |
| 34 |
this(true); |
| 35 |
} |
| 36 |
|
| 37 |
public WorkingSetComparator(boolean useLabels){ |
| 38 |
this.useLabels=useLabels; |
| 39 |
} |
| 29 |
private Collator fCollator = Collator.getInstance(); |
40 |
private Collator fCollator = Collator.getInstance(); |
| 30 |
|
41 |
|
| 31 |
/** |
42 |
/** |
|
Lines 34-62
Link Here
|
| 34 |
* @see Comparator#compare(Object, Object) |
45 |
* @see Comparator#compare(Object, Object) |
| 35 |
*/ |
46 |
*/ |
| 36 |
public int compare(Object o1, Object o2) { |
47 |
public int compare(Object o1, Object o2) { |
| 37 |
String name1 = null; |
48 |
String name1 = null; |
| 38 |
String name2 = null; |
49 |
String name2 = null; |
| 39 |
|
50 |
int result = 0; |
| 40 |
if (o1 instanceof IWorkingSet) { |
51 |
if(useLabels){ |
| 41 |
name1 = ((IWorkingSet) o1).getLabel(); |
52 |
if (o1 instanceof IWorkingSet) { |
| 42 |
} |
53 |
name1 = ((IWorkingSet) o1).getLabel(); |
| 43 |
|
54 |
} |
| 44 |
if (o2 instanceof IWorkingSet) { |
55 |
|
| 45 |
name2 = ((IWorkingSet) o2).getLabel(); |
56 |
if (o2 instanceof IWorkingSet) { |
| 46 |
} |
57 |
name2 = ((IWorkingSet) o2).getLabel(); |
| 47 |
|
58 |
} |
| 48 |
int result = fCollator.compare(name1, name2); |
59 |
|
| 49 |
if (result == 0) { // okay, same name - now try the unique id |
60 |
result = fCollator.compare(name1, name2); |
| 50 |
|
61 |
} |
| 51 |
if (o1 instanceof IWorkingSet) { |
62 |
if (result == 0) { // okay, same name - now try the unique id |
| 52 |
name1 = ((IWorkingSet) o1).getName(); |
63 |
|
| 53 |
} |
64 |
if (o1 instanceof IWorkingSet) { |
| 54 |
|
65 |
name1 = ((IWorkingSet) o1).getName(); |
| 55 |
if (o2 instanceof IWorkingSet) { |
66 |
} |
| 56 |
name2 = ((IWorkingSet) o2).getName(); |
67 |
|
| 57 |
} |
68 |
if (o2 instanceof IWorkingSet) { |
| 58 |
result = name1.compareTo(name2); |
69 |
name2 = ((IWorkingSet) o2).getName(); |
| 59 |
} |
70 |
} |
| 60 |
return result; |
71 |
result = name1.compareTo(name2); |
| 61 |
} |
72 |
} |
|
|
73 |
return result; |
| 74 |
} |
| 62 |
} |
75 |
} |