01: /*******************************************************************************
02: * Copyright (c) 2002, 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.cheatsheets.registry;
11:
12: import org.eclipse.jface.viewers.IBasicPropertyConstants;
13: import org.eclipse.jface.viewers.Viewer;
14: import org.eclipse.jface.viewers.ViewerComparator;
15: import org.eclipse.ui.model.WorkbenchAdapter;
16:
17: import com.ibm.icu.text.Collator;
18:
19: /**
20: * A Viewer element sorter that sorts Elements by their name attribute.
21: * Note that capitalization differences are not considered by this
22: * sorter, so a < B < c.
23: */
24: public class CheatSheetCollectionSorter extends ViewerComparator {
25: public final static CheatSheetCollectionSorter INSTANCE = new CheatSheetCollectionSorter();
26: private Collator collator = Collator.getInstance();
27:
28: /**
29: * Creates an instance of <code>NewWizardCollectionSorter</code>. Since this
30: * is a stateless sorter, it is only accessible as a singleton; the private
31: * visibility of this constructor ensures this.
32: */
33: private CheatSheetCollectionSorter() {
34: super ();
35: }
36:
37: /**
38: * The 'compare' method of the sort operation.
39: *
40: * @return the value <code>0</code> if the argument o1 is equal to o2;
41: * a value less than <code>0</code> if o1 is less than o2;
42: * and a value greater than <code>0</code> if o1 is greater than o2.
43: */
44: public int compare(Viewer viewer, Object o1, Object o2) {
45: String name1 = ((WorkbenchAdapter) o1).getLabel(o1);
46: String name2 = ((WorkbenchAdapter) o2).getLabel(o2);
47:
48: if (name1.equals(name2))
49: return 0;
50:
51: return collator.compare(name1, name2);
52: }
53:
54: /**
55: * Return true if this sorter is affected by a property
56: * change of propertyName on the specified element.
57: */
58: public boolean isSorterProperty(Object object, String propertyId) {
59: return propertyId.equals(IBasicPropertyConstants.P_TEXT);
60: }
61: }
|