KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > NewWizardCollectionComparator


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
12 package org.eclipse.ui.internal.dialogs;
13
14 import org.eclipse.jface.viewers.IBasicPropertyConstants;
15 import org.eclipse.jface.viewers.ViewerComparator;
16 import org.eclipse.ui.internal.registry.WizardsRegistryReader;
17
18 /**
19  * A Viewer element sorter that sorts Elements by their name attribute.
20  * Note that capitalization differences are not considered by this
21  * sorter, so a < B < c.
22  *
23  * NOTE one exception to the above: an element with the system's reserved
24  * name for base Wizards will always be sorted such that it will
25  * ultimately be placed at the beginning of the sorted result.
26  */

27 class NewWizardCollectionComparator extends ViewerComparator {
28     /**
29      * Static instance of this class.
30      */

31     public final static NewWizardCollectionComparator INSTANCE = new NewWizardCollectionComparator();
32
33
34     /**
35      * Creates an instance of <code>NewWizardCollectionSorter</code>. Since this
36      * is a stateless sorter, it is only accessible as a singleton; the private
37      * visibility of this constructor ensures this.
38      */

39     private NewWizardCollectionComparator() {
40         super();
41     }
42
43     /*
44      * (non-Javadoc)
45      * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
46      */

47     public int category(Object JavaDoc element) {
48         if (element instanceof WorkbenchWizardElement) {
49             return -1;
50         }
51         if (element instanceof WizardCollectionElement){
52             String JavaDoc id = ((WizardCollectionElement)element).getId();
53             if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY.equals(id)) {
54                 return 1;
55             }
56             if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY.equals(id)) {
57                 return 3;
58             }
59             if (WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY.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 JavaDoc object, String JavaDoc propertyId) {
72         return propertyId.equals(IBasicPropertyConstants.P_TEXT);
73     }
74 }
75
Popular Tags