Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » what is the Xtext 2.0 replacement for DefaultDocumentEditor?
what is the Xtext 2.0 replacement for DefaultDocumentEditor? [message #662554] Thu, 31 March 2011 05:51 Go to next message
Henrik Rentz-Reichert is currently offline Henrik Rentz-ReichertFriend
Messages: 261
Registered: July 2009
Senior Member
Hi,

I used a piece of code to make a change to the EMF model and readily reconcile it in the Xtext editor:

IXtextDocument document = ...
final String fragment = ...
DefaultDocumentEditor edit = new DefaultDocumentEditor();
Injector injector = ...
injector.injectMembers(edit);
edit.process(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
if (resource != null) {
EObject object = resource.getEObject(fragment);
// do something useful...
}
}
}, document);

What is the replacement for this in Xtext 2.0?

Thanks,
Henrik
Re: what is the Xtext 2.0 replacement for DefaultDocumentEditor? [message #662595 is a reply to message #662554] Thu, 31 March 2011 09:08 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

please use IXtextDocument.modify(IUnitOfWork). It encapsulates the
modification.
Just as a sidenote: It's almost never necessary to obtain an injector.
One would usually inject the required dependencies directly and create
the instances itself by Guice. When this rule is transitively applied,
nobody except the ExectuableExtensionFactory needs access to the
injector. E.g. in your code, you could use

@Inject
Provider<DefaultDocumentEditor> editorProvider;

editorProvider.get().process(unitOfWork, document);

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 31.03.11 07:51, schrieb Henrik Rentz-Reichert:
> Hi,
>
> I used a piece of code to make a change to the EMF model and readily reconcile it in the Xtext editor:
>
> IXtextDocument document = ...
> final String fragment = ...
> DefaultDocumentEditor edit = new DefaultDocumentEditor();
> Injector injector = ...
> injector.injectMembers(edit);
> edit.process(new IUnitOfWork.Void<XtextResource>() {
> @Override
> public void process(XtextResource resource) throws Exception {
> if (resource != null) {
> EObject object = resource.getEObject(fragment);
> // do something useful...
> }
> }
> }, document);
>
> What is the replacement for this in Xtext 2.0?
>
> Thanks,
> Henrik
Re: what is the Xtext 2.0 replacement for DefaultDocumentEditor? [message #662841 is a reply to message #662595] Fri, 01 April 2011 08:01 Go to previous message
Henrik Rentz-Reichert is currently offline Henrik Rentz-ReichertFriend
Messages: 261
Registered: July 2009
Senior Member
Hi Sebastian,

thanks. Now it works again.

And thanks also for the hint regrading the injection.
The code snippet is from my diagram plugin which is neither aware of Xtext nor of DI.
But I will consider to introduce an ExectuableExtensionFactory for the DiagramTypeProvider as Jan already proposed.

-Henrik

Am 31.03.2011 11:09, schrieb Sebastian Zarnekow:
> Hi Henrik,
>
> please use IXtextDocument.modify(IUnitOfWork). It encapsulates the modification.
> Just as a sidenote: It's almost never necessary to obtain an injector. One would usually inject the required dependencies directly
> and create the instances itself by Guice. When this rule is transitively applied, nobody except the ExectuableExtensionFactory
> needs access to the injector. E.g. in your code, you could use
>
> @Inject
> Provider<DefaultDocumentEditor> editorProvider;
>
> editorProvider.get().process(unitOfWork, document);
>
> Regards,
> Sebastian
Previous Topic:Xtext for composed metamodels
Next Topic:Passing complex boolean expressions to Xbase filter method
Goto Forum:
  


Current Time: Fri Apr 26 05:49:39 GMT 2024

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

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

Back to the top