Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » retrieving the model from a different plugin
retrieving the model from a different plugin [message #1061620] Mon, 03 June 2013 06:24 Go to next message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

I have developed a view depicting some aspects of a DSL.
I have managed to update the view on changes on the XTextEditor (and outline). However I would also like the view to be updated when launched (without needs of clicking on the editors to trigger the change listener). To this end I need to retrieve the model (DSL) which is currently loaded.
What is right way to do that?


Follow me on Twitter @andreasindico

Re: retrieving the model from a different plugin [message #1061624 is a reply to message #1061620] Mon, 03 June 2013 06:56 Go to previous message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

Ok I guess I can answer myself

I retrieve the current editor in this way:

IEditorPart ie = (IEditorPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();


I therefore check whether the returned editor is an XtextEditor or not
If it is an XtextEditor instance I therefore use the IUnitOfWork in this way

eobject = editor.getDocument().readOnly(
    new IUnitOfWork<EObject, XtextResource>() {
    public EObject exec(XtextResource resource) throws Exception {
	EObjectAtOffsetHelper eObjectAtOffsetHelper = new EObjectAtOffsetHelper();
	EObject eObject = eObjectAtOffsetHelper.resolveElementAt(resource, 0);
	return eObject;
     }
});


notice that I could have also used a simpler
resource.getContents().get(0);


in order to retrieve the root node of my model



Follow me on Twitter @andreasindico

[Updated on: Mon, 03 June 2013 06:57]

Report message to a moderator

Previous Topic:Disable lazyRessources
Next Topic:xText + EMF Editor
Goto Forum:
  


Current Time: Wed Aug 20 14:52:01 EDT 2014

Powered by FUDForum. Page generated in 0.01471 seconds