KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > registry > CheatSheetCollectionSorter


1 /*******************************************************************************
2  * Copyright (c) 2002, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.cheatsheets.registry;
12
13 import org.eclipse.jface.viewers.IBasicPropertyConstants;
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.jface.viewers.ViewerComparator;
16 import org.eclipse.ui.model.WorkbenchAdapter;
17
18 import com.ibm.icu.text.Collator;
19
20 /**
21  * A Viewer element sorter that sorts Elements by their name attribute.
22  * Note that capitalization differences are not considered by this
23  * sorter, so a < B < c.
24  */

25 public class CheatSheetCollectionSorter extends ViewerComparator {
26     public final static CheatSheetCollectionSorter INSTANCE = new CheatSheetCollectionSorter();
27     private Collator collator = Collator.getInstance();
28
29     /**
30      * Creates an instance of <code>NewWizardCollectionSorter</code>. Since this
31      * is a stateless sorter, it is only accessible as a singleton; the private
32      * visibility of this constructor ensures this.
33      */

34     private CheatSheetCollectionSorter() {
35         super();
36     }
37
38     /**
39      * The 'compare' method of the sort operation.
40      *
41      * @return the value <code>0</code> if the argument o1 is equal to o2;
42      * a value less than <code>0</code> if o1 is less than o2;
43      * and a value greater than <code>0</code> if o1 is greater than o2.
44      */

45     public int compare(Viewer viewer, Object JavaDoc o1, Object JavaDoc o2) {
46         String JavaDoc name1 = ((WorkbenchAdapter)o1).getLabel(o1);
47         String JavaDoc name2 = ((WorkbenchAdapter)o2).getLabel(o2);
48
49         if (name1.equals(name2))
50             return 0;
51
52         return collator.compare(name1, name2);
53     }
54
55     /**
56      * Return true if this sorter is affected by a property
57      * change of propertyName on the specified element.
58      */

59     public boolean isSorterProperty(Object JavaDoc object, String JavaDoc propertyId) {
60         return propertyId.equals(IBasicPropertyConstants.P_TEXT);
61     }
62 }
63
Popular Tags