Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference issue while using EmbeddedEditor
Cross reference issue while using EmbeddedEditor [message #1720239] Fri, 15 January 2016 13:52 Go to next message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
Hi,


Code used to show xtext control (embedded mode) in a standalone application

		
               EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);

		handle = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations().withParent(parent);
		LineNumberRulerColumn lnrc = new LineNumberRulerColumn();
		handle.getViewer().addVerticalRulerColumn(lnrc);


To add cross reference capability in standalone application, i injected "ResourceSetBasedAllContainersState" class for IAllContainersState interface in "NGXUiModule"

		var state = new ResourceSetBasedAllContainersState();
		var containers = Arrays.asList("All");
		var container2Uris = ArrayListMultimap.create();
		container2Uris.put("Base", URI.createFileURI("/Users/XYZ/file1.ngx"));
		container2Uris.put("Base", URI.createFileURI("/Users/XYZ/file2.ngx"));
		state.configure(containers, container2Uris)
		return state;	


"ngx" is the extension provided while creating the xtext project

When i open file2.ngx file using xtext editor in standalone application, it is not looking in file2.ngx for its references.

It gives "Couldn't resolve reference to " error.

Please help me to solve this cross reference issue.

Saravanan A
Re: Cross reference issue while using EmbeddedEditor [message #1720256 is a reply to message #1720239] Fri, 15 January 2016 15:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You should populate the resource set in the resourceprovider

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference issue while using EmbeddedEditor [message #1720261 is a reply to message #1720256] Fri, 15 January 2016 15:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You should populate the resource set in the resourceprovider

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference issue while using EmbeddedEditor [message #1720276 is a reply to message #1720261] Fri, 15 January 2016 18:12 Go to previous messageGo to next message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
I have tried that too...Still not working...

public class NGXResourceProvider implements IEditedResourceProvider {

	@Inject
	private IResourceSetProvider resourceSetProvider;

	private XtextResource resource;

	@Override
	public XtextResource createResource() {
		try {
			if (resource != null) {
				return resource;
			}
			ResourceSet resourceSet = resourceSetProvider.get(null);
			Resource baseResource = resourceSet.createResource(URI.createFileURI("/Users/XYZ/file1.ngx"));
			resourceSet.createResource(URI.createFileURI("/Users/XYZ/file2.ngx"));			
			resource = (XtextResource) baseResource;
			return resource;
		} catch (Exception e) {
			return null;
		}
	}

	public XtextResource getResource() {
		return resource;
	}

}



		NGXResourceProvider resourceProvider = injector.getInstance(NGXResourceProvider.class);
		this.resource = resourceProvider.createResource();

		EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
		handle = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations().withParent(parent);
Re: Cross reference issue while using EmbeddedEditor [message #1720279 is a reply to message #1720276] Fri, 15 January 2016 20:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you share a complete minimal reproduceable example? how does you guice setup look like?
i am not sure that xtext will work truely standlone so having a starting point to analyse would help.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference issue while using EmbeddedEditor [message #1720295 is a reply to message #1720279] Sat, 16 January 2016 08:01 Go to previous messageGo to next message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
Please create below mentioned to 2 files in any directory and change
DirectoryUtil.java (org.xtext.example.ngx.ui/src/org/xtext/example/ngx/ui/) accordingly.

file1.ngx content
Type Name as STRING



file2.ngx content
Entity entity1 as Name


In NgxUiModule, i have injected the "ResourceSetBasedAllContainersState" provider.

Check View.java (StandalonePrj) for Embedded XText editor creation.
Re: Cross reference issue while using EmbeddedEditor [message #1720297 is a reply to message #1720279] Sat, 16 January 2016 09:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i dont see anything on "standalone" in your project. it is all eclipse based. standalone in terms of xtext is "without osgi AND workspace environment".
so if you want to use a resourcesetbased index in eclipse you have to configure that

class NgxUiModule extends AbstractNgxUiModule {
	
	def configureIResourceDescriptions(Binder binder) {
		binder.bind(IResourceDescriptions).to(ResourceSetBasedResourceDescriptions).in(Scopes.SINGLETON);
	}
	
	override Class<? extends IAllContainersState.Provider> bindIAllContainersState$Provider() {
		return ResourceSetBasedAllContainersStateProvider;
	}
	
}


public class CustomCLangResourceProvider implements IEditedResourceProvider {

	@Inject
	private Provider<ResourceSet> resourceSetProvider;

	private XtextResource resource;

	@Override
	public XtextResource createResource() {
		try {
			if (resource != null) {
				return resource;
			}
			ResourceSet resourceSet = resourceSetProvider.get();
			for (URI uri : DirectoryUtil.getAllUris()) {
				Resource baseResource = resourceSet.createResource(uri);
				resource = (XtextResource) baseResource;				
			}
			
			return resource;
		} catch (Exception e) {
			return null;
		}
	}

	public XtextResource getResource() {
		return resource;
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference issue while using EmbeddedEditor [message #1720301 is a reply to message #1720297] Sat, 16 January 2016 13:40 Go to previous messageGo to next message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
Hi,

StandalonePrj is a RCP application and not used as plugin inside eclipse. I don't see a workspace environment here. Correct me if i am wrong.

Where should i place these 2 files(ngx files), so that xtext can resolve cross reference dependencies ?

Thanxs for quick reply.

Saravanan A
Re: Cross reference issue while using EmbeddedEditor [message #1720302 is a reply to message #1720301] Sat, 16 January 2016 13:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
they re are actually your files patched. then it works (on my machine)
what is the error you get?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 16 January 2016 14:00]

Report message to a moderator

Re: Cross reference issue while using EmbeddedEditor [message #1720309 is a reply to message #1720302] Sat, 16 January 2016 15:11 Go to previous messageGo to next message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
Thanx you so much. It works...

Is there any provider which scans the directory (monitor the changes) and loads all the ngx files ?
Re: Cross reference issue while using EmbeddedEditor [message #1720310 is a reply to message #1720309] Sat, 16 January 2016 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No (maybe you can make
Use of xtext.mwe.reader


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference issue while using EmbeddedEditor [message #1720312 is a reply to message #1720310] Sat, 16 January 2016 15:30 Go to previous message
saravanan Arumugam is currently offline saravanan ArumugamFriend
Messages: 7
Registered: September 2011
Junior Member
If you know any sample/tutorial about reader please give some pointers...
Previous Topic:Problems getting xtext running in IntelliJ
Next Topic:How to add formatter based on the new formatting API to the project
Goto Forum:
  


Current Time: Fri Apr 26 01:38:32 GMT 2024

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

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

Back to the top