Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Crossreferences in an embedded editor
Crossreferences in an embedded editor [message #892501] Thu, 28 June 2012 13:20 Go to next message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
Hi,

I have some scoping issues with a partial editor I created with the EmbeddedEditorFactory. Here I want to crossreference to other model elements in other files. The language I developed is capable of this, so I think there is an error with my implementation...

First of all I created a resource with an URI "somefile.dsl" in the SWT control in which I want to embedd the editor.


IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {

	        @Override
	        public XtextResource createResource() {
	            try {
	            	MyDSLStandaloneSetup.doSetup();
	                ResourceSet resourceSet = new ResourceSetImpl();
	                Resource resource = resourceSet.createResource(URI.createURI("somefile.dsl"));

	                return (XtextResource) resource;
	            } catch (Exception e) {
	                return null;
	            }
	        }
	    };



I think there must be the error, as the URI "somefile.dsl" is not in the project where my other models are. But If I change the URI to the project path, I get the error that the file "somefile.dsl" does not exist. Unfortunately it is not an option to create files in the project.

Do you have any ideas on how to solve this problem? Any hints, suggestiones etc would help me alot Wink

Best regards,
Masija
Re: Crossreferences in an embedded editor [message #892637 is a reply to message #892501] Thu, 28 June 2012 22:08 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Masija,

please do yourself a favor and don't ever use the standalone setup in an
eclipse environment - it's called StandaloneSetup for good reasons ;-)

Furthermore you should - if you want to edit an actual file - use the
platform:/resource uri of that file.


Please try to use something along these lines:

@Inject
XtextResourceSetProvider resourceSetProvider;

XtextResourceSet resourceSet =
resourceSetProvider.get(projectOfEnclosingIResource)
URI uri =
URI.createURI("platform:/resource/projectName/path/in/project.dslExtension")
resourceSet.getResource(..)

I suggest to learn more about dependency injection and how EMF works.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.06.12 15:20, schrieb masija .:
> Hi,
>
> I have some scoping issues with a partial editor I created with the
> EmbeddedEditorFactory. Here I want to crossreference to other model
> elements in other files. The language I developed is capable of this, so
> I think there is an error with my implementation...
>
> First of all I created a resource with an URI "somefile.dsl" in the SWT
> control in which I want to embedd the editor.
>
>
>
> IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {
>
> @Override
> public XtextResource createResource() {
> try {
> MyDSLStandaloneSetup.doSetup();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI("somefile.dsl"));
>
> return (XtextResource) resource;
> } catch (Exception e) {
> return null;
> }
> }
> };
>
>
>
> I think there must be the error, as the URI "somefile.dsl" is not in the
> project where my other models are. But If I change the URI to the
> project path, I get the error that the file "somefile.dsl" does not
> exist. Unfortunately it is not an option to create files in the project.
> Do you have any ideas on how to solve this problem? Any hints,
> suggestiones etc would help me alot ;)
>
> Best regards,
> Masija
Re: Crossreferences in an embedded editor [message #892884 is a reply to message #892637] Sun, 01 July 2012 09:52 Go to previous messageGo to next message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
Hi Sebastian,
thanks alot for your reply and your references to usefull topics to understand the concepts of xtext and emf!
If I reread your message, my question appears quite stupid, so thanks again for your time Wink

Best regards,
Masija
Re: Crossreferences in an embedded editor [message #893007 is a reply to message #892884] Mon, 02 July 2012 09:28 Go to previous message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
Hi Sebastian, again a question from me...
I can't get your snippets fo work corectly. I have injected an XtextResourceSetProvider. After that I changed the createResource() method i posted above to:


IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {

	        @Override
	        public XtextResource createResource() {
	            try {
	            	      	
	               	        URI fileURI = editingDomain.getResourceSet().getResources().get(0).getURI();
	        		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fileURI.segment(1));
	        		ResourceSet resourceSet = resourceSetProvider.get(project);
	        		Resource resource = resourceSet.createResource(URI.createURI("somefile.dsl"));
	        		
	                return (XtextResource) resource;
	            } catch (Exception e) {
	                return null;
	            }
	        }
	    };

EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
	    handle = factory.newEditor(resourceProvider).withParent(parent);
	    partialEditor = handle.createPartialEditor(true);
	    // set the input of the document in the popup editor to the value, stored in the modelA
	    handle.getDocument().set(StringValueOfModelA);



But this doesn't change anything... Perhaps an explanation what I am trying to do. I have a model (ModelA) which has some EString properties. In the editor of this model, i embedded an Editor for my xtext dsl to be able to input correct statements of my grammar. This grammar references another xtext model (ModelB), which is in the same project as ModelA.

These crossreferences are not possible... So I dont want to edit an actual file, I want to edit some Strings in ModelA, which should be interpreted in respect to my xtext grammar. These strings shouldnt be saved somewhere in the workspace.
Perhaps your hint, how EMF works will be promising... I have started to read the EMF book, but haven't got the big picture to understand what I am doing wrong.
Perhaps you could comment again in this topic and help me Wink

Regards
Masija

[Updated on: Mon, 02 July 2012 09:33]

Report message to a moderator

Previous Topic:How to use xtext inferred JVM model outside of xtext project?
Next Topic:XText Web proposals engine
Goto Forum:
  


Current Time: Fri Apr 19 04:28:50 GMT 2024

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

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

Back to the top