Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to use Xtext(M2M with Xtend) and GMF to create diagramm? (Beginner)
How to use Xtext(M2M with Xtend) and GMF to create diagramm? (Beginner) [message #942410] Sat, 13 October 2012 13:20
J Sommer is currently offline J Sommer
Messages: 28
Registered: October 2012
Location: Germany
Junior Member
Hi,
I have started to work with Eclipse and I'm still a beginner. So I want to get some help from here.
I use Xtext to read my DSL. And then I want to show the instance with a diagram, which I have already defined with GMF. But the ecore(MFilesystem) in Xtext and the ecore(Filesystem) in GMF are different. So I use the Xtend to change the model and create an EObject(Filesystem). But i don't know, how the GMF use the resource from Xtent to create a diagram. I show my problem here:

1. I have defined the ecore in xtext(Grammmar)
grammar org.xtext.Filesystem with org.eclipse.xtext.common.Terminals

generate filesystem "http://www.xtext.org/Filesystem"

MFilesystem:
	(mfiles+=MFile | mfolder+=MFolder)* ;
	
MFile:
	'myfile' name=ID ';'
;
MFolder:
	'myfolder' name = ID ';'
;

http://farm9.staticflickr.com/8327/8082261415_65a69aa38c.jpg

2. I have defined the ecore in GMF
http://farm9.staticflickr.com/8048/8082263442_149b8e8b0f.jpghttp://farm9.staticflickr.com/8336/8082305888_824c467570.jpg

3. I try to run the runtime for Xtext
http://farm9.staticflickr.com/8475/8082313936_d06206d838.jpg

and create the diagramm from my DSL file (test.filesystem).
http://farm9.staticflickr.com/8323/8082338379_f35894ba57_z.jpg

4. Then I have this problem
http://farm9.staticflickr.com/8332/8082347529_3ca68fd520.jpg

5. So I try to use Xtend to change my model in Xtext
http://farm9.staticflickr.com/8476/8082347146_dc220f9ca9.jpg
package org.xtext.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import org.gmf.filesystem.filesystem.Filesystem
import org.gmf.filesystem.filesystem.FilesystemFactory
import org.gmf.filesystem.filesystem.impl.FilesystemFactoryImpl
import org.xtext.filesystem.MFile
import org.xtext.filesystem.MFolder

class FilesystemGenerator implements IGenerator  {
	Filesystem myfilesystem
	FilesystemFactory myfilesystemFactory
	
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		//TODO implement me
		
		val ast = resource.contents.get(0)
		
		myfilesystemFactory = new FilesystemFactoryImpl()
		myfilesystem = myfilesystemFactory.createFilesystem()
		
		val fi = myfilesystemFactory.createFile()
		var astFi = (ast.eContents.get(0)) as MFile
		fi.name = astFi.name
		myfilesystem.files.add(fi)

		val fo = myfilesystemFactory.createFolder()
		var astFo = (ast.eContents.get(1)) as MFolder
		fo.name = astFo.name
		myfilesystem.folders.add(fo)

	}
}


6. But it does not work. I think, I have done something wrong. So I want to know, how I can do so that the GMF uses
myfilesystem
to create a diagram.

Thanks.

[Updated on: Sat, 13 October 2012 19:31]

Report message to a moderator

Previous Topic:Changing shape on property change
Next Topic:Place a custom figure into a compartment
Goto Forum:
  


Current Time: Sun Oct 26 05:29:06 GMT 2014

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

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