Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Save Action
Xtext Save Action [message #1059783] Tue, 21 May 2013 15:06 Go to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi all,

I write a code in the Xtext save method.I have problem:
1:Auto Complision is not active in the editor.
2.I can not Ctrl+Z
3-My cursor is in the beginning of the editor every time.
4-I can not trim mymodel.getDisplayName().if I trim it ,changes not do.

@Override
	public void afterSave(XtextEditor editor) {
		// TODO Auto-generated method stub
		

		IXtextDocument myDocument = editor.getDocument();
		myDocument.modify(new IUnitOfWork<Void, XtextResource>() {
			@Override
			public java.lang.Void exec(XtextResource res) throws Exception {
				ContentModel mymodel =(ContentModel) res.getContents().get(0);
				mymodel.setName(mymodel.getDisplayName().toString().intern());
				System.out.println(mymodel.getDisplayName().toString());
				
				return null;
			}
		});	



Best Regrads,

[Updated on: Tue, 21 May 2013 15:06]

Report message to a moderator

Re: Xtext Save Action [message #1059797 is a reply to message #1059783] Tue, 21 May 2013 16:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi,

i dont understand 1 2 and 3
4 works fine for me

package org.xtext.example.mydsl.ui;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.xtext.builder.nature.NatureAddingEditorCallback;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Model;

public class MyDslEditorCallback extends NatureAddingEditorCallback {
	

	@Override
	public void afterSave(XtextEditor editor) {
		System.out.println("here we go");
		editor.getDocument().modify(new IUnitOfWork<Void, XtextResource>() {

			@Override
			public java.lang.Void exec(XtextResource state) throws Exception {
				for (Greeting g : ((Model)state.getContents().get(0)).getGreetings()) {
					g.setName(g.getName().toUpperCase());
				}
				return null;
			}
			
		});
		if (isDirty()) {
			editor.doSave(new NullProgressMonitor());
		}
		super.afterSave(editor);
		
	}


}
Re: Xtext Save Action [message #1059799 is a reply to message #1059797] Tue, 21 May 2013 16:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
The crtl z problem look like a bug to me.
Re: Xtext Save Action [message #1059886 is a reply to message #1059799] Wed, 22 May 2013 06:22 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian ,

After I have written this code,Auto Completion is not active.When I enter ctrl+space,does not come any auto completion (not open diaglog page):my first problem is this.

Second problem is :I load screenshot.I wrote "displayName = "ddddddddddeee "": There is a blank end of the displayname.and then, When I save the editor :

ContentModel ddddddddddeee { :here ,"{" curly bracket shifting one space.
if I write "displayName = " ddddddddddeee"" :a blank begin ,Name "ddddddddddeee" shifting.

İf I wite "ddddddddddeee" :there isnt any blank , Nothing happens :not change name with displayname.


PS:I can not trim displayname: such as :
String dumyString = mymodel.getDisplayName().toString().trim();
dumyString = dumyString.replace(" ", "");

if I use: mymodel.setName(dumyString);
not change the name with displayname.




Do you know another class for I can reach the XtextResorces?I can try this prosses in it?How I can reach XtextResources instead of IXtextEditorCallback?











Re: Xtext Save Action [message #1059892 is a reply to message #1059886] Wed, 22 May 2013 06:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi I don't know any for "automatically to be called" maybe Sebastian
Zarnekow knows

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1059896 is a reply to message #1059886] Wed, 22 May 2013 06:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Maybe http://www.eclipse.org/forums/index.php/m/786926/ helps

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1059956 is a reply to message #1059896] Wed, 22 May 2013 11:00 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I bind NatureAddingEditorCallback in the UI.but not works,I do not bind it ?

@Override
public Class<? extends org.eclipse.xtext.ui.editor.IXtextEditorCallback> bindIXtextEditorCallback() {
return org.eclipse.xtext.builder.nature.NatureAddingEditorCallback.class;
}

public Class<? extends EditorCallback> bindModulefileBuilder() {
return EditorCallback.class;
}


Best regards,

[Updated on: Wed, 22 May 2013 11:07]

Report message to a moderator

Re: Xtext Save Action [message #1059957 is a reply to message #1059956] Wed, 22 May 2013 11:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Looks good

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1059958 is a reply to message #1059957] Wed, 22 May 2013 11:08 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
not works Sad

@Override
public Class<? extends org.eclipse.xtext.ui.editor.IXtextEditorCallback> bindIXtextEditorCallback() {
return org.eclipse.xtext.builder.nature.NatureAddingEditorCallback.class;
}

public Class<? extends EditorCallback> bindModulefileBuilder() {
return EditorCallback.class;
}



Christian Dietrich wrote on Wed, 22 May 2013 07:03
Looks good

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de

Re: Xtext Save Action [message #1059964 is a reply to message #1059958] Wed, 22 May 2013 11:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Sorry I don't get what you are doing. Simply override the method that
is already there

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1059966 is a reply to message #1059964] Wed, 22 May 2013 11:44 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member

not works :
@Override
	public Class<? extends org.eclipse.xtext.ui.editor.IXtextEditorCallback> bindIXtextEditorCallback() {
		return org.eclipse.xtext.builder.nature.NatureAddingEditorCallback.class;
	}
	
	public Class<? extends EditorCallback> bindModulefileBuilder() {
	     return EditorCallback.class;



works it :I bind it now

public void configureMySpecialCallback(com.google.inject.Binder
binder) {
binder.bind(IXtextEditorCallback.class).annotatedWith(Names. named( "EditorCallback")).to(
EditorCallback.class);
}
Re: Xtext Save Action [message #1059970 is a reply to message #1059966] Wed, 22 May 2013 11:54 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi ,

I write this code for change name with displayname after save.my code :
public class EditorCallback extends NatureAddingEditorCallback {
	@Override
	public void afterSave(XtextEditor editor) {
		System.out.println("here we go");
		editor.getDocument().modify(new IUnitOfWork<Void, XtextResource>() {
          
			@Override
			public java.lang.Void exec(XtextResource state) throws Exception {
				ContentModel mymodel = ((ContentModel) state.getContents().get(0));
				System.out.println(mymodel);
				mymodel.setName(mymodel.getDisplayName().toString());
				
				return null;
				
			}
			
		});
		if (isDirty()) {
			editor.doSave(new NullProgressMonitor());
		}
		super.afterSave(editor);
		
	}


and then bind it :

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


BUTTT :I take an error ->
Save Failed
java.lang.StackOverflowError

Wehere do I error ?please heelp me I do not understand .is it a bug?


Re: Xtext Save Action [message #1059972 is a reply to message #1059970] Wed, 22 May 2013 12:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Sorry don't know better you go the other hook

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1059986 is a reply to message #1059972] Wed, 22 May 2013 12:56 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi,

Thank you for help

Best regards,
Re: Xtext Save Action [message #1060278 is a reply to message #1059797] Thu, 23 May 2013 19:51 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian ,
I try this code : but my problem is not reach other elements of model Sad.I reach onlly ContentModel'name and displayname.How can I reach other elements of Model?
@Override
			public java.lang.Void exec(XtextResource state) throws Exception {
		    // WebApplication mymodel1 = ((WebApplication) state.getContents().get(0));
				
			//	System.out.println(mymodel1);
				
				//mymodel.setName(mymodel.getDisplayName().toString());
				
				ContentModel mymodel =(ContentModel) state.getContents().get(0);
                 
				if(mymodel.getDisplayName().equals(null) || mymodel.getDisplayName().equals("")){
			    	mymodel.setDisplayName(mymodel.getName());
			  
				}
				
				return null;
				
			}
			
		});
		if (isDirty()) {
			editor.doSave(new NullProgressMonitor());
		}
		super.afterSave(editor);
		
	}


My grammar :

ContentModel returns ContentModel:
'ContentModel'
name=QualifiedName
'{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('description' '=' description=STRING)?
ownedWebApplication=WebApplication
'}';

ContentUnit returns ContentUnit:
ContentModel | WebApplication | SiteCollection | Web | CustomList | ContentType | Field | View;

WebApplication returns WebApplication:
'WebApplication'
name=QualifiedName
'{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('description' '=' description=STRING)?
ownedSiteColection+=SiteCollection (ownedSiteColection+=SiteCollection)*
'}';

SiteCollection returns SiteCollection:
'SiteCollection'
name=QualifiedName
'{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('description' '=' description=STRING)?
ownedWeb=Web
'}';


-----------------------------------------------------------------------------------
Christian Dietrich wrote on Tue, 21 May 2013 12:02
Hi,

i dont understand 1 2 and 3
4 works fine for me

package org.xtext.example.mydsl.ui;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.xtext.builder.nature.NatureAddingEditorCallback;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Model;

public class MyDslEditorCallback extends NatureAddingEditorCallback {
	

	@Override
	public void afterSave(XtextEditor editor) {
		System.out.println("here we go");
		editor.getDocument().modify(new IUnitOfWork<Void, XtextResource>() {

			@Override
			public java.lang.Void exec(XtextResource state) throws Exception {
				for (Greeting g : ((Model)state.getContents().get(0)).getGreetings()) {
					g.setName(g.getName().toUpperCase());
				}
				return null;
			}
			
		});
		if (isDirty()) {
			editor.doSave(new NullProgressMonitor());
		}
		super.afterSave(editor);
		
	}


}
Re: Xtext Save Action [message #1060281 is a reply to message #1060278] Thu, 23 May 2013 20:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Simply traverse the model ?!?
btw you should try the other proposed solution anyway (XtextDocumentProvider)
Re: Xtext Save Action [message #1060287 is a reply to message #1060281] Thu, 23 May 2013 21:29 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
yes I do not traverse the model.this problem is very big for me Sad
Re: Xtext Save Action [message #1060298 is a reply to message #1060287] Fri, 24 May 2013 03:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
ahm you are the guy the knows your metamodel best. Stuff like
ecoreutil2.getallcontentsoftype or eswitch may help

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060304 is a reply to message #1060298] Fri, 24 May 2013 06:01 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I wan to traverse model in the public java.lang.Void exec(XtextResource state).
I can not reach model element in this class.How can I use ecoreutil2.getallcontentsoftype .

[Updated on: Fri, 24 May 2013 06:01]

Report message to a moderator

Re: Xtext Save Action [message #1060308 is a reply to message #1060304] Fri, 24 May 2013 06:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Ahm still don't get it
http://www.eclipse.org/forums/index.php/t/487834/

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060323 is a reply to message #1060308] Fri, 24 May 2013 07:13 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian ,

My root is ContentModel.I write this code ContentModel mymodel =(ContentModel) state.getContents().get(0); This code gets onlly contentmodel.my aim is :mymodel.setDisplayName(mymodel.getName()); but this operation is done for every elements.now I can do this for contentmodel element onnly Sad

ContentModel returns ContentModel:
	'ContentModel'
	name=QualifiedName
	'{'
	'guID' '=' guID=STRING
	'displayName' '=' displayName=STRING
	('description' '=' description=STRING)?
	ownedWebApplication=WebApplication
	'}';
	
ContentUnit returns ContentUnit:
	ContentModel | WebApplication | SiteCollection | Web | CustomList | ContentType | Field | View;

WebApplication returns WebApplication:
	'WebApplication'
	name=QualifiedName
	'{'
	'guID' '=' guID=STRING
	'displayName' '=' displayName=STRING
	('description' '=' description=STRING)?
	ownedSiteColection+=SiteCollection (ownedSiteColection+=SiteCollection)*
	'}';

SiteCollection returns SiteCollection:
	'SiteCollection'
	name=QualifiedName
	'{'
	'guID' '=' guID=STRING
	'displayName' '=' displayName=STRING
	('description' '=' description=STRING)?
	ownedWeb=Web
	'}';
Re: Xtext Save Action [message #1060324 is a reply to message #1060323] Fri, 24 May 2013 07:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi I still do not get it why you traverse the model from the starting
point and look for all places that are from interest for you. This is
not at all Xtext specific. If you have A and B and A has a b B you'd
call a.getB()

?!?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060326 is a reply to message #1060323] Fri, 24 May 2013 07:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26125
Registered: July 2009
Senior Member
Christian as already suggested
org.eclipse.xtext.EcoreUtil2.getAllContentsOfType(EObject, Class<T>) for
walking the tree.

On 24/05/2013 9:13 AM, junior developer wrote:
> Hi Christian ,
>
> My root is ContentModel.I write this code ContentModel mymodel
> =(ContentModel) state.getContents().get(0); This code gets onlly
> contentmodel.my aim is :mymodel.setDisplayName(mymodel.getName()); but
> this operation is done for every elements.now I can do this for
> contentmodel element onnly :(
>
>
> ContentModel returns ContentModel:
> 'ContentModel'
> name=QualifiedName
> '{'
> 'guID' '=' guID=STRING
> 'displayName' '=' displayName=STRING
> ('description' '=' description=STRING)?
> ownedWebApplication=WebApplication
> '}';
>
> ContentUnit returns ContentUnit:
> ContentModel | WebApplication | SiteCollection | Web | CustomList
> | ContentType | Field | View;
>
> WebApplication returns WebApplication:
> 'WebApplication'
> name=QualifiedName
> '{'
> 'guID' '=' guID=STRING
> 'displayName' '=' displayName=STRING
> ('description' '=' description=STRING)?
> ownedSiteColection+=SiteCollection
> (ownedSiteColection+=SiteCollection)*
> '}';
>
> SiteCollection returns SiteCollection:
> 'SiteCollection'
> name=QualifiedName
> '{'
> 'guID' '=' guID=STRING
> 'displayName' '=' displayName=STRING
> ('description' '=' description=STRING)?
> ownedWeb=Web
> '}';
>
Re: Xtext Save Action [message #1060327 is a reply to message #1060324] Fri, 24 May 2013 07:30 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian ,

I understand you ,but I define ContentUnit in the grammar ,ContentUnit returns ContentUnit:
ContentModel | WebApplication | SiteCollection | Web | CustomList | ContentType | Field | View;

I write my code :

if(mymodel.getDisplayName().equals(null) || mymodel.getDisplayName().equals("")){
mymodel.setDisplayName(mymodel.getName());
mymodel.getOwnedWebApplication().setDisplayName(mymodel.getOwnedWebApplication().getName());

}

Must I do for every element ?

[Updated on: Fri, 24 May 2013 07:30]

Report message to a moderator

Re: Xtext Save Action [message #1060329 is a reply to message #1060327] Fri, 24 May 2013 07:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi,

you are the guy that manages your grammar and metamodel ?!?
Re: Xtext Save Action [message #1060332 is a reply to message #1060329] Fri, 24 May 2013 07:57 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi,

I try manage my metamodel .
I want to reach all elements from the ContentUnit.I try it.otherwise,I must traverse all elements with hierarchically.
Re: Xtext Save Action [message #1060333 is a reply to message #1060332] Fri, 24 May 2013 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
I gave you hints on 2 utilities before

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060703 is a reply to message #1060333] Tue, 28 May 2013 06:52 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I want to create field automatically,
When I create an element,ist default fields are created automatically.Which class is used for this.How can I do ?

Best Regrads,
Re: Xtext Save Action [message #1060705 is a reply to message #1060703] Tue, 28 May 2013 06:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Sorry i cant follow you.
Re: Xtext Save Action [message #1060710 is a reply to message #1060705] Tue, 28 May 2013 07:54 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I understand you,I search it but I do not find a solution:( I have no idea which class is used . How can I solved this problem.
Re: Xtext Save Action [message #1060715 is a reply to message #1060710] Tue, 28 May 2013 08:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
I don't know your problem. I don't understand it.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060718 is a reply to message #1060715] Tue, 28 May 2013 08:44 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
I want to do Create an element,its default fields are created automatically such as my grammar :
ContentType returns ContentType:
'ContentType'
name=QualifiedName
'{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('description' '=' description=STRING)?
('group' '=' group=STRING)?
('parent' '=' parentContentType=[ContentType|QualifiedName])?
(ownedField+=Field (ownedField+=Field)*)?
'}';

Field returns Field:
LookUp | BooleanField | TextField | NumberField;

TextField returns TextField:
'Text' name=QualifiedName '{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('required' '=' required=EBoolean)?
('unlimitedLenghtInDocumentLibraries' '=' unlimitedLenghtInDocumentLibraries=EBoolean)?
('description' '=' description=STRING)?
('group' '=' group=STRING)?
('default' '=' default=STRING)?
('displaySize' '=' displaySize=INT)?
('maxLength' '=' maxLength=INT)?
'}';


My grammar is below.When I create a contenttype ,ContentType's Fields are created automatically:ownedField+=Field (ownedField+=Field)*)?
When I create ContentType below Text Field is created automatically in the Xtext Editor.User may change its property onlly.I hope ,I can explain my problem.

Text text {
guID = "guID"
displayName="bollty u" required = true unlimitedLenghtInDocumentLibraries= false default = "Default"


}

[Updated on: Tue, 28 May 2013 08:45]

Report message to a moderator

Re: Xtext Save Action [message #1060720 is a reply to message #1060718] Tue, 28 May 2013 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
My question still is: do you need that derived element explicitly in
the file

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060721 is a reply to message #1060720] Tue, 28 May 2013 08:56 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
hi,

I I can understand derived element explicitly in the file correctly.no I do not derived elements.I will give own value in the Field's properties.I do not call other elemets .
Re: Xtext Save Action [message #1060724 is a reply to message #1060721] Tue, 28 May 2013 09:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Sorry if it happens automatically it is derived

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060725 is a reply to message #1060721] Tue, 28 May 2013 09:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
BTW why don't you try the hook I proposed (xtextdoxumentprovider it
was I think - the editor callback might be the wrong place

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060736 is a reply to message #1060710] Tue, 28 May 2013 09:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Still the question: did you try to move your code to
XtextDocumentProvider.doSaveDocument

(document may be an XtextDocument)
Re: Xtext Save Action [message #1060752 is a reply to message #1060736] Tue, 28 May 2013 11:09 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I understand ,it is drived.I do not try XtextDocumentProvider.doSaveDocument.
I wrote code in the
public class EditorCallback extends NatureAddingEditorCallback {
public class EditorCallback extends NatureAddingEditorCallback {
@Override

I solved internal name and Displayname.When I save editor,qualifiedname is wrote in the displayname field and if qualifiedname has emtpt ,remove blanked and then rewrite fullname, and first blanked name is written in the displayname field.I solved my problem .All changes manupulation on the editor .I written my code in the
public void afterSave(XtextEditor editor) .

Now ,I want to drived process (create default field in the right place on the editor when one element is created).I may use XtextDocumentProvider.doSaveDocument.Hence when Xtextdocument is saved ,I will create default elements.Do you have offered an example?
Re: Xtext Save Action [message #1060755 is a reply to message #1060752] Tue, 28 May 2013 11:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
No. Simple downcast and call your code on the xtextdocument

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Save Action [message #1060763 is a reply to message #1060755] Tue, 28 May 2013 11:46 Go to previous messageGo to previous message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Thank you for help .I try it.My problem may be solved
I written code in the public class MyXtextDocumentProvider extends XtextDocumentProvider{
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {






super.doSaveDocument(monitor, element, document, overwrite);
}


protected boolean createNewEntity(Entity sibling, String name) {
		Entity newEntity = DomainmodelFactory.eINSTANCE.createEntity();
		newEntity.setName(name);
		return addTypeAsSibling(sibling, newEntity);
	}

	protected boolean createNewDatatype(Entity sibling, String name) {
		DataType newDatatype = DomainmodelFactory.eINSTANCE.createDataType();
		newDatatype.setName(name);
		return addTypeAsSibling(sibling, newDatatype);
	}

	protected boolean addTypeAsSibling(Entity sibling, Type newType) {
		EObject container = sibling.eContainer();
		EList<AbstractElement> elements = null;
		if (container instanceof PackageDeclaration) {
			elements = ((PackageDeclaration) container).getElements();
		} else if (container instanceof DomainModel) {
			elements = ((DomainModel) container).getElements();
		} else {
			return false;
		}
		int index = elements.indexOf(sibling) + 1;
		elements.add(index, newType);
		return true;
	}
}

Previous Topic:Create Automatically elements when one element is created
Next Topic:SelectionListener registration
Goto Forum:
  


Current Time: Mon Oct 20 13:08:32 GMT 2014

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

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