Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Offsets not correct when using ProjectionViewer
Offsets not correct when using ProjectionViewer [message #467242] Tue, 01 May 2007 20:38 Go to next message
Eclipse UserFriend
Originally posted by: jweeks.neuraldk.org

Hello,

I've created an editor which extends TextEditor, and utilizes a
ProjectionViewer to create folds which the user can dynamically change.
This part works fine, however, I also have a feature which requires me to
get the current text at the cursor position, and this fails if the editor
has folds in it.

I retrieve the current position via:
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
IEditorPart part = page.getActiveEditor();
ITextEditor editor = (ITextEditor)part;
ISelectionProvider selprovider =
editor.getEditorSite().getSelectionProvider();
TextSelection selectedText =
(TextSelection)selprovider.getSelection();
int offset = selectedText.getOffset();

And I then get the text at that offset using a method I've added to my text
editor:
public String getLineAtOffset( int offset )
{
StyledTextContent stc =
this.getSourceViewer().getTextWidget().getContent();
return stc.getLine( stc.getLineAtOffset(offset) );
}

The problem here, from what I can tell, is that my method of getting an
offset retrieves an offset into the master document, however, my method of
getting the text based on a document appears to be using the projection
document.

Is there a way to convert to/from master/projection document offsets, or
some other way to ensure that only one coordinate system is used in this
transaction?

Thanks,
Jeff
Re: Offsets not correct when using ProjectionViewer [message #467270 is a reply to message #467242] Wed, 02 May 2007 05:38 Go to previous messageGo to next message
Eclipse UserFriend
Jeff Weeks [ neuraldk ] wrote:

>Hello,
>
>I've created an editor which extends TextEditor, and utilizes a
>ProjectionViewer to create folds which the user can dynamically change.
>This part works fine, however, I also have a feature which requires me to
>get the current text at the cursor position, and this fails if the editor
>has folds in it.
>
>I retrieve the current position via:
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> IEditorPart part = page.getActiveEditor();
> ITextEditor editor = (ITextEditor)part;
> ISelectionProvider selprovider =
> editor.getEditorSite().getSelectionProvider();
> TextSelection selectedText =
>(TextSelection)selprovider.getSelection();
> int offset = selectedText.getOffset();
>
>And I then get the text at that offset using a method I've added to my text
>editor:
> public String getLineAtOffset( int offset )
> {
> StyledTextContent stc =
>this.getSourceViewer().getTextWidget().getContent();
> return stc.getLine( stc.getLineAtOffset(offset) );
> }
>
>The problem here, from what I can tell, is that my method of getting an
>offset retrieves an offset into the master document, however, my method of
>getting the text based on a document appears to be using the projection
>document.
>
>Is there a way to convert to/from master/projection document offsets, or
>some other way to ensure that only one coordinate system is used in this
>transaction?
>
>
Did you try ProjectionMapping?

Dani

>Thanks,
>Jeff
>
>
Re: Offsets not correct when using ProjectionViewer [message #467318 is a reply to message #467270] Wed, 02 May 2007 22:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jweeks.neuraldk.org

Daniel Megert wrote:

> Jeff Weeks [ neuraldk ] wrote:
>
>>Hello,
>>
>>I've created an editor which extends TextEditor, and utilizes a
>>ProjectionViewer to create folds which the user can dynamically change.
>>This part works fine, however, I also have a feature which requires me to
>>get the current text at the cursor position, and this fails if the editor
>>has folds in it.
>>
>>I retrieve the current position via:
>> IWorkbenchPage page =
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
>> IEditorPart part = page.getActiveEditor();
>> ITextEditor editor = (ITextEditor)part;
>> ISelectionProvider selprovider =
>> editor.getEditorSite().getSelectionProvider();
>> TextSelection selectedText =
>>(TextSelection)selprovider.getSelection();
>> int offset = selectedText.getOffset();
>>
>>And I then get the text at that offset using a method I've added to my
>>text editor:
>> public String getLineAtOffset( int offset )
>> {
>> StyledTextContent stc =
>>this.getSourceViewer().getTextWidget().getContent();
>> return stc.getLine( stc.getLineAtOffset(offset) );
>> }
>>
>>The problem here, from what I can tell, is that my method of getting an
>>offset retrieves an offset into the master document, however, my method of
>>getting the text based on a document appears to be using the projection
>>document.
>>
>>Is there a way to convert to/from master/projection document offsets, or
>>some other way to ensure that only one coordinate system is used in this
>>transaction?
>>
>>
> Did you try ProjectionMapping?

This looks like exactly what I'd want to use, but I'm not sure how I'm
supposed to use it.

ProjectionMapping is listed as an internal class on help.eclipse.org, and
says not to use it. I can't get a handle on an instance of this class
anyway, though, as I don't know where to acquire a ProjectionDocument
instance to get it from in the first place.

--Jeff
Re: Offsets not correct when using ProjectionViewer [message #467570 is a reply to message #467318] Mon, 07 May 2007 10:53 Go to previous message
Eclipse UserFriend
Jeff Weeks [ neuraldk ] wrote:

>Daniel Megert wrote:
>
>
>
>>Jeff Weeks [ neuraldk ] wrote:
>>
>>
>>
>>>Hello,
>>>
>>>I've created an editor which extends TextEditor, and utilizes a
>>>ProjectionViewer to create folds which the user can dynamically change.
>>>This part works fine, however, I also have a feature which requires me to
>>>get the current text at the cursor position, and this fails if the editor
>>>has folds in it.
>>>
>>>I retrieve the current position via:
>>> IWorkbenchPage page =
>>> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
>>> IEditorPart part = page.getActiveEditor();
>>> ITextEditor editor = (ITextEditor)part;
>>> ISelectionProvider selprovider =
>>> editor.getEditorSite().getSelectionProvider();
>>> TextSelection selectedText =
>>>(TextSelection)selprovider.getSelection();
>>> int offset = selectedText.getOffset();
>>>
>>>And I then get the text at that offset using a method I've added to my
>>>text editor:
>>> public String getLineAtOffset( int offset )
>>> {
>>> StyledTextContent stc =
>>>this.getSourceViewer().getTextWidget().getContent();
>>> return stc.getLine( stc.getLineAtOffset(offset) );
>>> }
>>>
>>>The problem here, from what I can tell, is that my method of getting an
>>>offset retrieves an offset into the master document, however, my method of
>>>getting the text based on a document appears to be using the projection
>>>document.
>>>
>>>Is there a way to convert to/from master/projection document offsets, or
>>>some other way to ensure that only one coordinate system is used in this
>>>transaction?
>>>
>>>
>>>
>>>
>>Did you try ProjectionMapping?
>>
>>
>
>This looks like exactly what I'd want to use, but I'm not sure how I'm
>supposed to use it.
>
>ProjectionMapping is listed as an internal class on help.eclipse.org, and
>says not to use it.
>
Right. Use its interface: IDocumentInformationMapping. You can get this
via ProjectionDocument.getProjectionMapping() which is not internal. I
filed a bug report to change that API to return an
IDocumentInformationMapping (see bug 185773).

> I can't get a handle on an instance of this class
>anyway, though, as I don't know where to acquire a ProjectionDocument
>instance to get it from in the first place.
>
>
You can get this via viewer.getDocument(). An easier approach might be
to use the ProjectionViewer methods outlined in ITextViewerExtension5.

Dani

>--Jeff
>
>
>
Previous Topic:Remote debug RCP
Next Topic:GUI Builder for eclipse
Goto Forum:
  


Current Time: Wed May 21 02:05:35 EDT 2025

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

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

Back to the top