KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > WizardCollectionSorter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.pde.internal.ui.wizards;
12
13 import org.eclipse.jface.viewers.Viewer;
14 import org.eclipse.jface.viewers.ViewerSorter;
15
16 public class WizardCollectionSorter extends ViewerSorter {
17     private String JavaDoc baseCategory;
18
19 public WizardCollectionSorter(String JavaDoc baseCategory) {
20     this.baseCategory = baseCategory;
21 }
22 public int compare(Viewer viewer, Object JavaDoc o1, Object JavaDoc o2) {
23     String JavaDoc name2 = ((WizardCollectionElement) o2).getLabel();
24     String JavaDoc name1 = ((WizardCollectionElement) o1).getLabel();
25     if (name2.equals(name1))
26         return 0;
27
28     if (baseCategory != null) {
29         // note that this must be checked for name2 before name1 because if they're
30
// BOTH equal to baseCategory then we want to answer false by convention
31
if (name2.equalsIgnoreCase(baseCategory))
32             return -1;
33
34         if (name1.equalsIgnoreCase(baseCategory))
35             return 1;
36     }
37
38     return name2.compareTo(name1);
39 }
40 public boolean isSorterProperty(Object JavaDoc object,Object JavaDoc propertyId) {
41     return true;
42 }
43 }
44
Popular Tags