Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » GraphView: loading models from the running platform
GraphView: loading models from the running platform [message #962987] Mon, 29 October 2012 13:36 Go to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
Hi,

I finally found the time to experiment with Jan's GraphView framework.
I really like the approach and the tool works well out of the box.
Thanks, Jan.

However, when trying to make "just one little change" I utterly failed with the Xtext basics:

My goal is to load the models (mapping model and styling model) from a plug-in in the running platfrom rather than from a workspace project (I want to deploy these models as part of my tool).

Here's what I tried and where I failed:
1. load a set of statically known models and insert them into the set of models of the SelectDiagramConfigurationDialog.
- I tried two kinds of URIs: "platform:/plugin/..." and "classpath:"
2. The models are found but at this point none of the imports to any Java types worked, so I replaced several guice bindings:
- change JdtTypeProviderFactory to ClasspathTypeProviderFactory (and also bind a classloader instance)
- change JdtBasedSimpleTypeScopeProvider to ClasspathBasedTypeScopeProvider
3. At this point Java types imported into the models could again be resolved, but after hours of experimentations I could not get cross-references from the styling model to the mapping model resolved. The very same models worked fine when loaded from a project in the workspace. Obviously when reading from a platform plug-in, I don't have a project, but I ensured that I use the exact same injectors as generated by Xtext and that all resources are loaded via the same resource set. I also ensured that the resourceSet has a classpathUriResolver initialized using this call sequence:
		this.resourceSet.getClasspathUriResolver();
		this.resourceSet.setClasspathURIContext(getClass());

I tried loading in different order with/without explicit resolving etc.

Actually, I'm not sure if I need this technique for my final solution but I'm wondering if this is a standard Xtext pattern that has an easy solution:
- Load different models with cross-references from a running plug-in.
Is this a simple/hard task? Any hints how this can be done, how failure to resolve can be debugged?

thanks,
Stephan
Re: GraphView: loading models from the running platform [message #965622 is a reply to message #962987] Wed, 31 October 2012 11:28 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
Have you tried to obtain an XtextResourceSet from the injector of the
mapping language (should get the bindings right), set the classloader of
the bundle containing the model (should be the right classloader) to be
loaded and load the models with a platform:/plugin URI ?

Am 29.10.12 14:36, schrieb Stephan Herrmann:
> Hi,
>
> I finally found the time to experiment with Jan's GraphView framework.
> I really like the approach and the tool works well out of the box.
> Thanks, Jan.
>
> However, when trying to make "just one little change" I utterly failed
> with the Xtext basics:
>
> My goal is to load the models (mapping model and styling model) from a
> plug-in in the running platfrom rather than from a workspace project (I
> want to deploy these models as part of my tool).
>
> Here's what I tried and where I failed:
> 1. load a set of statically known models and insert them into the set of
> models of the SelectDiagramConfigurationDialog.
> - I tried two kinds of URIs: "platform:/plugin/..." and "classpath:"
> 2. The models are found but at this point none of the imports to any
> Java types worked, so I replaced several guice bindings:
> - change JdtTypeProviderFactory to ClasspathTypeProviderFactory (and
> also bind a classloader instance)
> - change JdtBasedSimpleTypeScopeProvider to ClasspathBasedTypeScopeProvider
> 3. At this point Java types imported into the models could again be
> resolved, but after hours of experimentations I could not get
> cross-references from the styling model to the mapping model resolved.
> The very same models worked fine when loaded from a project in the
> workspace. Obviously when reading from a platform plug-in, I don't have
> a project, but I ensured that I use the exact same injectors as
> generated by Xtext and that all resources are loaded via the same
> resource set. I also ensured that the resourceSet has a
> classpathUriResolver initialized using this call sequence:
>
> this.resourceSet.getClasspathUriResolver();
> this.resourceSet.setClasspathURIContext(getClass());
>
> I tried loading in different order with/without explicit resolving etc.
> Actually, I'm not sure if I need this technique for my final solution
> but I'm wondering if this is a standard Xtext pattern that has an easy
> solution:
> - Load different models with cross-references from a running plug-in.
> Is this a simple/hard task? Any hints how this can be done, how failure
> to resolve can be debugged?
>
> thanks,
> Stephan
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: GraphView: loading models from the running platform [message #965860 is a reply to message #965622] Wed, 31 October 2012 15:04 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
Hi Jan,

Your suggestions sound very similar to things I've tried in millions Smile of different combinations.

Let me see, what might be different:

Jan Kohnlein wrote on Wed, 31 October 2012 12:28
Have you tried to obtain an XtextResourceSet from the injector of the
mapping language (should get the bindings right),


Originally I added this in SelectDiagramConfigurationDialog (in the org.eclipse.xtext.graphview plug-in):
@Inject
XtextResourceSet resourceSet;


I now tried 2 other variants:
this.resourceSet = GraphViewStyleActivator.getInstance().getInjector(GraphViewMappingActivator.ORG_ECLIPSE_XTEXT_GRAPHVIEW_MAP_GRAPHVIEWMAPPING).getInstance(XtextResourceSet.class);
// or:
this.resourceSet = GraphViewMappingActivator.getInstance().getInjector(GraphViewStyleActivator.ORG_ECLIPSE_XTEXT_GRAPHVIEW_STYLE_GRAPHVIEWSTYLING).getInstance(XtextResourceSet.class);


Shouldn't the injector of the graphview plugin know about both languages? Mapping only knows its own language, right? Styling should also know both languages, but none worked.

Quote:
set the classloader of
the bundle containing the model (should be the right classloader) to be
loaded


That's what I tried to achieve by this call mentioned in my post:
this.resourceSet.setClasspathURIContext(getClass());


(Is there a better API for this?)

The models are in a fragment of the graphview plug-in so they should share that class loader. Actually all model classes are found, so I don't see a classloader issue.

Quote:
and load the models with a platform:/plugin URI ?


Yes, that was always in the set of variants I tried. Actually, I don't see any different results between platform:/plugin and classpath:

No matter how I combine these: both models get loaded but any references like StyleSheet.diagramMapping remain as unresolved proxies, no matter how hard I try to resolve.

Could this approach break any of the scope providers? The only explicit change I made concerns how JVM types are found (and that part works) - could that change have destructive effects on other parts of resolution?

At the surface the effect is: the selection dialog correctly shows the mapping and all styles, the graph is even rendered but rendering doesn't use the selected style (because its cross-references are unresolved).

thanks,
Stephan
Re: GraphView: loading models from the running platform [message #972561 is a reply to message #965860] Mon, 05 November 2012 18:25 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
Ups, maybe my previous post was a bit long, so here's the executive summary:

Jan's suggestions did not yield any success on my side.

Resolving cross references between different models (of different languages) which are loaded from a running plug-in does not work.

Has anyone succeeded in this before?

thanks,
Stephan
Re: GraphView: loading models from the running platform [message #997406 is a reply to message #972561] Mon, 07 January 2013 10:39 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
Since I failed to deploy gvmap and gvstyle in a plug-in I took a different road:

After mapping and styling have been consolidated using the corresponding DSLs, I hand-coded their behavior into a Java class.
Next I added an extension point to the GraphView plug-in where clients can provide their own model instantiator and plugged the above into this extension point.

Aside from bypassing the deployment problem this also added more flexibility for the instance mapping.

Jan, would you be interested in a patch in this direction? I figure you may not like the idea of bypassing the two DLSs, but I think the combination is actually quite useful: prototyping the mapping in your DSL and later consolidating this into a deployable, fixed m2m trafo.

What I haven't solved yet, but might be desirable, is a combination of programmatical instance mapping (in Java) with declarative styling.

cheers
Stephan
Previous Topic:Errors and not showing in Problems view
Next Topic:Symptom and Solution for Unresolved Xtext Cross-References
Goto Forum:
  


Current Time: Thu Oct 30 12:23:31 GMT 2014

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

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