Save selected node as png file (GEF5) [message #1772332] |
Fri, 08 September 2017 08:14 |
Thomas Oberle Messages: 11 Registered: April 2017 |
Junior Member |
|
|
Hello,
In my GEF5 application I want to save the currently selected node to disk by using a Handled Menu Item.
In my handler class I use the following code to get the selected element:
ZestContentViewer viewer = SWAPart.getZestViewer();
StructuredSelection selection = (StructuredSelection)viewer.getSelection();
Object selectedElement = selection.getFirstElement();
My Problem is that selection.getFirstElement() returns an object of "IGeometry" and not the corresponding part object.
But for taking a snapshot I need the part and not the model.
WritableImage image = swSysPart.getVisual().snapshot(new SnapshotParameters(), null);
File file = new File("C:\\Temp\\chart.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
} catch (IOException e) {
// TODO: handle exception here
}
How can I get the corresponding part of the element which is returned by selection.getFirstElement()?
Or is there a better way to save the selected node as *.png.
Best Regards,
Thomas
[Updated on: Fri, 08 September 2017 08:14] Report message to a moderator
|
|
|
Re: Save selected node as png file (GEF5) [message #1772335 is a reply to message #1772332] |
Fri, 08 September 2017 08:44 |
|
Hi Thomas,
I would take the selection from the SelectionModel of the viewer. The SelectionModel stores the IContentParts that are currently selected. Via the content part, you can access the visual (getVisual()) and the corresponding model object (getContent()). You can also access the HoverModel to query the content part that is currently under the mouse pointer.
In general, if you need to query the content part for a model object, you can use the viewer's content-part-map (getContentPartMap()), and if you need to query the content part for a visual, you can use the viewer's visual-part-map (getVisualPartMap()).
Best regards,
Matthias
|
|
|
Powered by
FUDForum. Page generated in 0.03421 seconds