KickJava   Java API By Example, From Geeks To Geeks.

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


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.IMarker;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
17 import org.eclipse.search.ui.IGroupByKeyComputer;
18
19 public class GroupByKeyComputer implements IGroupByKeyComputer {
20
21     IJavaElement fLastJavaElement= null;
22     String JavaDoc fLastHandle= null;
23
24     public Object JavaDoc computeGroupByKey(IMarker marker) {
25         if (marker == null)
26             return null;
27         
28         IJavaElement jElement= getJavaElement(marker);
29         if (jElement != null && jElement.exists()) {
30             // no help from JavaModel to rename yet
31
// return getJavaElement(marker);
32
return fLastHandle;
33         }
34         return null;
35     }
36
37     private String JavaDoc getJavaElementHandleId(IMarker marker) {
38         try {
39             return (String JavaDoc)marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID);
40         } catch (CoreException ex) {
41             ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$
42
return null;
43         }
44     }
45     
46     private IJavaElement getJavaElement(IMarker marker) {
47         String JavaDoc handle= getJavaElementHandleId(marker);
48         if (handle == null) {
49             fLastHandle= null;
50             fLastJavaElement= null;
51             return null;
52         }
53         
54         if (!handle.equals(fLastHandle)) {
55             fLastJavaElement= SearchUtil.getJavaElement(marker);
56             if (fLastJavaElement != null)
57                 fLastHandle= fLastJavaElement.getHandleIdentifier();
58             else
59                 fLastHandle= null;
60         }
61         return fLastJavaElement;
62     }
63 }
64
Popular Tags