what is the Xtext 2.0 replacement for DefaultDocumentEditor? [message #662554] |
Thu, 31 March 2011 01:51  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.31371 seconds