KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.jdt.internal.ui.search;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.jface.viewers.ViewerSorter;
17 import org.eclipse.search.ui.ISearchResultViewEntry;
18 import org.eclipse.ui.texteditor.MarkerUtilities;
19
20 /**
21  * Sorts the search result viewer by the matching position.
22  */

23 public class MatchPositionSorter extends ViewerSorter {
24     /*
25      * Overrides method from ViewerSorter
26      */

27     public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
28         int pos1= 0;
29         int pos2= 0;
30
31         if (e1 instanceof ISearchResultViewEntry)
32             pos1= getMatchPosition((ISearchResultViewEntry)e1);
33         if (e2 instanceof ISearchResultViewEntry)
34             pos2= getMatchPosition((ISearchResultViewEntry)e2);
35         return pos1-pos2;
36     }
37     
38     private int getMatchPosition(ISearchResultViewEntry entry) {
39         IMarker marker= entry.getSelectedMarker();
40         if (marker == null)
41             return 0;
42         return MarkerUtilities.getCharStart(marker);
43     }
44
45     /*
46      * Overrides method from ViewerSorter
47      */

48     public boolean isSorterProperty(Object JavaDoc element, String JavaDoc property) {
49         return true;
50     }
51 }
52
Popular Tags