Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345274 - diagram.xmi is modified when editor opens
Summary: diagram.xmi is modified when editor opens
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: Diagram Editor (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: Petya Sabeva CLA
QA Contact: Stefan Dimov CLA
URL:
Whiteboard: PMC_approved
Keywords:
Depends on:
Blocks: 339900
  Show dependency tree
 
Reported: 2011-05-10 10:15 EDT by Petya Sabeva CLA
Modified: 2011-05-23 19:28 EDT (History)
5 users (show)

See Also:
david_williams: pmc_approved+
stefan.dimov: pmc_approved? (raghunathan.srinivasan)
stefan.dimov: pmc_approved? (naci.dai)
stefan.dimov: pmc_approved? (deboer)
stefan.dimov: pmc_approved? (neil.hauge)
stefan.dimov: pmc_approved? (kaloyan)
stefan.dimov: pmc_approved? (cbridgha)
stefan.dimov: review+
neil.hauge: review+


Attachments
proposed patch (15.66 KB, patch)
2011-05-10 10:17 EDT, Petya Sabeva CLA
no flags Details | Diff
Patch proposal (15.92 KB, text/plain)
2011-05-12 11:00 EDT, Petya Sabeva CLA
no flags Details
patch proposal (16.11 KB, patch)
2011-05-12 11:14 EDT, Petya Sabeva CLA
no flags Details | Diff
patch proposal (17.06 KB, patch)
2011-05-13 04:35 EDT, Petya Sabeva CLA
no flags Details | Diff
Read entity coordinates from ini file (19.46 KB, patch)
2011-05-13 07:51 EDT, Stefan Dimov CLA
no flags Details | Diff
read entity coordinates from xml file (34.78 KB, patch)
2011-05-19 06:59 EDT, Petya Sabeva CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petya Sabeva CLA 2011-05-10 10:15:50 EDT
When you open the JPA Diagram Editor for the first time while you are using some versioning control system like CVS, GIT, SVN ect. the diagram.xmi is marked as changed.

The solution that we made was to move the diagram.xmi to the project's 
.metadata folder on the file system and to use simple diagram.ini file to store the necessary data for the diagram editor such as: entity name and its coordnates on the diagram. This .ini file will be saved only when the editor is saved...
Comment 1 Petya Sabeva CLA 2011-05-10 10:17:17 EDT
Created attachment 195219 [details]
proposed patch
Comment 2 Stefan Dimov CLA 2011-05-10 14:01:42 EDT
Neil, does it make sense to propose this one for PMC review? Do you think it's important enough?
Comment 3 Neil Hauge CLA 2011-05-10 14:15:54 EDT
Changing the metadata in this way right before the release seems like a very
big change to be making at this point, and I would think carries a decent
amount of risk.  That said, it is good when these types of changes are resolved
before they are released so that the metadata doesn't end up changing from
release to release.

What is the real impact of the bug on users if the bug is not fixed?
Comment 4 Stefan Dimov CLA 2011-05-11 04:40:21 EDT
Every time when the user opens a saved diagram, the corresponding xmi file is being changed even though the user didn't make any changes in the diagram. It's a behavior dictated by the Graphiti framework. When the user keeps the xmi file in some versioning control system along with the JPA project and when she checks out the project and opens the diagram, the xmi file is being changed and shown as different from the one in the version control system. 

The solution we've found is to keep the xmi file in the preference store. This file is needed only while the diagram stays open. We don't need it to restore the diagram when it opens, so we don't need to be kept in the VC system. Although, we still need some small part of the info saved in it to restore the diagram. The info we need is just the names of the visualized entities and their coordinates in the diagram. With this fix when the diagram closes we save the necessary info in a simple ini file. This file is part of the JPA project and could be kept in the VC system without the annoying deffect described here.

The change became bigger than we expected and maybe it's too risky to submit it before the release.
Comment 5 Neil Hauge CLA 2011-05-11 10:53:12 EDT
I asked David Williams for his thoughts on this issue and he was of the general opinion that it would be worth it to try and fix this now to avoid later changes in metadata, and based on the severity of the problem.  I've cc'd him so he could add any comments regarding that opinion.

I suppose the main question now is how confident you are in the proposed solution.  It will be time consuming to make changes to this metadata format after the release so it is important to try and get this right the first time.  If you are confident in the changes and the new format then I am prepared to approve and send up for PMC review.  In general David and I both agree that it is an important bug to fix, but we want to be careful to get the right solution.

Please fill out the questionnaire when you are ready to submit for PMC approval.
Comment 6 Stefan Dimov CLA 2011-05-11 11:14:29 EDT
I still haven't had the time to test it, but tomorrow or at friday I will be ready to answer your question
Comment 7 Stefan Dimov CLA 2011-05-12 09:20:21 EDT
Found a glitch:

1. Create JPA project and diagram
2. Close the diagram
3. Delete diagram ini file from the project explorer
4. Open the diagram again

Result: The diagram appears as it was saved the last time. It should be empty instead of this.

Otherwise, the patch seems ok.

P.S.: Please, remove all the validation warnings before submitting the new version
Comment 8 Petya Sabeva CLA 2011-05-12 11:00:57 EDT
Created attachment 195500 [details]
Patch proposal

Please try this one. It should cover this case...
Comment 9 Petya Sabeva CLA 2011-05-12 11:14:28 EDT
Created attachment 195502 [details]
patch proposal

Previous patch did not work, but this one should work fine...
Comment 10 Petya Sabeva CLA 2011-05-13 04:35:47 EDT
Created attachment 195564 [details]
patch proposal

The previous patch became incompatible with the HEAD after the patch from https://bugs.eclipse.org/bugs/show_bug.cgi?id=338960 was being commited...
Comment 11 Stefan Dimov CLA 2011-05-13 07:51:15 EDT
Created attachment 195584 [details]
Read entity coordinates from ini file

New version - the patch is ok with just a glitch in it.
Comment 12 Stefan Dimov CLA 2011-05-13 08:12:11 EDT
This is an important fix, for every JPA developer which uses some kind of version control system, that's why it needs to get into Indigo.

The workaround is not to submit the diagram file when the diagram was not change, but anyway it's still confusing for the user.

The diagram xmi file is no longer in the project - it's in the preference store. Instead of it there is a an ini file in the 'diagrams' folder of the project.

The fix was tested manually. I've checked all the possible scenarios including the one with the old style - if the user has a diagram and opens it in IDE with this fix, the editor will open the diagram and when saved the xmi file will disappear from the project and get to the prefs store. Instead of it a new ini file will appear. All the existing JUnit tests are passing successfully.

There is more detailed description of the problem and the solution in comment #4. I've reviewed the fix and it's ok. 

The risk is low.
Comment 13 Neil Hauge CLA 2011-05-13 10:00:07 EDT
I think bug will be headed for RC2 at this point.
Comment 14 Stefan Dimov CLA 2011-05-13 10:31:20 EDT
ok
Comment 15 David Williams CLA 2011-05-15 01:28:52 EDT
I'm all in favor of fixing this for Indigo, since, as you say, it's really bad to change "shared files" if they really should not be shared. But, I couldn't apply the patch, so hard for me to look at code very closely. 

The reason I was going to look at it closely was because from glancing at the patch, it seems that every method is "public". Even ones like getIniFile(). Normally that's something you wouldn't want to expose to the world, but to keep it private, or at least package protected ... if possible, and I don't know if its possible since I can't really see the code in context. I also found it odd that getIniFile was a static method ... guess I don't know that its for. 

Another technical comment, I noticed statements such as 

File newXMIFile = new File(newXMIFilePath.toOSString());
 
which implies to me you are using "raw" java methods, instead of Eclipse's API for preferences or metadata. Is that common? Seems there's some potential to be restrictive ... such as if/when people start to use a "lined resource" for their project, or some other type of of (future) indirection. 

So, don't get me wrong ... it's probably all fine, and good reasons for everything ... just making some comments based on casual scan of the patch file. Can't say I know (easily) the "right" way to do anything ... just making observations. 

Does seem fair for me to ask for a patch I could apply, though ... but, maybe others can apply it? Maybe its just my workspace? (in which case, no big deal). 

Thanks for catching/fixing this before Indigo.
Comment 16 David Williams CLA 2011-05-15 01:30:48 EDT
Sorry for typo, in above comment, where I said "lined resource" I mean "linked resource".
Comment 17 Petya Sabeva CLA 2011-05-17 12:13:14 EDT
Yes David, you are right that most of the methods shouldn't be "public"... According to getIniFile() - it is invoked by several other classes which are in different packages and is marked as static because of the "iniFile" field, which is static since it is called by another static method from the same class... Actually all methods in the ModelIntegrationUtil.class are static, but I will remove it since I'm trying to refactor the patch in a way to use IFileStore instead of java.io.File. 
So what do you think, will be fine, if I am using this appraoch?
Comment 18 David Williams CLA 2011-05-17 13:24:04 EDT
(In reply to comment #17)
> ... since I'm trying to refactor the patch in a way to use
> IFileStore instead of java.io.File. 
> So what do you think, will be fine, if I am using this appraoch?

yes, does sound probably ok ... but, be warned :) ... I'm not saying I know what the right design is ... just making observations. (Such, as, I'm do not know if IFileStore can be used in a ".metadata" location ... as far as I know, that's usually done with "preference" APIs ... but, I emphasize, I do not know (I'd need to study up, to refresh my memory). 

Doubt if there's time for you to do too much studying, but seems this problem would have been solved before, and perhaps some good patterns used, such as VE, WindowBuider, or similar "visual designers". Of course, they might have used bad patterns too :) hard to know. 

I think fine if you focus on main issue of "getting out of source control" and can always improve in later releases ... and the more "private" you can make the methods, the easier it will be to change in later releases :) 

But, overall, important work. Thanks for the careful effort.
Comment 19 Petya Sabeva CLA 2011-05-19 06:59:25 EDT
Created attachment 196100 [details]
read entity coordinates from xml file

Ok, so in this patch I was trying to reduce the use of java.io.File, the existing .xmi file is moved to the .metadata on the filesystem (i was getting the .metadata location in this way: JPADiagramEditorPlugin.getDefault().getStateLocation()) and the necessary entities' coordinates are stored and read in a xml format in a new .xml file instead of .ini file...
Comment 20 Tran Le CLA 2011-05-19 15:33:47 EDT
Patch committed in RC2