Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to modify Xtext resources programmatically
How to modify Xtext resources programmatically [message #795498] Fri, 10 February 2012 14:39
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I am implementing an action that performs changes in the Xtext files, it's similar to "Override/Implement
Methods", etc. I don't know if I'm on the right track.

For now, I can only get the active editor (the editor for the object I have opened), but I will need to modify other files I don't have opened. However, I can't even make changes to the editor I'm able to get. This is what I am doing:

       public void setActivePart(IAction action, IWorkbenchPart targetPart) {

		this.editor = targetPart.getSite().getPage().getActiveEditor();
	}


and,

IXtextDocument xDoc = XtextDocumentUtil.get(editor);
					
				
				
					xDoc.modify(
							new IUnitOfWork.Void<XtextResource>() {
								@Override
								public void process(XtextResource res) {
									try {
										System.out.println("Change name");
										Table table = (Table) r.getContents().get(0);
										table.setName("test");
									} catch (Exception e) {
										e.printStackTrace();
									} finally {
	
									}
								}
							} 
							);
					
					 Display.getDefault().syncExec( new Runnable() {  public void run() { 
						 
						 editor.doSave(null);
						 
					 } });


But it doesn't make any change to my resource.

Am I going the right way?

Thanks for your advice!





Previous Topic:Get token list for an EObject
Next Topic:Code formatting fails
Goto Forum:
  


Current Time: Tue Apr 16 09:34:34 GMT 2024

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

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

Back to the top