Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Import a xtext file into EMF
Import a xtext file into EMF [message #1108101] Fri, 13 September 2013 10:43 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

I've the following use case and would like to have some opinions which would be the best way to realise this:

In our Project we use a combined EMF/GMF Editor, where one part of this editor is to model hardware platforms (realised in EMF).
Furthermore there is another editor (realised in xtext) which is also used to describe hardware platforms. As typical for Xtext, this instances are stored then as plain text, with a tree structure.

What we want now to achieve is to import this xtext files (plain text) into a model of our EMF/GMF editor (xmi files). So there must be some kind of transformation.

Are there any tools/frameworks supporting this, as Xtext relies on EMF? Or what do you reckon would be a clean way to realise this?

Cheers,
Phil

[Updated on: Fri, 13 September 2013 11:25]

Report message to a moderator

Re: Import a xtext file into EMF [message #1108120 is a reply to message #1108101] Fri, 13 September 2013 11:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Phil,

Can't you just load (ResourceSet.getResource()) one of these Xtext-based
resources into the resource set of your EMF/GMF editor?

On 13/09/2013 12:43 PM, Phil H wrote:
> Hi,
>
> I've the following use case and would like to have some opinions which
> would be the best way to realise this:
>
> In our Project we use a combined EMF/GMF Editor, where one part of
> this editor is to model hardware platforms (realised in EMF).
> Furthermore there is another editor (realised in xtext) which is also
> used to describe hardware platforms. As typical for Xtext, this
> instances are stored then as plain text, with a tree structure.
>
> What we want now to achieve is to import this xtext files (plain text)
> into our EMF/GMF editor (xmi files). So there must be some kind of
> transformation.
> Are there any tools/frameworks supporting this, as Xtext relies on
> EMF? Or what do you reckon would be a clean way to realise this?
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Import a xtext file into EMF [message #1108137 is a reply to message #1108120] Fri, 13 September 2013 11:45 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

you mean like in this way? What is MyDslStandaloneSetup()? Is it inside the xtext project?:

Quote:

Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
URI uri = URI.createFileURI(path);
Resource resource = resourceSet.getResource(uri, true);


But then I've to provide my transformation logic? I prefer a generally way provided by a tool or framework, because the metamodel of the xtext editor can maybe change and so it would be easier to implement this changes.
Re: Import a xtext file into EMF [message #1108144 is a reply to message #1108137] Fri, 13 September 2013 11:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi yes it is part of the framework but is meant for standalone use
only. But maybe your understanding problem is way before. .mydsl and
..xmi is the same. Is only different persistence.

Eds code shows how to initialize the framework. The rest of the
resource handling is 1:1 the same as with std. Emf.

Regarding gmf. You may search other topics to find hints on the
integration since there are specialties on gmf and Xtext so that the
interoperation is tricky

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1108161 is a reply to message #1108144] Fri, 13 September 2013 12:26 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Christian,

GMF is not important for this because the hardware platforms are only shown in the emf tab.

So to summarize, you would recommended this way?:

- I need a workspace with EMF / GMF Editor and the xtext project (also the .ui plugin)?

- I use ResourceSet.getResource() to read in my xtext file (plain text).

- Next I've to transform the structure from the xtext metamodel to the one from the emf metamodel (both ecore), by my own logic. This would result in a new Resource (XtextResourceSet -> XMIResource) ?

- As a last step, I've to somehow integrate the resulting resource in my existing EMF file.

Re: Import a xtext file into EMF [message #1108192 is a reply to message #1108161] Fri, 13 September 2013 13:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

Still the Question: how is that Code called? Standalone. Action in the Editor. Automatic through Xtext builder ...


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1108200 is a reply to message #1108192] Fri, 13 September 2013 13:45 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Christian,

In the EMF Editor, I attached an "Import" command to the context menu, which calls then a handler. The handler opens a FileDialog, where the user can select the corresponding xtext model. That's the startng point for the model import so far.
Re: Import a xtext file into EMF [message #1108223 is a reply to message #1108200] Fri, 13 September 2013 14:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

then have a look at http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/
(dont call the generator, call your stuff)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1110222 is a reply to message #1108223] Mon, 16 September 2013 15:04 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Christian,

so in particular, this 3 lines seems to be relevant then for my case?:

URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = resourceSetProvider.get(project);
Resource r = rs.getResource(uri, true);


since I'm calling the handler in EMF, I don't get an IFile or IProject, so I've no idea how to use this lines of code..
Re: Import a xtext file into EMF [message #1110225 is a reply to message #1110222] Mon, 16 September 2013 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

what is the starting point of your handler
"I'm calling the handler in EMF"
says nothing to me.

i you choose "import" you select a file don't yoou?
isnt that std. code of emf anyway?
then it should work out of the box.

so please give some more context.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1110258 is a reply to message #1110225] Mon, 16 September 2013 16:15 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Christian,

I attached the command to the context menu of my EMF editor, which calls then my handler:

Shell shell = Display.getCurrent().getActiveShell();
FileDialog fileDialog = new FileDialog(shell);
fileDialog.setText("Import an existing Hardware Model");
fileDialog.setFilterExtensions(new String[] { "*.hwmodel" });
fileDialog.setFilterNames(new String[] { "*.hwmodel" });
try {
	String path = fileDialog.open();
...


I just have the path to a xtext file. Furthermore, there are no xtext projects at all. The user just have a project containing files of the EMF/GMF editor. The xtext files are provided by another editor and stored on the hard drive or somewhere else.
This files look like this:

Package {
	elements {
		System "ExampleFlash" {
			ECUs (
				"MC5_Demo"
			)
		},


In my workspace, I've got the plugin of the xtext editor, but I don't know how the link you gave me will help me for my use-case.

Hope this informations gives you a clearer view.
Re: Import a xtext file into EMF [message #1110270 is a reply to message #1110258] Mon, 16 September 2013 16:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi what does happen if you inject a Provider<ResourceSet> instead

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1110280 is a reply to message #1110270] Mon, 16 September 2013 16:54 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Accordingly to your blog post, I attached

@Inject
IResourceSetProvider resourceSetProvider;


to my handler, but resourceSetProvider seems to be null. Am I'm missing something (please see attached image)?

Furthermore I'm not sure what stuff of the plugins I need at all in my workspace. is the .ui project necessary? Did I need the grammar file? I want to have as less files as necessary for my use-case.
Re: Import a xtext file into EMF [message #1110285 is a reply to message #1110280] Mon, 16 September 2013 17:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi you need an executable extension factory and use it in the
plugin.XML to get guice running

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1110438 is a reply to message #1110285] Mon, 16 September 2013 22:29 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

I tried to understand this concept and read some blogs and documentation, but it's still not clear for me what I've to do.

In my .ui project, I've the following extension point given:

extension point="org.eclipse.ui.editors">
   <editor class="org.xtext.hw.ui.HwDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            default="true"
            extensions="hwmodel"
            id="org.xtext.hw.HwDsl"
            name="HwDsl Editor">
   </editor>
</extension>


I reckon copying this extension point to my .editor plugin (this plugin contains my handler) is wrong, because when I do this, the Injection is still null. So what else have I to put inside my EMF editor plugin.xml?
Re: Import a xtext file into EMF [message #1110640 is a reply to message #1110438] Tue, 17 September 2013 06:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

you hav to use a executable extensionfactory for YOUR handler Class.

for further reading
http://www.eclipse.org/Xtext/documentation.html#equinoxSetup
http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html
http://kthoms.wordpress.com/2011/09/28/moving-an-xtend-generator-into-its-own-plugin/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1110892 is a reply to message #1110640] Tue, 17 September 2013 13:17 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I already read this, but it doesn't helped me really...The problem is that I haven't created the xtext plugin and just want to find a way to import the instances..

What do you mean by using an executable extensionfactory for my handler Class? Have I to create my own executable extensionfactory class in the .editor plugin? I though Xtext provide me with one..Or have I to extend my handler class with an executable extensionfactory??

The documentation says: "The only thing you have to do in order to use this factory is to prefix the class with the factory MyDslExecutableExtensionFactory name followed by a colon."

A few more details would be nice..
Re: Import a xtext file into EMF [message #1110944 is a reply to message #1110892] Tue, 17 September 2013 14:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

first: just a stupid question:

resourceset rs = new Resourcesetimpl();
rs.getResource(URI.createURI(...)); dosent work?

second:

a executableextensionfactory i a class that helps you to create classes (via plugin xml)
aware of guice.

therefor you ne a (subclass) of abstractguiceawareecectuableextensionfactory
that exposes an injector to create the class instances with help of guice.

=> you write class="x.y.z.EEF::x.z.y.YourHandler" in the plugin.xml

regarding the topic: create own or use the one from xtext
id create a own but it might with the one from the ui project as well.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1113211 is a reply to message #1110944] Fri, 20 September 2013 20:21 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Quote:
Hi,

first: just a stupid question:

resourceset rs = new Resourcesetimpl();
rs.getResource(URI.createURI(...)); dosent work?


You're right, I tried the following and it works so far:

String path = fileDialog.open();
ResourceSet rs = new ResourceSetImpl();
rs.getResource(URI.createFileURI(path), true);
TreeIterator<Notifier> it = rs.getAllContents();
while (it.hasNext()) {
Notifier notifier = it.next();
if (notifier instanceof XYZ) {
XYZ xyz = (XYZ) notifier;
 ....


Now I'm able to get the objects out of the file, but I'm still not sure why this works. Do you think that I've choosen a good way?

And is it still necessary to have my xtext plugins in the workspace or is it sufficient enought to have generated emf stuff (impl for example)?
Re: Import a xtext file into EMF [message #1113212 is a reply to message #1113211] Fri, 20 September 2013 20:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
nope you need the xtext plugins.

and you will always find the root of your model in resource.getContents() and you can ask a resourceset for its resources.
but how you do this is just a matter of taste


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Import a xtext file into EMF [message #1113213 is a reply to message #1113212] Fri, 20 September 2013 20:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: the Classes EcoreUtil / EcoreUtil2 may contain useful utility for working with the model

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Implicitly Import instances of external EMF model
Next Topic:What's necessary for using uml2 within xtext plugin?
Goto Forum:
  


Current Time: Thu Mar 28 17:19:52 GMT 2024

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

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

Back to the top