|
|
|
Re: ZEST: Register GraphViewer as a model listener [message #1274197 is a reply to message #1273225] |
Fri, 21 March 2014 05:26 |
Robert Walter Messages: 29 Registered: July 2011 |
Junior Member |
|
|
Okay, here is my solution so far which I think is decent enough to share:
I work with Xtext SDK 2.5.0.v201312110906 and GEF4 Zest SDK 0.1.0.201403150206.
1. Create a subclass of ViewPart and give it a GraphViewer object
2. Mark this class with the Singleton annotation of Guice
3. Initialize your viewer in the your override of createPartControl (refer to this tutorial if necessary). However, I don't set the input however, since I don't have a model at startup time.
4. Add your view the views extension point of your DSL.ui project
5. Make sure that it is instantiated using your ExecutableExtensionFactory, sth like this:
<extension point="org.eclipse.ui.views">
<view class="[YOUR LANGUAGE].ui.ExecutableExtensionFactory:[YOUR LANGUAGE].ui.views.[YOUR VIEW]"
id="[AN ID]"
name="SOME NAME"
restorable="true">
</view>
</extension>
6. Add a "refresh" method to your ViewPart implementation, sth like this, where you pass the model as a resource or however you like:
def refresh(MyGraphModel flatList) {
Display.^default.syncExec [ |
graphViewer.setInput(flatList)
]
}
7. Subclass Xtext's BuilderParticipant and inject your singleton graph viewer:
@Inject
MyGraphView graphView
override protected handleChangedContents(Delta delta, IBuildContext context,
EclipseResourceFileSystemAccess2 fileSystemAccess) throws CoreException {
val resource = context.resourceSet.getResource(delta.uri, true);
if (shouldGenerate(resource, context)) {
try {
if (graphView != null && graphView.graphViewer != null) {
graphView.refresh(resource.m2m)
}
} catch (RuntimeException e) {
if (e.cause instanceof CoreException) {
throw e.cause as CoreException
}
throw e;
}
}
super.handleChangedContents(delta, context, fileSystemAccess)
}
Note that I call the super-implementation after my graph refresh to avoid unresolved objects in the resource.
8. You need to add your View to the perspectiveExtensions extension point if you want to show it right at start up.
9. Make sure that you've added bindings for your BuilderParticipant and ViewPart to your UI Module so Guice knows what to create.
If I haven't forgotten anything, this should lead to a graph view that "listens" to updates in your Xtext Editor.
Once I have a decent m2m transformation to show a nice graph I upload a video.
Have fun!
[Updated on: Fri, 21 March 2014 05:29] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04051 seconds