Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to get Ecore ResourceSet from a custom View?
How to get Ecore ResourceSet from a custom View? [message #1489992] Thu, 27 November 2014 21:35 Go to next message
Pavel Bogachev is currently offline Pavel BogachevFriend
Messages: 3
Registered: November 2014
Junior Member
Hi,

I'm taking a part in a development of an XText-based Eclipse plugin for a DSL designed by our team. I need to create a View, that reflects some components of Ecore model, generated by Xtext grammar. It is going to be somewhat similar to Outline, but with many differences, e.g. it is going to be a CheckboxTreeView, have some nodes not present in grammar, restructure some parts of the tree, etc.

I'm having problems trying to access generated Resource from a my own separate View rather than from Outline View. Just like Outline, my View needs to be kept up-to-date with changes in DSL code, but I can't find a source that supplies Outline with constantly updated Resource contents.

So far, I only managed to manually pass Resource from _createChildren() method of Outline to my View. But that's obviously not the way to go, since my View shouldn't depend on OutlineView.

My attempt looks like this:

public class MyDSLOutlineTreeProvider extends DefaultOutlineTreeProvider {
    def _createChildren(IOutlineNode parentNode, MyXTextGrammarRoot root) {
        // ...

        MyView.updateInput(
            root.eResource.getResourceSet().getResources().get(0)
        )
    }
//...
}


I need to get same object independently from outline. How do I do that?
Re: How to get Ecore ResourceSet from a custom View? [message #1510697 is a reply to message #1489992] Sun, 14 December 2014 09:06 Go to previous message
Pavel Bogachev is currently offline Pavel BogachevFriend
Messages: 3
Registered: November 2014
Junior Member
I got the solution. For those who interested, I'll write down what I needed to do.

To get your xtext grammar root you need to do the following:

IEditorPart editor = partRef.getPage().getActiveEditor();
IXtextDocument document =
	((XtextEditor) editor).getDocument();

MyXTextGrammarRoot root =
	(MyXTextGrammarRoot) document.readOnly(
		new IUnitOfWork<XtextResource, XtextResource>() {
			public XtextResource exec(XtextResource state) {
				return state;
			}
		}
	).getContents().get(0);

System.out.println(root.eResource());


To listen to any changes of your xtext model:

document.addModelListener(
	new IXtextModelListener() {
		@Override
		public void modelChanged(XtextResource resource) {
			System.out.println(resource);
		}
	}
);
Previous Topic:[Xtext]Cross reference between different files
Next Topic:XText standalone content assistant
Goto Forum:
  


Current Time: Thu Apr 25 20:33:10 GMT 2024

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

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

Back to the top