Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Save selected node as png file (GEF5)(Save selected node as png file (GEF5))
Save selected node as png file (GEF5) [message #1772332] Fri, 08 September 2017 08:14 Go to next message
Thomas Oberle is currently offline Thomas OberleFriend
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 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
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
Previous Topic:Bend Connections routed by OrthogonalRouter (GEF 5)
Next Topic:Prevent nodes from being dragged out of parent bounds (GEF5)
Goto Forum:
  


Current Time: Sat Nov 09 02:30:31 GMT 2024

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

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

Back to the top