Skip to main content



      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 01:51 Go to next message
Eclipse UserFriend
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 05:08 Go to previous messageGo to next message
Eclipse UserFriend
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 04:01 Go to previous message
Eclipse UserFriend
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: Thu Jul 10 04:05:00 EDT 2025

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

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

Back to the top