Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Navigate through diagrams of different types(Navigate through diagrams of different types)
Navigate through diagrams of different types [message #835654] Tue, 03 April 2012 14:02 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi there,

I defined two different models and the corresponding diagrams.
The first model / diagram called 'Device Overview' (DO) lets me describe a 'device' that may use a 'component'.
The component itself is described in a 'Component Detail' (CD) model / diagram.

The plug-in works fine and - thanks to the help of this forum - I can even drag a component from a CD model and drop it on a DO diagram.

Now I would like to double-click on the component shortcut in the DO diagram, to open the correponding CD diagram.

I had a look to several posts and also the Jevon diagram partitionning tutorial.
I did the following actions :

1. I loaded the CD.gmfmap file as a resource for the DO.gmfmap.

2. In the DO.gmfmap, there's a declaration for a Component Top Node Reference.
At that level, I modified the Node Mapping 'Misc/Related Diagrams' property.
I selected the CD.gmfmap canvas.

3. I regenerated the corresponding DO.gmfgen file. The generator adds an 'open diagram behaviour' in Gen Diagram -> Gen Top Level Component.
So far so good...

4. I then modified the 'Diagram kind' and 'Editor ID' as requested by selecting the corresponding values in CD.gmfgen.

After regenerating the DO.diagram project, I get the following exception when double-clicking on the component shorcut in the DO diagram.

org.eclipse.core.commands.ExecutionException: Can't open diagram
at deviceoverview.diagram.edit.policies.OpenDiagramEditPolicy$OpenDiagramCommand.doExecuteWithResult(OpenDiagramEditPolicy.java:106)

and then :

Caused by: org.eclipse.core.commands.ExecutionException: Can't create diagram of 'ComponentDetail' kind
at deviceoverview.diagram.edit.policies.OpenDiagramEditPolicy$OpenDiagramCommand.intializeNewDiagram(OpenDiagramEditPolicy.java:124)
at deviceoverview.diagram.edit.policies.OpenDiagramEditPolicy$OpenDiagramCommand.doExecuteWithResult(OpenDiagramEditPolicy.java:95)

I had a look to the generated OpenDiagramEditPolicy.java file and more precisely to the following doExecuteWithResult method :

protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
try {
Diagram diagram = getDiagramToOpen();
if (diagram == null) {
diagram = intializeNewDiagram();
}
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment() + '#'
+ diagram.eResource().getContents().indexOf(diagram);
IEditorInput editorInput = new URIEditorInput(uri, editorName);
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
page.openEditor(editorInput, getEditorID());
return CommandResult.newOKCommandResult();
} catch (Exception ex) {
throw new ExecutionException("Can't open diagram", ex);
}
}

It appears that the program fails to get the diagram to open. It then tries to initialize a new diagram that also fails.
I don't want a new diagram to be created but the right and existing one to be opened Smile.

So I had a closer look to getDiagramToOpen. It simply returns the value of the 'diagramLink' attribute from the 'diagramFacet' object.
But, strange enough, this diagram link is null and I don't understand why.
Could anybody tell me what's wrong ?

The gmfgraph and gmfgen files are in the DeviceCore project.
I also upload the plug-in directory with the sample models.

Regards,

Laurent
Re: Navigate through diagrams of different types [message #836503 is a reply to message #835654] Wed, 04 April 2012 15:08 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

I studied my problem a little bit futher.
Using the 'Shortcuts provided for' property in CD gmfgen and even adding a shortcut action in DO gmfgen context menu doesn't change anything.

So I should may be change the generated OpenDiagramEditPolicy#getOpenCommand.
My idea is to switch from the DO View returned by the targetEditPart to the CD View.

From the DO View given by the targetEditPart, I have access to the EMF CDModelImpl object containing the Component I double-clicked on.
My question is : Is there a way to find back the associated GMF diagram / view from this EMF CDModelImpl object ?

And still, is this the right way to deal with my navigation problem Wink ?

Regards,

Laurent
Re: Navigate through diagrams of different types [message #838128 is a reply to message #836503] Fri, 06 April 2012 16:02 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

I found a workaround to my problem.
Forget about the 'Misc/Related Diagrams' property in DO.gmfmap.
Add manually an open behaviour in DO.gmfgen at Gen Top Level Node ComponentEditPart.
Let both 'Diagram kind' and 'Editor ID' properties empty.
But specify an OpenCDDiagramEditPolicy java file instead of the default OpenDiagramEditPolicy.

In this file, you only write a new 'getOpenCommand' method that locate the targeted CD diagram resource and open it with CDDiagramEditorUtil#openDiagram.

See the attached file for details.

So, it seems GMF doesn't support opening diagram B from inside diagram A when they are based on distinct underlying ecore models.

If I'm wrong, could somebody please tell me the right gmfgraph and gmfgen configuration to do this automatically without having to write the attached code ?
If not, I consider filling a enhancement resquest in bugzilla.

Regards,

Laurent
Previous Topic:Bug: object doesn't appear in GMF diagram editor, but is created in Ecore model
Next Topic:Copy-paste betwen diagrams
Goto Forum:
  


Current Time: Sun Nov 01 02:31:46 GMT 2020

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

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

Back to the top