KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > nls > search > NLSGroupByKeyComputer


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.refactoring.nls.search;
12
13 import org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.JavaModelException;
20
21 import org.eclipse.search.ui.IGroupByKeyComputer;
22
23 import org.eclipse.jdt.internal.ui.search.IJavaSearchUIConstants;
24 import org.eclipse.jdt.internal.ui.search.SearchMessages;
25 import org.eclipse.jdt.internal.ui.search.SearchUtil;
26 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
27
28 /** @deprecated */
29 class NLSGroupByKeyComputer implements IGroupByKeyComputer {
30
31     IJavaElement fLastJavaElement= null;
32     String JavaDoc fLastHandle= null;
33
34     public Object JavaDoc computeGroupByKey(IMarker marker) {
35         if (marker == null || marker.getResource() == null)
36             return null;
37         
38         if (!marker.getResource().getName().endsWith(".java")) //$NON-NLS-1$
39
return marker.getResource();
40         
41         IJavaElement jElement= getJavaElement(marker);
42         if (jElement != null && jElement.exists()) {
43             // no help from JavaModel to rename yet
44
// return getJavaElement(marker);
45
return fLastHandle;
46         }
47         return null;
48     }
49
50     private String JavaDoc getJavaElementHandleId(IMarker marker) {
51         try {
52             return (String JavaDoc)marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID);
53         } catch (CoreException ex) {
54             ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$
55
return null;
56         }
57     }
58     
59     private IJavaElement getJavaElement(IMarker marker) {
60         String JavaDoc handle= getJavaElementHandleId(marker);
61         if (handle == null) {
62             fLastHandle= null;
63             fLastJavaElement= null;
64             return null;
65         }
66         
67         if (!handle.equals(fLastHandle)) {
68             fLastHandle= handle;
69             fLastJavaElement= SearchUtil.getJavaElement(marker);
70             IResource handleResource= null;
71             try {
72                 if (fLastJavaElement != null)
73                     handleResource= fLastJavaElement.getCorrespondingResource();
74             } catch (JavaModelException ex) {
75                 ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.javaElementAccess.title"), SearchMessages.getString("Search.Error.javaElementAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$
76
// handleResource= null;
77
}
78             if (fLastJavaElement != null && marker.getResource().equals(handleResource)) {
79                 // need to get and set new handle here
80
}
81         }
82         return fLastJavaElement;
83     }
84 }
85
Popular Tags