KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.viewers.Viewer;
14 import org.eclipse.search.ui.ISearchResultViewEntry;
15
16 /**
17  * Sorts the search result viewer by the Java Element name.
18  */

19 public class ElementNameSorter extends JavaSearchSorter {
20     
21     /*
22      * Overrides method from ViewerSorter
23      */

24     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
25         String JavaDoc name1= null;
26         String JavaDoc name2= null;
27
28         if (e1 instanceof ISearchResultViewEntry)
29             name1= getLabel(e1);
30         if (e2 instanceof ISearchResultViewEntry)
31             name2= getLabel(e2);
32         if (name1 == null)
33             name1= ""; //$NON-NLS-1$
34
if (name2 == null)
35             name2= ""; //$NON-NLS-1$
36
return getCollator().compare(name1, name2);
37     }
38
39     protected int getLabelAppearance() {
40         return JavaSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER;
41     }
42 }
43
Popular Tags