Can I be notified of Java editor's currently selected element, like the content outline is? [message #212483] |
Sun, 14 August 2005 06:23 |
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 17:06 |
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 #212730 is a reply to message #212676] |
Wed, 17 August 2005 14:31 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.03682 seconds