Modify text in XtextEditor [message #917378] |
Thu, 20 September 2012 03:24 |
ken liu Messages: 3 Registered: September 2012 |
Junior Member |
|
|
In my use case, I set two editor to share one resource, one is XtextEditor, the other is a editor with a table viewer.
Now, my problem is after I modify resource in table viewer, how can I update the text which displayed on XtextEditor? Is there any method which can generate the text according to the xtext grammar and resource automatically? 0r need I write this kind of method by myself.
the only way I know to modify text in an editor is to use editor.getDocumentProvider().getDocument(editor.getEditorInput()).set();
but I don't know how to get the text according to xtext grammer from resource
I'll appreciate if someone can provide helps
[Updated on: Thu, 20 September 2012 03:25] Report message to a moderator
|
|
|
|
|
Re: Modify text in XtextEditor [message #917490 is a reply to message #917482] |
Thu, 20 September 2012 06:11 |
|
Hi,
since i dont know your usecase it is hard to say.
xtextDocument.modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource res) throws Exception {
//do something with res
// e.g.
//Model m = (Model) resource.getContents().get(0);
//or
// res.getContents().set(0, MyDslFactory.eINSTANCE.createModel());
return null;
}
}
);
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Modify text in XtextEditor [message #917512 is a reply to message #917490] |
Thu, 20 September 2012 06:39 |
ken liu Messages: 3 Registered: September 2012 |
Junior Member |
|
|
Hi
I think you misunderstood my problem.
I don't want to do any operation on the model & resource. My problem is how to display these stuff on the xtextEditor.
In my use case, I put two editor into a multipage editor as two separate pages, but they share the same resource. And I override the pageChange(int newPageIndex), this will called when I click on the tab bar of multipage editor.
Here is some of these code
@Override
protected void pageChange(int newPageIndex) {
IEditorInput input = getEditorInput();
if (input instanceof FileEditorInput) {
FileEditorInput fInput = (FileEditorInput)input;
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = (injector.getInstance(XtextResourceSet.class));
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(URI.createURI(fInput.getURI().toString()), true);
//this method will get the content from resource and display on editor
resourceTableEditor.refreshContentsWithResource(resource);
//don't know how to deal with it, what i wanna do is to display the content of resource on the editor
XtextDocument document = (XtextDocument) editor.getDocument();
document.modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state)
throws Exception {
// TODO Auto-generated method stub
return null;
}
});
//the only way i found to change text on the editor(XtextEditor)
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("add stuff!!");
}
}
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("add stuff!!") Although this method can modify the text, I don't know how to generate the string text from resource which need correspond to the dsl grammar. Do I need to write the transform method by myself? Or there exist another method such as the modify() you said.
[Updated on: Thu, 20 September 2012 06:59] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03245 seconds