01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import com.ibm.icu.text.Collator;
13: import java.util.Comparator;
14:
15: import org.eclipse.ui.IWorkingSet;
16:
17: /**
18: * Compares two working sets by name.
19: */
20: public class WorkingSetComparator implements Comparator {
21:
22: /**
23: * Static instance of this class.
24: * @since 3.2
25: */
26: public static WorkingSetComparator INSTANCE = new WorkingSetComparator();
27:
28: private Collator fCollator = Collator.getInstance();
29:
30: /**
31: * Implements Comparator.
32: *
33: * @see Comparator#compare(Object, Object)
34: */
35: public int compare(Object o1, Object o2) {
36: String name1 = null;
37: String name2 = null;
38:
39: if (o1 instanceof IWorkingSet) {
40: name1 = ((IWorkingSet) o1).getLabel();
41: }
42:
43: if (o2 instanceof IWorkingSet) {
44: name2 = ((IWorkingSet) o2).getLabel();
45: }
46:
47: int result = fCollator.compare(name1, name2);
48: if (result == 0) { // okay, same name - now try the unique id
49:
50: if (o1 instanceof IWorkingSet) {
51: name1 = ((IWorkingSet) o1).getName();
52: }
53:
54: if (o2 instanceof IWorkingSet) {
55: name2 = ((IWorkingSet) o2).getName();
56: }
57:
58: result = fCollator.compare(name1, name2);
59: }
60: return result;
61: }
62: }
|