Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Go to a given line number and file in the main editor?
Go to a given line number and file in the main editor? [message #186419] Wed, 03 January 2007 01:31 Go to next message
Eclipse UserFriend
Originally posted by: alexmont1.comcast.net

I am developing an Eclipse plugin that has a view with several sections in
it. In one of these sections is a list of source files with line numbers
associated with them (e.g. "SomeClass.java, line 643"). What I want to
know how to do is make it so that when a user clicks on one of these, the
editor will go to that source file and that line.

I already know how to make a list or link that has a SelectionListener
that executes a function when you click on it, but I need to know what the
command is to tell the editor to go to a particular line of a particular
source file.

Essentially, I want to do exactly the same thing that the built-in
Problems view does (i.e. open an editor for the target file, or go to it
if there already is one, and go to a particular place in that file),
except that there is not necessarily a marker at the target line.
Re: Go to a given line number and file in the main editor? [message #186449 is a reply to message #186419] Wed, 03 January 2007 08:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benno_baumgartner.ch.ibm.com

Alexander Mont wrote:
> I am developing an Eclipse plugin that has a view with several sections
> in it. In one of these sections is a list of source files with line
> numbers associated with them (e.g. "SomeClass.java, line 643"). What I
> want to know how to do is make it so that when a user clicks on one of
> these, the editor will go to that source file and that line.
>
> I already know how to make a list or link that has a SelectionListener
> that executes a function when you click on it, but I need to know what
> the command is to tell the editor to go to a particular line of a
> particular source file.
>
> Essentially, I want to do exactly the same thing that the built-in
> Problems view does (i.e. open an editor for the target file, or go to it
> if there already is one, and go to a particular place in that file),
> except that there is not necessarily a marker at the target line.
>

Hi Alexander

Try something along the line of:
((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compila tionUnit)).selectAndReveal(int,
int);

HTH
Benno
Re: Go to a given line number and file in the main editor? [message #186639 is a reply to message #186449] Thu, 04 January 2007 04:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexmont1.comcast.net

That should work, but I am still a little confused. I have the class name
as a String. I can't figure out how to, given a string that is the name of
a source file, get the ICompilationUnit representing that source file.
Re: Go to a given line number and file in the main editor? [message #186721 is a reply to message #186639] Thu, 04 January 2007 13:48 Go to previous message
Eclipse UserFriend
Originally posted by: benno_baumgartner.ch.ibm.com

Alexander Mont wrote:
> That should work, but I am still a little confused. I have the class
> name as a String. I can't figure out how to, given a string that is the
> name of a source file, get the ICompilationUnit representing that source
> file.
>

Once you have the source file you can get the cu through:
org.eclipse.jdt.core.JavaCore.create(IFile)

I don't know how to obtain the file. If you have a fully qualified file
name you could use
ResourcePlugin.getWorkspace().getRoot().findMember(IPath) if you do not
have the fully qualified name then you must search the file in the
workspace. This would be slow, and of course you could have multiple
matches.

HTH
Benno
Previous Topic:Document with long lines taking toooooo long time to open esp: StyledTextWidget
Next Topic:Execute a Java program with a button
Goto Forum:
  


Current Time: Thu Apr 25 03:54:48 GMT 2024

Powered by FUDForum. Page generated in 0.07911 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top