|
|
|
|
Re: Modify text in XtextEditor [message #917512 is a reply to message #917490] |
Thu, 20 September 2012 02:39   |
Eclipse User |
|
|
|
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 02:59] by Moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06678 seconds