KickJava   Java API By Example, From Geeks To Geeks.

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


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.IFile;
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.JavaCore;
20 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.Position;
23 import org.eclipse.search.ui.NewSearchUI;
24 import org.eclipse.ui.texteditor.IMarkerUpdater;
25 import org.eclipse.ui.texteditor.MarkerUtilities;
26
27 public class JavaSearchMarkerUpdater implements IMarkerUpdater {
28     
29     
30     public JavaSearchMarkerUpdater() {
31         super();
32     }
33     
34     /**
35      * @see IMarkerUpdater#updateMarker(IMarker, IDocument, Position)
36      */

37     public boolean updateMarker(IMarker marker, IDocument document, Position position) {
38         
39         try {
40             String JavaDoc id= (String JavaDoc) marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID);
41             if (id != null) {
42                 IJavaElement j= JavaCore.create(id);
43                 if (j == null || !j.exists() || !j.isStructureKnown()) {
44                     IResource resource= marker.getResource();
45                     if (MarkerUtilities.getCharStart(marker) != -1 && MarkerUtilities.getCharEnd(marker) != -1 && resource instanceof IFile) {
46                         Object JavaDoc o= JavaCore.create(resource);
47                         if (o instanceof ICompilationUnit) {
48                             IJavaElement element= ((ICompilationUnit) o).getElementAt(position.getOffset());
49                             if (element != null) {
50                                 marker.setAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID, element.getHandleIdentifier());
51                                 marker.setAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID_CHANGED, new Boolean JavaDoc(true));
52                                 return true;
53                             }
54                             else
55                                 return false;
56                         }
57                     }
58                 } else {
59                     return true;
60                 }
61             }
62             else
63                 // no java search marker
64
return true;
65         } catch (CoreException ex) {
66             ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$
67
}
68         return false;
69     }
70     
71     /**
72      * @see IMarkerUpdater#getAttribute()
73      */

74     public String JavaDoc[] getAttribute() {
75         return new String JavaDoc[] { IJavaSearchUIConstants.ATT_JE_HANDLE_ID };
76     }
77
78     /**
79      * @see IMarkerUpdater#getMarkerType()
80      */

81     public String JavaDoc getMarkerType() {
82         return NewSearchUI.SEARCH_MARKER;
83     }
84 }
85
Popular Tags