Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Save event XtextEditor
Save event XtextEditor [message #756575] Mon, 14 November 2011 11:56 Go to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
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 14:34 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
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);
}


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Save event XtextEditor [message #756666 is a reply to message #756631] Mon, 14 November 2011 15:48 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
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 17:57 Go to previous messageGo to next message
Thomas Ponweiser is currently offline Thomas PonweiserFriend
Messages: 9
Registered: January 2012
Junior Member
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 18:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
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: Sun Dec 21 13:04:16 GMT 2014

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

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