Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Save event XtextEditor
Save event XtextEditor [message #756575] Mon, 14 November 2011 06:56 Go to next message
Eclipse UserFriend
Hi,

I'm wondering where I could find/customize/overwrite the doSave() method of an xtext editor, which was created in the classical way in Eclipse (New->Xtext Project). What I want to do is write some information in a file upon saving the model of the xtext editor. Due to the automatically generated structure of the editor, there is no explicit class, which extends the EditorPart and implements the doSave(), isDirty() etc. methods - the class where I could eventually write some data/preferences to a file.

Any help is kindly apreciated.
Re: Save event XtextEditor [message #756631 is a reply to message #756575] Mon, 14 November 2011 09:34 Go to previous messageGo to next message
Eclipse UserFriend
You should create an implementation of IXtextEditorCallback and bind it like this in your <LanguageName>UIModule

public void configureMySpecialSaveHook(com.google.inject.Binder binder) {
binder.bind(IXtextEditorCallback.class).annotatedWith(Names.named("SpecialSaveHook")).to(
MySpecialSaveHook.class);
}
Re: Save event XtextEditor [message #756666 is a reply to message #756631] Mon, 14 November 2011 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Thank you for the hint, Sven. Here's what I did (and it works like I want it to):

I created my own XtextEditorCallback like this:

public class MyDSLXtextEditorCallback extends AbstractDirtyStateAwareEditorCallback {

	@Override
	public void afterSave(XtextEditor editor) {
		System.out.println("Saved!");
	}
}


and then I bound it in the <LanguageName>UIModule like this:

public void configureMyDSLXtextEditorCallback(com.google.inject.Binder binder) {
	binder.bind(IXtextEditorCallback.class).annotatedWith(Names.named("MyDSLXtextEditorCallback")).to(MyDSLXtextEditorCallback.class);
}


Thank you very much for your help!
Re: Save event XtextEditor [message #899667 is a reply to message #756575] Wed, 01 August 2012 13:57 Go to previous messageGo to next message
Eclipse UserFriend
This should be easy:

In the afterSave() method I would need the org.eclipse.emf.common.util.URI of the resource previously saved. How can I get it?

Thanks for your help in advance!
Re: Save event XtextEditor [message #899674 is a reply to message #899667] Wed, 01 August 2012 14:36 Go to previous message
Eclipse UserFriend
Hi,

i am not quite sure what you want to do
never the less:
- call XtextEditor.getResource get an IResource and use std mechanims to calc the emf uri
- use XtextEditor.getDocument.readOnly/XtextEditor.getDocument.readOnly/modify

~Christian
Previous Topic:Variable declaration
Next Topic:how to generate the ecore model from your grammar
Goto Forum:
  


Current Time: Wed Jul 23 06:16:05 EDT 2025

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

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

Back to the top