Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » GMF multidiagram editor - avoid data lost(GMF multidiagram editor - avoid data lost)
GMF multidiagram editor - avoid data lost [message #1691799] Thu, 09 April 2015 17:44 Go to next message
Gregorio Barberio is currently offline Gregorio BarberioFriend
Messages: 5
Registered: April 2015
Junior Member
Hi,
I have a simple question.
In my GMF/EMF tool, I can edit a diagram from an "active part" of Eclipse and from that (the active Tab) I can edit details of the diagrams in other "active part", my problem is:
when I switch between the "active part" I can meet data loss if I do not save before switching.
I need a solution to show to the user a dialog that inform him about the possibility of data loss, the dialog should appear when a user click on a different Tab.

Have you some suggestions?
Thanks
Re: GMF multidiagram editor - avoid data lost [message #1691981 is a reply to message #1691799] Sat, 11 April 2015 12:04 Go to previous messageGo to next message
Nikos Margaritis is currently offline Nikos MargaritisFriend
Messages: 65
Registered: September 2014
Member

Is a single file shared between these tabs? Like the model in different views (emf/gmf)? If so you need to share the editingDomain. Take a look here https://www.eclipse.org/articles/article.php?file=Article-Integrating-EMF-GMF-Editors/index.html

If not, and for example you display different files in each tab that are generated on the fly you will need to add some logic in your editor class. (see changePage method for the message you mentioned)

[Updated on: Sat, 11 April 2015 18:34]

Report message to a moderator

Re: GMF multidiagram editor - avoid data lost [message #1692130 is a reply to message #1691981] Mon, 13 April 2015 18:03 Go to previous messageGo to next message
Gregorio Barberio is currently offline Gregorio BarberioFriend
Messages: 5
Registered: April 2015
Junior Member
Thank you for your answer!
Yes, there is a single diagram file opened but the editingDomain is not shared, the sharing of editingDomain is too complex in this stage, I need to start from scratch...

The second suggestion appears to be nearest to my scope, can you explain me the suggested solution with some additional detail?
Thank you
Re: GMF multidiagram editor - avoid data lost [message #1692143 is a reply to message #1692130] Mon, 13 April 2015 21:30 Go to previous messageGo to next message
Nikos Margaritis is currently offline Nikos MargaritisFriend
Messages: 65
Registered: September 2014
Member

Hello,

could you please post a screenshot showing your opened file and the tabs? So as for everyone to understand the concept and which editor you are using. For example, are you using the default multipage editor generated by GMF (that is the model editor) or you have created a new multipage editor which combines the diagram and some EMF views?

If you provide the requested details I can give you a hint in which Class/Methods to look at.

Generally, the diagram editor class is located in the .diagram plugin under the xxx.diagram.parts > XXXDiagramEditor.java
The EMF(model views) editor is located under the .editor plugin under the xxx.presentation > XXXEditor.java

Now if you are sharing a single file between these tabs and the tabs include GMF and EMF views of the same file (only), then following the tutorial that I provided is the best way to go.
You will not have to start from scratch in order to follow the tutorial. You will just need to have a working GMF project.

Best, Nikos
Re: GMF multidiagram editor - avoid data lost [message #1692564 is a reply to message #1692143] Thu, 16 April 2015 13:58 Go to previous messageGo to next message
Gregorio Barberio is currently offline Gregorio BarberioFriend
Messages: 5
Registered: April 2015
Junior Member
I followed the instructions explained in this article:
[http://] hflorezf-en.blogspot.it/2014/04/gmf-partitioning.html

My case is very similar to the case of the example: the differences relate the names and the amount of the elements but the structure of the ecore is the same.

I have created and customized the code of the diagram Model and Container (respectively in my example are Model and Machine ).

When I try to model different Containers (or rather Machines), occurs data loss in the Container (Machine) that I have not saved.

This is a classical situation in which occurs data loss
(Please refers to TEST section of the referenced example)
1) Create a Partitioning Diagram.
2) Add Container1 and Container2
3) Select Container1 and double click. The container editor will be opened.
4) Draw elements and relations
5) Turn back on the Partitioning Diagram
6) Select Container2 and double click. The container editor will be opened.
7) Draw elements and relations
8) Save the changes on the active tab (Container 2 editor, figure above step 9 in the example)

Results
When turn back to Container 1 diagram, a message box appears:
"File Changed - The File Has Been changed on the file system do you want to load the changes"

If I choose "Yes" I lose unsaved data in Container 1
If I choose "No", the data saved in Container 2 are not loaded in the Container 1 and if I save again a data loss occurs in changes made in Container 1

This is only a simple scenario but it is simple to create more scenarios which are prone to data lose.

Thanks!

[Updated on: Thu, 16 April 2015 13:58]

Report message to a moderator

Re: GMF multidiagram editor - avoid data lost [message #1692604 is a reply to message #1692564] Thu, 16 April 2015 18:58 Go to previous messageGo to next message
Nikos Margaritis is currently offline Nikos MargaritisFriend
Messages: 65
Registered: September 2014
Member

Ok, then it is clear that you do not deal with a multipage editor here.

This is a multipage editor and what I was referring as tabs. (look at selection|tree|etc|Diagram at the bottom)
http://www.eclipse.org/articles/Article-Integrating-EMF-GMF-Editors/screenshots/IntegratedGMFEditor.png

In your case you just have a different instance of the same file opened in new eclipse tabs. It is like you open three instances of a single file and attempt to edit them without saving. When you attempt to save the file, eclipse identifies that this resource has changed and that's why you get the message that "File Changed - The File Has Been changed on the file system do you want to load the changes" when you attempt to open the other tabs. Because when you opened them the IEditorInput(the content of the file) given to eclipse in order to display the file was different. This is a "strategy" of eclipse in order to prevent data loss.

Sharing the editingDomain is not applicable in your case. Generally, I believe that this is not a good approach to edit the file (through partitioning). Even if you move and save each tab separately, when you move back to the previous tabs you will get the dialog message.

Possibly you could search on how to refresh all the open instances of the same file if that changes (without closing them). In case that you do something like that, you will then need to call it in the method doSave of your xxxDiagramEditor that is located under pluginName.diagram -> src --> part --> xxxDiagramEditor.java --> doSave method. However, I still say that this is not a good approach to deal with the problem.

You could combine, all the nodes in a single editor(having them all available in your palette) and allow elements and relations to be added only under/in those containers, that are of course resizable. This is consider partitioning too, in a different way..

Best.

[Updated on: Thu, 16 April 2015 19:20]

Report message to a moderator

Re: GMF multidiagram editor - avoid data lost [message #1692789 is a reply to message #1692604] Sat, 18 April 2015 15:08 Go to previous message
Gregorio Barberio is currently offline Gregorio BarberioFriend
Messages: 5
Registered: April 2015
Junior Member
I appreciated your suggestions.
Combine all the node in a single editor is not suitable in my scenario.
I found a simple solution, without writing code, installing this plugin:
[https://]github.com/mystilleef/eclipse4-smartsave

The plugin implement a function that intelligently saves files when editor loses focus.
I will investigate for an alternative solution.
Gregorio
Previous Topic:Graphical Modeling Framework/Tips
Next Topic:How to create an EReference programmatically?
Goto Forum:
  


Current Time: Fri Dec 15 14:20:51 GMT 2017

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

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