| 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 exceptions to the above: an element with the system's reserved |
| 24 | * category for Other Wizards will always be sorted such that it will |
| 25 | * ultimately be placed at the end of the sorted result, and an elemen |
| 26 | * with the reserved category name for General wizards will always be |
| 27 | * placed at the beginning of the sorted result. |
| 28 | * |
| 29 | * @since 3.2 |
| 30 | */ |
| 31 | class DataTransferWizardCollectionComparator extends ViewerComparator { |
| 32 | /** |
| 33 | * Static instance of this class. |
| 34 | */ |
| 35 | public final static DataTransferWizardCollectionComparator INSTANCE = new DataTransferWizardCollectionComparator(); |
| 36 | |
| 37 | /** |
| 38 | * Creates an instance of <code>DataTransferWizardCollectionSorter</code>. Since this |
| 39 | * is a stateless sorter, it is only accessible as a singleton; the private |
| 40 | * visibility of this constructor ensures this. |
| 41 | */ |
| 42 | private DataTransferWizardCollectionComparator() { |
| 43 | super(); |
| 44 | } |
| 45 | |
| 46 | public int category(Object element) { |
| 47 | if (element instanceof WizardCollectionElement){ |
| 48 | String id = ((WizardCollectionElement)element).getId(); |
| 49 | if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY.equals(id)) { |
| 50 | return 1; |
| 51 | } |
| 52 | if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY.equals(id)) { |
| 53 | return 3; |
| 54 | } |
| 55 | return 2; |
| 56 | } |
| 57 | return super.category(element); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Return true if this sorter is affected by a property |
| 62 | * change of propertyName on the specified element. |
| 63 | */ |
| 64 | public boolean isSorterProperty(Object object, String propertyId) { |
| 65 | return propertyId.equals(IBasicPropertyConstants.P_TEXT); |
| 66 | } |
| 67 | } |