Home » Modeling » TMF (Xtext) » Acessing Editor contents
| | |
Re: Acessing Editor contents [message #668481 is a reply to message #668466] |
Thu, 05 May 2011 19:49 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
Hi,
not sure what it is you are trying to do... but:
- You can naturally always find the text of what is in any open editor.
Either as text, or the parsed model.
- If you want to parse a file, or a string you do that simply by opening
it as an EMF resource (as the text->parser->model transformation is
registered by file extension).
So... if you want the text of the editor - the Eclipse framework will
give you handles to the editor, from which you get its input, a document
etc. and from those you can either open the same file (looking at the
URI in the input), or get the actual XtextDocument, then get the
XtextResource.
Is the functionality invoked from a menu, button or is it triggered by
something else? Could you explain the use case a bit more? I find that
one almost never have to get the actual text in some complicated way...
(so hence my questions).
Regards
- henrik
On 5/5/11 9:02 PM, Oscar Rodriguez wrote:
> Henri,
>
> Thanks for your reply.
>
> I am pretty new with xtext. I reviewed xtext JUnit and honestly did not
> find anything useful.
>
> Let explain better what my problem is:
>
> My own language is already modeled in xtext. Syntax Coloring is fine as
> well. That part is more or less solved.
>
> What I need is to get access to my source code in the editor. To be
> clear, putting it into a known language: I need access to the actual C
> code inside the xtext editor (whatever editor object it is), not to the
> xtext's C language definition.
>
> I can see that there are URIs everywhere to load resoruces, not sure if
> they are used only for loading the language definition files or the
> actual source code files.. but anyway, I guess I cannot use URIs as all
> my data is in String buffers (not formated in anything but in my own
> programming language). What I need is two things:
>
> To load the editor content from a String when xtext editor gains focus,
> and to get the editor content when it losses focus.
>
> Is there a way to do it?
>
> Thanks,
>
> /Oscar
|
|
| |
Re: Acessing Editor contents [message #668725 is a reply to message #668481] |
Fri, 06 May 2011 20:42 |
Oscar Rodriguez Messages: 5 Registered: May 2011 |
Junior Member |
|
|
Hi Hernik,
Thanks again for replying.
Let me give a clearer picture of what I need to do:
My application requires that the actual file contents can be changed from several sources semi-concurrently: from the user editing directly in xtext's editor or from other threads running in the application. It forces to have an editor that does not really edit files, but edit buffers and those buffers are passed to another plug-in that keeps the consistency of the file contents. That plug-in is in charge of sending the buffers to xtext editor and receiving them and merging with the other data produced by other elements of the application.
So, what I need is:
1. An xtext constructor that, instead opening a file, requests a buffer from the plug-in and displays it in the editor.
2. Gain access to eclipse's get focus event, so that, xtext editor content can be reloaded from a buffer requested to the plug-in.
3. Gain access to the lost focus event so that the editor data is flushed into the plugin and gets merged with the other data.
Sumarizing, xtext will never really work with files, and need free access to the editor content. No URIs for loading either.
I found org.eclipse.xtext.example.ui.autoedit example, which seem to have access to the text implmenting IAutoEditStrategy, however, I am still lost.
Any idea?
Thanks,
/Oscar
Henrik Lindberg wrote on Thu, 05 May 2011 15:49Hi,
not sure what it is you are trying to do... but:
- You can naturally always find the text of what is in any open editor.
Either as text, or the parsed model.
- If you want to parse a file, or a string you do that simply by opening
it as an EMF resource (as the text->parser->model transformation is
registered by file extension).
So... if you want the text of the editor - the Eclipse framework will
give you handles to the editor, from which you get its input, a document
etc. and from those you can either open the same file (looking at the
URI in the input), or get the actual XtextDocument, then get the
XtextResource.
Is the functionality invoked from a menu, button or is it triggered by
something else? Could you explain the use case a bit more? I find that
one almost never have to get the actual text in some complicated way...
(so hence my questions).
Regards
- henrik
On 5/5/11 9:02 PM, Oscar Rodriguez wrote:
> Henri,
>
> Thanks for your reply.
>
> I am pretty new with xtext. I reviewed xtext JUnit and honestly did not
> find anything useful.
>
> Let explain better what my problem is:
>
> My own language is already modeled in xtext. Syntax Coloring is fine as
> well. That part is more or less solved.
>
> What I need is to get access to my source code in the editor. To be
> clear, putting it into a known language: I need access to the actual C
> code inside the xtext editor (whatever editor object it is), not to the
> xtext's C language definition.
>
> I can see that there are URIs everywhere to load resoruces, not sure if
> they are used only for loading the language definition files or the
> actual source code files.. but anyway, I guess I cannot use URIs as all
> my data is in String buffers (not formated in anything but in my own
> programming language). What I need is two things:
>
> To load the editor content from a String when xtext editor gains focus,
> and to get the editor content when it losses focus.
>
> Is there a way to do it?
>
> Thanks,
>
> /Oscar
[Updated on: Fri, 06 May 2011 20:45] Report message to a moderator
|
|
| |
Re: Acessing Editor contents [message #668754 is a reply to message #668481] |
Sat, 07 May 2011 02:40 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
Sounds very complex. Are you using EMF for this in any way?
Much of the Xtext functionality depends on the content being an eclipse
Resource (IFile etc.) since this is used for many of the features you
expect in a normal eclipse editor (markers being one of them).
I found this out when working with external files, and my solution was
to link such files to the workspace in a hidden project.
I am afraid I am not knowledgeable enough to give you advice on how to
best map your concurrently modified model to URI's, EMF Resource,
storages and Eclipse resources.
Regards
- henrik
On 5/6/11 10:24 PM, Oscar Rodriguez wrote:
> Henrik,
>
> Thanks a lot for taking the time trying to help me.
>
> Let me try to summarize what I need to do:
>
> I have files that can be modified in several ways and
> somehow semi-concurrently. It means that a file can be
> changed by a user directly in xtext editor and by other
> threads running underneath.
>
> Said that, xtext will NEVER open the files directly, but a
> file handler plug-in will, in order to keep the data
> consistency given this environment. That is why I need
> xtext editor to load its contents from a buffer instead of
> a file (in the constructor). The content will be flushed to
> the file handler plugins when xtext losses focus, and will
> reload its contents (from a buffer) when it gains focus
> again.
>
> So, I need 3 things:
>
> 1. A constructor to feed the contents of the editor from
> a buffer
> 2. To catch the lost focus event to flush the editor
> content to the file handler plug-in
> 3. To catch the gain focus event to reload the editor's
> contents from the file handler buffer.
>
> I found org.eclipse.xtext.example.ui.autoedit example,
> which seem to have access to the text implmenting
> IAutoEditStrategy, however, I am still lost.
>
> thanks!
>
> /Oscar
|
|
| |
Goto Forum:
Current Time: Sat Apr 27 04:45:01 GMT 2024
Powered by FUDForum. Page generated in 0.05436 seconds
|