Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JavaEditor question !
JavaEditor question ! [message #202873] Sun, 08 May 2005 14:27 Go to next message
Eclipse UserFriend
Originally posted by: jerryisdaman.gmail.com

hi
Does anyone know how to get the document offset of the keyborad cursor in
the JavaEditor ?

e.g. suppose below is a file opened by java editor and "|" represents
the keyborad cursor , the cursor location or document offst is 8 (7
characters + 1 space). and how to get this locaion programatically ?

Testing |
Re: JavaEditor question ! [message #202897 is a reply to message #202873] Mon, 09 May 2005 08:14 Go to previous messageGo to next message
Tom Hofmann is currently offline Tom HofmannFriend
Messages: 770
Registered: July 2009
Senior Member
AbstractTextEditor editor;

ITextSelection selection=
(ITextSelection) editor.getSelectionProvider().getSelection()

-tom

J wrote:
> hi Does anyone know how to get the document offset of the keyborad
> cursor in the JavaEditor ?
> e.g. suppose below is a file opened by java editor and "|" represents
> the keyborad cursor , the cursor location or document offst is 8 (7
> characters + 1 space). and how to get this locaion programatically ?
>
> Testing |
>
Re: JavaEditor question ! [message #203960 is a reply to message #202897] Wed, 18 May 2005 01:22 Go to previous messageGo to next message
Gary Horen is currently offline Gary HorenFriend
Messages: 18
Registered: July 2009
Junior Member
Further questions:

1. Once I get the Selection, I would like to translate it into an
IJavaElement. I have found one way to do this: if you inherit from
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor (bad idea!) you
can call CompilationUnitEditor#getElementAt(). So, is there a more approved
way to do this? One that would not use an internal API?

2. The class used to provide a selection change listener
(AbstractSelectionChangeListener) is a protected inner class of
AbstractTextEditor. Is there an approved way to add (install()?) a selection
change listener to the editor infrastructure somewhere? I believe that what
I want is to somehow get into the chain of notifications that the Outline
pane takes advanatage of.

Thanks,
-Gary Horen


"Tom Eicher" <eclipse@tom.eicher.name> wrote in message
news:d5n6i6$7u4$1@news.eclipse.org...
> AbstractTextEditor editor;
>
> ITextSelection selection=
> (ITextSelection) editor.getSelectionProvider().getSelection()
>
> -tom
>
> J wrote:
>> hi Does anyone know how to get the document offset of the keyborad cursor
>> in the JavaEditor ? e.g. suppose below is a file opened by java editor
>> and "|" represents the keyborad cursor , the cursor location or document
>> offst is 8 (7 characters + 1 space). and how to get this locaion
>> programatically ?
>>
>> Testing |
>>
Re: JavaEditor question ! [message #203999 is a reply to message #203960] Wed, 18 May 2005 12:13 Go to previous message
Tom Hofmann is currently offline Tom HofmannFriend
Messages: 770
Registered: July 2009
Senior Member
Gary Horen wrote:
> 1. Once I get the Selection, I would like to translate it into an
> IJavaElement. I have found one way to do this: if you inherit from
> org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor (bad idea!) you
> can call CompilationUnitEditor#getElementAt(). So, is there a more approved
> way to do this? One that would not use an internal API?

Well, then see what CompilationUnitEditor#getElementAt() does... and
also see ICodeAssist.codeSelect.

> 2. The class used to provide a selection change listener
> (AbstractSelectionChangeListener) is a protected inner class of
> AbstractTextEditor. Is there an approved way to add (install()?) a selection
> change listener to the editor infrastructure somewhere? I believe that what
> I want is to somehow get into the chain of notifications that the Outline
> pane takes advanatage of.

See ISelectionProvider and IPostSelectionProvider (and get one from
ITextEditor.getSelectionProvider).

HTH, tom
Previous Topic:M7 is great, just two little things...
Next Topic:Problems/Tasks for only one resource
Goto Forum:
  


Current Time: Sat Nov 09 00:13:48 GMT 2024

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

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

Back to the top