KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > StepIntoSelectionHyperlinkDetector


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.jdt.core.IJavaElement;
14 import org.eclipse.jdt.core.IMethod;
15 import org.eclipse.jdt.core.JavaModelException;
16 import org.eclipse.jdt.internal.debug.ui.EvaluationContextManager;
17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18 import org.eclipse.jdt.internal.debug.ui.JavaWordFinder;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.IRegion;
21 import org.eclipse.jface.text.ITextViewer;
22 import org.eclipse.jface.text.TextSelection;
23 import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
24 import org.eclipse.jface.text.hyperlink.IHyperlink;
25 import org.eclipse.ui.IEditorInput;
26 import org.eclipse.ui.texteditor.ITextEditor;
27
28 /**
29  * This is a specialization of a hyperlink detector for the step into selection command
30  *
31  * @since 3.3
32  */

33 public class StepIntoSelectionHyperlinkDetector extends AbstractHyperlinkDetector {
34     
35     /**
36      * Specific implementation of a hyperlink for step into command
37      */

38     class StepIntoSelectionHyperlink implements IHyperlink {
39         
40         private IRegion fRegion = null;
41         
42         /**
43          * Constructor
44          * @param region
45          */

46         public StepIntoSelectionHyperlink(IRegion region) {
47             fRegion = region;
48         }
49         /**
50          * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion()
51          */

52         public IRegion getHyperlinkRegion() {
53             return fRegion;
54         }
55         /**
56          * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText()
57          */

58         public String JavaDoc getHyperlinkText() {
59             return null;
60         }
61         /**
62          * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel()
63          */

64         public String JavaDoc getTypeLabel() {
65             return null;
66         }
67         /**
68          * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
69          */

70         public void open() {
71             StepIntoSelectionActionDelegate delegate = new StepIntoSelectionActionDelegate();
72             delegate.init(JDIDebugUIPlugin.getActiveWorkbenchWindow());
73             delegate.run(null);
74         }
75         
76     }
77
78     /**
79      * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
80      */

81     public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
82         ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class);
83         if(editor != null && !canShowMultipleHyperlinks && EvaluationContextManager.getEvaluationContext(JDIDebugUIPlugin.getActiveWorkbenchWindow()) != null) {
84             IEditorInput input = editor.getEditorInput();
85             IJavaElement element = StepIntoSelectionUtils.getJavaElement(input);
86             int offset = region.getOffset();
87             if(element != null) {
88                 try {
89                     IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
90                     if(document != null) {
91                         IRegion wregion = JavaWordFinder.findWord(document, offset);
92                         if(wregion != null) {
93                             IMethod method = StepIntoSelectionUtils.getMethod(new TextSelection(document, wregion.getOffset(), wregion.getLength()), element);
94                             if (method != null) {
95                                 return new IHyperlink[] {new StepIntoSelectionHyperlink(wregion)};
96                             }
97                         }
98                     }
99                 }
100                 catch(JavaModelException jme) {JDIDebugUIPlugin.log(jme);}
101             }
102         }
103         return null;
104     }
105 }
106
Popular Tags