GraphView: loading models from the running platform [message #962987] |
Mon, 29 October 2012 13:36 |
Stephan Herrmann Messages: 1853 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 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
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
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Re: GraphView: loading models from the running platform [message #965860 is a reply to message #965622] |
Wed, 31 October 2012 15:04 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Hi Jan,
Your suggestions sound very similar to things I've tried in millions of different combinations.
Let me see, what might be different:
Jan Kohnlein wrote on Wed, 31 October 2012 12:28Have 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03942 seconds