Bug 116247 - AbstractDocumentProvider allows Save as to a document that already opened
Summary: AbstractDocumentProvider allows Save as to a document that already opened
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal
Target Milestone: ---   Edit
Assignee: Tom Macdougall CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 116081 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-14 10:36 EST by Mohamed Badr CLA
Modified: 2010-07-19 12:27 EDT (History)
0 users

See Also:


Attachments
patch for Resource Editor IDE plugin for SaveAs issue (10.44 KB, patch)
2005-11-21 11:42 EST, Tom Macdougall CLA
no flags Details | Diff
patch for Resource Editor plugin for SaveAs issue (1.68 KB, patch)
2005-11-21 11:45 EST, Tom Macdougall CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mohamed Badr CLA 2005-11-14 10:36:12 EST
Breif description to the problem, if you have two documents opened (both are 
dirty). Try to save as one of the documents, with the same name of the other 
one, this will lead to having two different opened documnet for the same file 
(each has different contents) which will cause confusion and errors.

I investigated the problem found that in 
AbstractDocumentProvider::saveDocument, it try to save without checking if 
this new document is already opened or not. 


I added the following check to saveDocument which fix the problem.

Object obj=null;
String newPath = element.toString();
String filePath = null;

for (Iterator i = getConnectedElements();i.hasNext();) {
  obj = i.next();
  filePath = obj.toString();
  if (filePath.equals(newPath)) {
    IDocument info= getDocument(obj);
    if (info != document) {
      Status status= new Status(IStatus.WARNING, EditorPlugin.getPluginId(),   
IStatus.ERROR, EditorMessages.Editor_error_saveAsTargetOpenInEditor, null);
      throw new CoreException(status);
   }
}

Note, in this code, I just used string comparison which is not a bright 
solution. the submitter should do a better check if they are equal.
Note 2, unfortunatily I couldn't construct the map key from the file path 
which might have saved the loop. I don't think it's doable, though it worth a 
look.
Comment 1 Tom Macdougall CLA 2005-11-21 11:42:44 EST
Created attachment 30319 [details]
patch for Resource Editor IDE plugin for SaveAs issue

Added subclass DiagramDocumentEditorIDE of DiagramDocumentEditor that contains an enhanced performSaveAs method. This method now includes a check if save target file is already open. The FileDiagramEditor class now inherits DiagramDocumentEditorIDE and logic diagrams will no longer be allowed to save to a file that is currently opened.
Comment 2 Tom Macdougall CLA 2005-11-21 11:45:17 EST
Created attachment 30320 [details]
patch for Resource Editor plugin for SaveAs issue
Comment 3 Tom Macdougall CLA 2005-11-21 11:55:56 EST
Committed the code
Comment 4 Tom Macdougall CLA 2005-11-21 12:06:08 EST
*** Bug 116081 has been marked as a duplicate of this bug. ***
Comment 5 Tom Macdougall CLA 2005-11-22 10:56:50 EST
Renamed DiagramDocumentEditorIDE to IDEDiagramDocumentEditor to be consistent with the IDE naming convention.
Comment 6 Eclipse Webmaster CLA 2010-07-19 12:27:28 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime Diagram was the original product and component for this bug