Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » ZEST: Register GraphViewer as a model listener
ZEST: Register GraphViewer as a model listener [message #1273156] Wed, 19 March 2014 16:07 Go to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 29
Registered: July 2011
Junior Member
Hi,
this might be a stupid question but I'm new to ZEST and GEF.

THe following use case: I have my own RCP application where I integrated my own GraphView as a ViewPart.
It is added via an extension point, so (I think) I have no control about the instantiation of my view and its containing GraphViewer instance (I might be wrong here).

What I want to do is to show the view next to an Xtext editor where the user can manipulate a model. When the user saves the changes, I have a hook from Xtext to be notified if the new model should be build (by overriding the BuilderParticipant that invokes the generator of my language).

The problem is that, from within my Xtext code, I see no clean chance to access the ViewPart and/or GraphViewer instance that was created during eclipse startup. I know that I could ask the workbench for the view part via its id but this seems unnecessary complicated.

Isn't the described use case quite popular (that you want to register a viewer to a model) but you don't know about the model when eclipse instantiates the view? What's the kook here?

Thanks.
Re: ZEST: Register GraphViewer as a model listener [message #1273163 is a reply to message #1273156] Wed, 19 March 2014 16:26 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

instead of replacing the builderparticipant, I suggest an alternative approach.

First, create a command (or action) that loads the model using the current editor. This command can know about your ViewPart/GraphViewer, so it can initialize its content.

Then register an IResourceChangeListener (inside the view initialization code) on the file of the editor (core.resources plug-in). This listener will be notified when the file is saved, so you can update your viewer as required.

Cheers,
Zoltán
Re: ZEST: Register GraphViewer as a model listener [message #1273225 is a reply to message #1273163] Wed, 19 March 2014 18:53 Go to previous messageGo to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 29
Registered: July 2011
Junior Member
Hey Zoltán,

thanks for that suggestion. Sounds like a possible alternative and I will give it a try. Much appreciated.

One reason to go with the Xtext Builder participant is that it already includes some smart strategy to decide whether or not it is reasonable to "build". In other words, with hooking in the builder participant I wouldn't have to care about the user saving corrupt models.

Best,
Robert
Re: ZEST: Register GraphViewer as a model listener [message #1274197 is a reply to message #1273225] Fri, 21 March 2014 05:26 Go to previous message
Robert Walter is currently offline Robert WalterFriend
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

Previous Topic:GEF as native Drag Source
Next Topic:Save not working
Goto Forum:
  


Current Time: Tue Mar 19 10:36:15 GMT 2024

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

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

Back to the top