Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Can I be notified of Java editor's currently selected element, like the content outline is?
Can I be notified of Java editor's currently selected element, like the content outline is? [message #212483] Sun, 14 August 2005 06:23 Go to next message
Guillaume Pothier is currently offline Guillaume PothierFriend
Messages: 5
Registered: July 2009
Junior Member
Hi,
Whenever I move the caret to a certain position in the java editor, the
corresponding java element is automatically selected in the outline
view. I want to create a view with the same behavior, but it seems I
cannot do that using public API: the java editor directly tells the
outline view to change its selection, but the ISelectionService knows
nothing about it.
I guess I could listen to selection changes in the outline view, but
what if the user did not open it?
For now the only way I can think of doing it is accessing the
JavaEditor, which is an internal class, and use reflexion to call the
protected computeHighlightRangeSourceReference() method. Not exactly
clean...
Is there a better way to do it now? If not, is a better way planned?
Regards
Guillaume Pothier
Re: Can I be notified of Java editor's currently selected element, like the cont [message #212676 is a reply to message #212483] Tue, 16 August 2005 17:06 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
Guillaume Pothier wrote:

> Hi,
> Whenever I move the caret to a certain position in the java editor, the
> corresponding java element is automatically selected in the outline
> view. I want to create a view with the same behavior, but it seems I
> cannot do that using public API: the java editor directly tells the
> outline view to change its selection, but the ISelectionService knows
> nothing about it.
> I guess I could listen to selection changes in the outline view, but
> what if the user did not open it?
> For now the only way I can think of doing it is accessing the
> JavaEditor, which is an internal class, and use reflexion to call the
> protected computeHighlightRangeSourceReference() method. Not exactly
> clean...
> Is there a better way to do it now? If not, is a better way planned?
> Regards
> Guillaume Pothier


Take a look at JavaBrowsingPart.selectedChanged or more specifically
org.eclipse.jdt.internal.ui.browsing.setSelectionFromEditor( IWorkbenchPart,
ISelection). It's an internal class, but this is the code I looked at to
figure out how to make a view update from the JavaEditor selections.

You will also need to call
getViewSite().getPage().addPostSelectionListener(ISelectionL istener). The
WorkbenchPage actually handles notifying selectionListeners, not the
JavaEditor.

Karen
Re: Can I be notified of Java editor's currently selected element, like the cont [message #212707 is a reply to message #212483] Wed, 17 August 2005 06:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: prasadmpatil.gmail.com

Hi Guillaume,

This can also be done using AST. Take a look at the following plugin which
does something similar.

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt- ui-home/plugins/org.eclipse.jdt.astview/index.html

HTH
~Prasad
Re: Can I be notified of Java editor's currently selected element, like the cont [message #212730 is a reply to message #212676] Wed, 17 August 2005 14:31 Go to previous message
Guillaume Pothier is currently offline Guillaume PothierFriend
Messages: 5
Registered: July 2009
Junior Member
Karen Moore wrote:
> Guillaume Pothier wrote:
>
>> Hi,
>> Whenever I move the caret to a certain position in the java editor,
>> the corresponding java element is automatically selected in the
>> outline view. I want to create a view with the same behavior, but it
>> seems I cannot do that using public API: the java editor directly
>> tells the outline view to change its selection, but the
>> ISelectionService knows nothing about it.
>> I guess I could listen to selection changes in the outline view, but
>> what if the user did not open it?
>> For now the only way I can think of doing it is accessing the
>> JavaEditor, which is an internal class, and use reflexion to call the
>> protected computeHighlightRangeSourceReference() method. Not exactly
>> clean...
>> Is there a better way to do it now? If not, is a better way planned?
>> Regards
>> Guillaume Pothier
>
>
>
> Take a look at JavaBrowsingPart.selectedChanged or more specifically
> org.eclipse.jdt.internal.ui.browsing.setSelectionFromEditor( IWorkbenchPart,
> ISelection). It's an internal class, but this is the code I looked at
> to figure out how to make a view update from the JavaEditor selections.
> You will also need to call
> getViewSite().getPage().addPostSelectionListener(ISelectionL istener).
> The WorkbenchPage actually handles notifying selectionListeners, not the
> JavaEditor.
>
> Karen
>

Thanks, it helped a lot! I wrote an enhancement request:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=107122
g
Previous Topic:[PDE/Build] Exporting a product with plugins needing bytecode-enhancement
Next Topic:superclass TypeDeclaration in DOM/AST
Goto Forum:
  


Current Time: Fri Apr 26 13:09:17 GMT 2024

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

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

Back to the top