Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Saving GEF diagram
Saving GEF diagram [message #547678] Mon, 19 July 2010 10:47 Go to next message
Alireza  is currently offline Alireza Friend
Messages: 8
Registered: July 2010
Junior Member
Hello Eclipsers.

I know the topic is old ut i could not find solution after 2 hours of searching. So please help.

I am developing a GEF plugin. Every thing works inside Eclipse. The only feature that i want to add now is that i want to let the user to save his/her diagram so that he/she can load it later.

Here are the things that i already know:
1- I should save my model - I am completely able to rebuild the diagram from its model. Thanks to MVC.

2- I know there is a method called doSave and doSaveAs in eclipse editors that i have to modify.

Here are the things that i dont know:

1- How should i open a specific file with a specific extension in my editor. I have already set the etension attribute of the editor and it successfully opens up the editor. I want to know where i should start to read the content of the file and HOW.

2- How should i save the file ? Should i open an stream in DoSave method and write it on the disk ? Should i serialize my model ?

Any hint is greately appreciated.
Thanks.
Alireza.
Re: Saving GEF diagram [message #547736 is a reply to message #547678] Mon, 19 July 2010 14:06 Go to previous messageGo to next message
Chris  is currently offline Chris Friend
Messages: 44
Registered: April 2010
Member
Alireza wrote on Mon, 19 July 2010 06:47

1- How should i open a specific file with a specific extension in my editor. I have already set the etension attribute of the editor and it successfully opens up the editor. I want to know where i should start to read the content of the file and HOW.

2- How should i save the file ? Should i open an stream in DoSave method and write it on the disk ? Should i serialize my model ?


Hi Alireza,

'm a bit of a beginner myself, so please be careful with what I say Wink

My model implements the Interface Serializable. There one can override the method readObject to do custom loading (I do not know if that is mandatory for GEF). The mechanism for loading a model in an Editor is an EditPartFactory, that has to be registered with the editor in the method configureGraphicalViewer().

The factory gets the root element of your diagram and returns the appropriate EditPart controller. Then recursively getModelChildren() from that EditPart is called and the Factory tries to create EditParts for these children. Thus you have to implement the factory with a huge "if(x instanceof y)" alternative and the necessaray EditPart controllers.

For an example of a doSaveAs implementation and demonstration of how these things work in concert, take a look at the Shape Editor example.

Regards,
Chris

[Updated on: Mon, 19 July 2010 14:06]

Report message to a moderator

Re: Saving GEF diagram [message #549578 is a reply to message #547736] Tue, 27 July 2010 09:17 Go to previous messageGo to next message
René is currently offline RenéFriend
Messages: 45
Registered: July 2009
Member
Hi Alireza,

I go along with Chris. Please look at the ShapesEditor-Examples. It describes carefully how to implement a save and load procedure for GEF. It uses an ObjectOutputStream to save the model object in a serialized fashion. You can find a detailed description here link along with the source code.

For myself I use XML-based approach to save the model data. It only distinguish form the ShapesEditor in the way the model data will be loaded in the setEditorInput(IEditorInput) method and the way how the data will be stored in the doSave() or doSaveAs() method of your editor class.


Regards,
René

[Updated on: Tue, 27 July 2010 09:18]

Report message to a moderator

Re: Saving GEF diagram [message #549611 is a reply to message #549578] Tue, 27 July 2010 11:17 Go to previous messageGo to next message
Alireza  is currently offline Alireza Friend
Messages: 8
Registered: July 2010
Junior Member
Thanks Guy,

I will go thorough your recommendations. Specifically, storing my model data in an XML format.

Thanks Alot.
Re: Saving GEF diagram [message #549724 is a reply to message #549611] Tue, 27 July 2010 17:12 Go to previous message
René is currently offline RenéFriend
Messages: 45
Registered: July 2009
Member
Hi Alireza,

i hope you didn't get me wrong. The Shapes Diagram Editor don't provide a explanation to use a XML-based model. Nevertheless the methodical approach is the same, only the concrete source of data differs. Unfortunately I can't post some code for you, because the tool i developed, doesn't lie under my copyright. But I sure you will manage it.

Cheers,
René
Previous Topic:Properties Order
Next Topic:Alligning the child figures
Goto Forum:
  


Current Time: Fri Apr 19 10:12:14 GMT 2024

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

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

Back to the top