KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > OpenEditorAtLineAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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  * Sebastian Davids: sdavids@gmx.de bug 37333 Failure Trace cannot
11  * navigate to non-public class in CU throwing Exception
12  *******************************************************************************/

13 package org.eclipse.jdt.internal.junit.ui;
14
15 import org.eclipse.core.runtime.CoreException;
16
17 import org.eclipse.jface.text.BadLocationException;
18 import org.eclipse.jface.text.IDocument;
19
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.texteditor.ITextEditor;
22
23 import org.eclipse.jdt.core.IJavaElement;
24 import org.eclipse.jdt.core.IJavaProject;
25
26 /**
27  * Open a test in the Java editor and reveal a given line
28  */

29 public class OpenEditorAtLineAction extends OpenEditorAction {
30
31     private int fLineNumber;
32     
33     public OpenEditorAtLineAction(TestRunnerViewPart testRunner, String JavaDoc cuName, String JavaDoc className, int line) {
34         super(testRunner, className);
35         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJUnitHelpContextIds.OPENEDITORATLINE_ACTION);
36         fLineNumber= line;
37     }
38         
39     protected void reveal(ITextEditor textEditor) {
40         if (fLineNumber >= 0) {
41             try {
42                 IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
43                 textEditor.selectAndReveal(document.getLineOffset(fLineNumber-1), document.getLineLength(fLineNumber-1));
44             } catch (BadLocationException x) {
45                 // marker refers to invalid text position -> do nothing
46
}
47         }
48     }
49     
50     protected IJavaElement findElement(IJavaProject project, String JavaDoc className) throws CoreException {
51         return findType(project, className);
52     }
53
54 }
55
Popular Tags