Navigate through diagrams of different types [message #835654] |
Tue, 03 April 2012 10:02  |
Eclipse User |
|
|
|
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 .
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 #838128 is a reply to message #836503] |
Fri, 06 April 2012 12:02  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.07132 seconds