KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > NameSorter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.search;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.jdt.core.IJavaElement;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.jface.viewers.ViewerSorter;
17
18 public class NameSorter extends ViewerSorter {
19     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
20         String JavaDoc property1= getProperty(e1);
21         String JavaDoc property2= getProperty(e2);
22         return collator.compare(property1, property2);
23     }
24
25     protected String JavaDoc getProperty(Object JavaDoc element) {
26         if (element instanceof IJavaElement)
27             return ((IJavaElement)element).getElementName();
28         if (element instanceof IResource)
29             return ((IResource)element).getName();
30         return ""; //$NON-NLS-1$
31
}
32 }
33
Popular Tags