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.dialogs;
11:
12: import org.eclipse.jface.viewers.IBasicPropertyConstants;
13: import org.eclipse.jface.viewers.ViewerComparator;
14: import org.eclipse.ui.internal.registry.WizardsRegistryReader;
15:
16: /**
17: * A Viewer element sorter that sorts Elements by their name attribute.
18: * Note that capitalization differences are not considered by this
19: * sorter, so a < B < c.
20: *
21: * NOTE one exception to the above: an element with the system's reserved
22: * name for base Wizards will always be sorted such that it will
23: * ultimately be placed at the beginning of the sorted result.
24: */
25: class NewWizardCollectionComparator extends ViewerComparator {
26: /**
27: * Static instance of this class.
28: */
29: public final static NewWizardCollectionComparator INSTANCE = new NewWizardCollectionComparator();
30:
31: /**
32: * Creates an instance of <code>NewWizardCollectionSorter</code>. Since this
33: * is a stateless sorter, it is only accessible as a singleton; the private
34: * visibility of this constructor ensures this.
35: */
36: private NewWizardCollectionComparator() {
37: super ();
38: }
39:
40: /*
41: * (non-Javadoc)
42: * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
43: */
44: public int category(Object element) {
45: if (element instanceof WorkbenchWizardElement) {
46: return -1;
47: }
48: if (element instanceof WizardCollectionElement) {
49: String id = ((WizardCollectionElement) element).getId();
50: if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY
51: .equals(id)) {
52: return 1;
53: }
54: if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY
55: .equals(id)) {
56: return 3;
57: }
58: if (WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY
59: .equals(id)) {
60: return 4;
61: }
62: return 2;
63: }
64: return super .category(element);
65: }
66:
67: /**
68: * Return true if this sorter is affected by a property
69: * change of propertyName on the specified element.
70: */
71: public boolean isSorterProperty(Object object, String propertyId) {
72: return propertyId.equals(IBasicPropertyConstants.P_TEXT);
73: }
74: }
|