Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Saving Shapes diagram into XML
Saving Shapes diagram into XML [message #214888] Tue, 25 April 2006 06:13 Go to next message
Eclipse UserFriend
Originally posted by: suresh.babu.lgcnsglobal.com

Hi,

Once i create the shapes with connections using GEF on the graphical editor, how to save this particular flow chart into XML or as XML.

Please give me sample code if any one has or some tips to achive this..
Re: Saving Shapes diagram into XML [message #214894 is a reply to message #214888] Tue, 25 April 2006 08:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam.giemza.gmx.de

Suresh schrieb:
> Hi,
>
> Once i create the shapes with connections using GEF on the graphical editor, how to save this particular flow chart into XML or as XML.
>
> Please give me sample code if any one has or some tips to achive this..

You have to override the doSave-method in your editor class (subclass of
GraphicalEditorWithPalette or another editor)! There you get a monitor
object. Now you have to write an object, that writes your modell to xml
an add it then to the monitor.

I hope it helps :)
Re: Saving Shapes diagram into XML [message #214903 is a reply to message #214894] Tue, 25 April 2006 08:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: suresh.babu.lgcnsglobal.com

Adam thanks for you reply.

But do you have any sample for this or any site where i can refer for the same.
Re: Saving Shapes diagram into XML [message #214907 is a reply to message #214903] Tue, 25 April 2006 08:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam.giemza.gmx.de

Suresh schrieb:
> Adam thanks for you reply.
>
> But do you have any sample for this or any site where i can refer for the same.

Try the Shapes-Example from GEF. doSave is implemented there. But they
use serialisation and not XML, but it shows how to save your stuff!
Re: Saving Shapes diagram into XML [message #214911 is a reply to message #214907] Tue, 25 April 2006 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: suresh.babu.lgcnsglobal.com

Adam, Actually I am working on Shapes example. Check the following

<b>diagram = (ShapesDiagram) in.readObject();
XMLHandler handleXML = new XMLHandler();
handleXML.WriteToXML("c:/Testing.xml",diagram);</b>

and handleXML.WriteToXML method details are

<b>XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(fileName)));
encoder.writeObject(object); // object here is diagram (which contains all other shapes).
encoder.close();</b>

But saving like this will give you following xml output
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_11" class="java.beans.XMLDecoder">
<object class="org.eclipse.gef.examples.shapes.model.ShapesDiagram"/ >
</java>
Re: Saving Shapes diagram into XML [message #214915 is a reply to message #214911] Tue, 25 April 2006 09:26 Go to previous message
Eclipse UserFriend
Originally posted by: adam.giemza.gmx.de

Suresh schrieb:
> Adam, Actually I am working on Shapes example. Check the following
>
> <b>diagram = (ShapesDiagram) in.readObject();
> XMLHandler handleXML = new XMLHandler();
> handleXML.WriteToXML("c:/Testing.xml",diagram);</b>
>
> and handleXML.WriteToXML method details are
>
> <b>XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(fileName)));
> encoder.writeObject(object); // object here is diagram (which contains all other shapes).
> encoder.close();</b>
>
> But saving like this will give you following xml output
> <?xml version="1.0" encoding="UTF-8"?>
> <java version="1.4.2_11" class="java.beans.XMLDecoder">
> <object class="org.eclipse.gef.examples.shapes.model.ShapesDiagram"/ >
> </java>


I think that your fault is in the usage of the XMLEncoder. Look into the
docs: http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncode r.html

It says: Despite the similarity of their APIs, the XMLEncoder class is
*exclusively* designed for the purpose of archiving graphs of JavaBeans
as textual representations of their public properties.

So maybe your model have to be a JavaBean with public getters and
setters and so on. I am not really sure.
Previous Topic:Resize inside an editpart
Next Topic:Synchronized GEF-Editors
Goto Forum:
  


Current Time: Thu Dec 18 21:11:49 GMT 2014

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

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