[xtext] propagate model changes to editor [message #28469] |
Mon, 09 February 2009 06:34  |
Eclipse User |
|
|
|
Originally posted by: knut.wannheden.gmail.com
Hi all,
I'd like to programmatically change the model instance (using the EMF
API) as loaded by the Xtext editor. Once my changes have been applied
I'd like to see the corresponding changes in the open editor. This
feature doesn't seem to be implemented yet (as also hinted by the TODO
comment in XtextDocument#modify).
Is this something that you plan to get into the Galileo release? And
will this be supported by an API like JDT's ASTRewrite (maybe EMF.Edit
based?) or will direct model modifications (using EMF API) be the basis?
As a workaround I now save the modified resource to a
ByteArrayOutputStream and then call XtextDocument#set with that inside
my UnitOfWork. That seems to work for now.
Cheers,
--knut
|
|
|
|
|
Re: [xtext] propagate model changes to editor [message #43770 is a reply to message #43712] |
Mon, 11 May 2009 10:57  |
Eclipse User |
|
|
|
Originally posted by: knut.wannheden.gmail.com
Hi Michael,
Yes, except for the parsing step that's what I did. The UnitOfWork is
given the model as it is parsed, so it can be directly modified. Then it
can be saved and set(). Unfortunately I don't have an example at hand
anymore but it should be something like this:
final XtextDocument doc = ...;
doc.modify(new UnitOfWork<Void>() {
Void exec(XtextResource resource) throws Exception {
MyModel model = resource.getContents().get(0);
// modification goes here
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
resource.save(out, null);
doc.set(out.toString());
}
};
Of course that's still just a workaround. I reported the following issue
for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=265097.
Cheers,
--knut
Michael Mühlberg wrote:
> Hello Knut,
>
> I'm confronted with the same problem.
>
> Does that mean you are getting the XtextDocument via get() then parsing it
> by hand, inserting your model element at the appropriate place and then
> calling set() -> Urrgh!
>
> Could you briefly explain your workaround a bit more in detail. A code
> example would be very nice.
>
> Ciao, Michael
>
>
> "Knut Wannheden" <knut.wannheden@gmail.com> wrote in message
> news:gmp4bm$jrs$1@build.eclipse.org...
>> Hi all,
>>
>> I'd like to programmatically change the model instance (using the EMF API)
>> as loaded by the Xtext editor. Once my changes have been applied I'd like
>> to see the corresponding changes in the open editor. This feature doesn't
>> seem to be implemented yet (as also hinted by the TODO comment in
>> XtextDocument#modify).
>>
>> Is this something that you plan to get into the Galileo release? And will
>> this be supported by an API like JDT's ASTRewrite (maybe EMF.Edit based?)
>> or will direct model modifications (using EMF API) be the basis?
>>
>> As a workaround I now save the modified resource to a
>> ByteArrayOutputStream and then call XtextDocument#set with that inside my
>> UnitOfWork. That seems to work for now.
>>
>> Cheers,
>>
>> --knut
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.05262 seconds