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.pde.internal.ui.wizards;
11:
12: import org.eclipse.jface.viewers.Viewer;
13: import org.eclipse.jface.viewers.ViewerComparator;
14:
15: public class WizardCollectionComparator extends ViewerComparator {
16: private String baseCategory;
17:
18: public WizardCollectionComparator(String baseCategory) {
19: this .baseCategory = baseCategory;
20: }
21:
22: public int compare(Viewer viewer, Object o1, Object o2) {
23: String name2 = ((WizardCollectionElement) o2).getLabel();
24: String 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:
41: public boolean isSorterProperty(Object object, Object propertyId) {
42: return true;
43: }
44: }
|