Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343002

Summary: when invoking "IDE.saveAllEditors(...)" on CM operations, choosing discard fails to refresh dirty editors.
Product: [Eclipse Project] Platform Reporter: John P. Petrakis <jpetrakis>
Component: IDEAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, prakash
Version: 3.4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
png showing saveAllEditor popup for single selection... none

Description John P. Petrakis CLA 2011-04-15 13:04:48 EDT
Build Identifier: M20110210-1200

The ClearCase plug-in preserves modification time on checkout.  In CC snapshot vies this is not an issue because undo-checkout reloads the file and the time stamp is updated and you are prompted to refresh the editor.  In the dynamic view type however, the upon undo-checkout the timestamp is not modified.  If there has never been a save to the file, the time stamp will never change so the editor is never prompted to reload.  The plug-in currently does not call saveAllEditors for undo-checkout... but I've modified the code to use saveAllEditors and the choice of discard won't refresh the editors.

Invoking saveAllEditors (if you chose SAVE) will force the update to the file time stamp, but discard will not because the file is never saved.  If saveAllEditors can save the dirty editors, why can it not revert the dirty editors if a user chooses "discard changes"?   Who would expect to have to save the editor changes so that you can throw them away on an undo checkout?

Reproducible: Always

Steps to Reproduce:
0. in a clearcase environment:
1. check out a file
2. dirty the editor but do not save
3. undo the checkout - editor never refreshes.
Comment 1 John P. Petrakis CLA 2011-04-15 13:06:09 EDT
By the way, I've tried this using eclipse distributions back to 3.4.0 with the same results.
Comment 2 Prakash Rangaraj CLA 2011-04-18 01:30:22 EDT
Is there a way I can reproduce this one without clearcase?
Comment 3 Dani Megert CLA 2011-04-18 05:00:50 EDT
What ClearCase plug-in / Team provider do you use? This is responsible to handle those cases.

>3. undo the checkout - editor never refreshes.
How exactly do you do this?
Comment 4 John P. Petrakis CLA 2011-04-18 08:28:06 EDT
This is the ClearCase SCM Adapter.  saveAllEditors can save them but it cannot discard when the user clicks "discard"??? Reverting editors would require knowledge of the type of editor... and in fact, things like "doRevertToLastSaved" only seems to be available in the ITextEditor implementation.  Other editors such as the manifest editor, are *internal* classes which I cannot access.  There is no provision in the IEditorPart interface for such a reversion... this functionality seems to be hidden in the implementation.  The only clean way appears to handle this is in saveAllEditors.  Calling this prior to the CM operation would be the only way to properly handle this it would seem.  I cannot access (for example) the xtools editor classes without resorting to reflection since eclipse and desktop product both must be supported.
Comment 5 Dani Megert CLA 2011-04-18 08:53:10 EDT
>>3. undo the checkout - editor never refreshes.
How exactly do you undo the check out? The SDK does not offer this. Is the main purpose of this bug to make the ClearCase undo feature work?

Couldn't you store the relevant information so that you can later refresh the dirty editors in your implementation of org.eclipse.core.commands.operations.IUndoableOperation.undo(IProgressMonitor, IAdaptable)? Using saveAll should be the last resort as it also saves potentially unrelated files.

>This is the ClearCase SCM Adapter.  saveAllEditors can save them but it cannot
>discard when the user clicks "discard"??? 
I'm not sure what "discard" you mean exactly. Out of the box there is no dialog when 'Save All' is invoked and AFAIK there is only a "prompt" option on the saveAll API.
Comment 6 John P. Petrakis CLA 2011-04-18 10:33:12 EDT
When I invoke savveAllEditors with confirm = true, I get a three-button popup, with "save", "discard", and "cancel".  I *have* the list of IResource objects that will be "uncheckedout"  I have tried to use this specific method:

public static boolean saveAllEditors(final IResource[] resourceRoots,
			final boolean confirm) 

Does this  *not* limit the action of the save to the list of IResources involved in the cm operation?

Save does the save... and cleans up the dirtyness of the editors.  Discard does not.  It seems to me it should.
Comment 7 Dani Megert CLA 2011-04-18 10:52:58 EDT
(In reply to comment #6)
> When I invoke savveAllEditors with confirm = true, I get a three-button popup,
> with "save", "discard", and "cancel".  
Mmh. I really don't think there is a 'Discard' button on it. Can you attach a screen shot of the dialog you're seeing?


> I *have* the list of IResource objects that will be "uncheckedout" 
> I have tried to use this specific method:
> 
> public static boolean saveAllEditors(final IResource[] resourceRoots,
>             final boolean confirm) 
> 
> Does this  *not* limit the action of the save to the list of IResources
> involved in the cm operation?
There are several saveAllEditors APIs. This one indeed knows what it saves, so you're fine here.
Comment 8 John P. Petrakis CLA 2011-04-18 11:19:04 EDT
Created attachment 193494 [details]
png showing saveAllEditor popup for single selection...
Comment 9 John P. Petrakis CLA 2011-04-18 11:21:35 EDT
Ok... so it isn't discard, but "No"... but the question is: "Save selection?".  If I say no it means no... perhaps I'm seeing this wrong?  However if you multiple select, you get a different kind of popup with checkboxes and a TWO button choice.  If I deselect one or more of the items in THAT case I would not necessarily expect a reversion.
Comment 10 Dani Megert CLA 2011-04-18 11:49:03 EDT
(In reply to comment #9)
> Ok... so it isn't discard, but "No"... but the question is: "Save selection?". 
> If I say no it means no... perhaps I'm seeing this wrong?
I think so: you simply say "no" to saving one of the dirty editors when performing 'Save All'. What you are looking for is an additional mode or API where one can specify to not only save but also revert the editor instead of saving. This however, will be hard to introduce after the fact: as you already noted there is no API on IEditorPart to request such a behavior from the editor.
Comment 11 Oleg Besedin CLA 2011-05-24 15:42:52 EDT
(In reply to comment #10)
> What you are looking for is an additional mode or API
> where one can specify to not only save but also revert the editor instead of
> saving. This however, will be hard to introduce after the fact: as you already
> noted there is no API on IEditorPart to request such a behavior from the
> editor.

Which does not sound like a practical enhancement. As always, please feel free to reopen, especially if there is a patch.
Comment 12 John P. Petrakis CLA 2011-06-07 15:06:07 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > Ok... so it isn't discard, but "No"... but the question is: "Save selection?". 
> > If I say no it means no... perhaps I'm seeing this wrong?
> I think so: you simply say "no" to saving one of the dirty editors when
> performing 'Save All'. What you are looking for is an additional mode or API
> where one can specify to not only save but also revert the editor instead of
> saving. This however, will be hard to introduce after the fact: as you already
> noted there is no API on IEditorPart to request such a behavior from the
> editor.

That's fine... *I* wouldn't have to do it explicitly if a "No" response to to the save would actually discarded changes when it asked: "do you want to save the changes"
Comment 13 Dani Megert CLA 2011-06-08 05:04:10 EDT
> That's fine... *I* wouldn't have to do it explicitly if a "No" response to to
> the save would actually discarded changes when it asked: "do you want to save
> the changes"

The operation is 'Save' and not 'SaveOrDiscard'. The only thing you can choose is whether to save or not and that is the expected behavior.