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 02:23 Go to next message
Guillaume Pothier is currently offline Guillaume Pothier
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 13:06 Go to previous messageGo to next message
Karen Butzke is currently offline Karen Butzke
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 02:50 Go to previous messageGo to next message
Eclipse User
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 10:31 Go to previous message
Guillaume Pothier is currently offline Guillaume Pothier
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 18 19:34:43 EDT 2014

Powered by FUDForum. Page generated in 0.01499 seconds