Bug 193324 - [Sync View] Provide compare editor input for a single file that support editing on both sides
Summary: [Sync View] Provide compare editor input for a single file that support editi...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Team (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement with 1 vote (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Tomasz Zarna CLA
QA Contact:
URL:
Whiteboard: hasPatch
Keywords:
Depends on:
Blocks: 125830 157849 193321 207939
  Show dependency tree
 
Reported: 2007-06-19 10:38 EDT by Michael Valenta CLA
Modified: 2011-10-10 08:24 EDT (History)
4 users (show)

See Also:


Attachments
Patch at initial stage (12.11 KB, patch)
2007-06-20 08:11 EDT, Tomasz Zarna CLA
no flags Details | Diff
mylar/context/zip (10.85 KB, application/octet-stream)
2007-06-20 08:11 EDT, Tomasz Zarna CLA
no flags Details
Patch v2 (21.46 KB, patch)
2007-06-26 13:05 EDT, Tomasz Zarna CLA
no flags Details | Diff
Patch v3 (48.96 KB, patch)
2007-07-17 06:24 EDT, Tomasz Zarna CLA
no flags Details | Diff
Manual test proposition (3.31 KB, patch)
2007-07-25 08:48 EDT, Tomasz Zarna CLA
no flags Details | Diff
Automated test draft (5.25 KB, patch)
2007-07-31 11:54 EDT, Tomasz Zarna CLA
no flags Details | Diff
The second part of the manual tests (4.61 KB, patch)
2007-08-28 08:17 EDT, Tomasz Zarna CLA
no flags Details | Diff
Patch v4 (55.30 KB, patch)
2008-11-20 11:11 EST, Tomasz Zarna CLA
no flags Details | Diff
mylyn/context/zip (75.54 KB, application/octet-stream)
2008-11-20 11:11 EST, Tomasz Zarna CLA
no flags Details
Patch v05 (36.88 KB, patch)
2008-11-27 06:34 EST, Szymon Brandys CLA
no flags Details | Diff
Patch v06 (37.08 KB, patch)
2008-11-27 11:18 EST, Tomasz Zarna CLA
no flags Details | Diff
mylyn/context/zip (27.49 KB, application/octet-stream)
2008-11-27 11:18 EST, Tomasz Zarna CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Valenta CLA 2007-06-19 10:38:13 EDT
In order to address bug 193321, we need a compare editor input for a single file that supports editing on both sides. Team provides a SaveableCompareEditorInput that supports editing on the left. We either need to modify the class to support editing on both sides or create a new class (which could possibly share a super class with SaveableCompareEditorInput ) that provides this funtionality.
Comment 1 Michael Valenta CLA 2007-06-19 10:47:30 EDT
The first things you will want to do is create an object contribution in Team that overrides the Compare with Each Other that is provided by Compare (since the SaveableCompareEditorInput is provided by Team/UI). Have a look at the Compare with Local History action in the org.eclipse.team.ui plugin.xml to see how this is done for the local history action.
Comment 2 Michael Valenta CLA 2007-06-19 11:11:47 EDT
I've created a wiki page that describes a bit about SaveableCompareEditorInput and some other topics related to CompareEditorInputs.

http://wiki.eclipse.org/index.php/Compare
Comment 3 Tomasz Zarna CLA 2007-06-20 08:11:14 EDT
Created attachment 71868 [details]
Patch at initial stage

I've overridden the Compare w/ Each Other action from Compare with an action from Team/UI. I called it org.eclipse.team.internal.ui.actions.CompareAction. The new action creates a compare editor using org.eclipse.team.internal.ui.synchronize.TwoSidesSaveableCompareEditorInput, which is a new class I introduced. It extends SaveableCompareEditorInput and supports comparing and editing on both sides of the editor. It's intended to work only for selection of 2 local files.

I indicated all methods copied from other classes, so you can review the code quicker :). Stars mean that a method was slightly modified. The code is not final, especially all the "doSomethingWithLeft/Right" methods. However, I belive it's better to show it to you at this moment than wait :)

I would be glad to hear any comments from you Michael.
Comment 4 Tomasz Zarna CLA 2007-06-20 08:11:16 EDT
Created attachment 71869 [details]
mylar/context/zip
Comment 5 Michael Valenta CLA 2007-06-20 14:55:41 EDT
This is a good start. Here are some comments:

 - There's a copy/past error in TwoSidesSaveableCompareEditorInput#getRightResource() where is says "if (left instancof..."
 - You have getRightLocalElement() and getLeftLocalElement() that cast the right and left to LocalResourceTypeElement but they are only used by a method that then casts to IResourceProvider. You also have two copies of getLeftResource and getRightResource: one with a parameter and one without.
 - The save behavior and dirty flag don't work properly but this is because you haven't cretaed a second savable for the input.
 
The biggest issue that remains is treating both files a separate Saveables. The SaveableCompareEditorInput is really tailored to only have a singel saveable (for now, think of a Saveable is a special wrapper around a file). For this enhancement, we need to treat each side as a Saveable (i.e. the input will need to have two saveables: one for the left and one for the right). You are going to need to generalize the SaveableCompareEditorInput so that it supports two saveables as well as one. A few places that are hardcoded to accept only one saveable:

- InternalResourceSaveableComparison inner class
- registerContextMenu/handleMenuAboutToShow
- isDirty
- findContentViewer
- getActiveSaveables
- contentsCreated/handleDispose

I'll leave it up to you to decide whether you can generalize the current class or whether you need to create a common superclass (e.g. AbstractSaveableCompareEditorInput). Also keep in mind that any changes you make must be backwards compatible since SaveableCompareEditorInput is API.
 
Comment 6 Tomasz Zarna CLA 2007-06-26 13:05:28 EDT
Created attachment 72494 [details]
Patch v2

Here is the patch addressing your comments Michael. Once again, I've started with subclassing SaveableCompareEditorInput, but this is just for now. When done, I will decide to one of your suggestions from the previous comment. At this moment, I'm working on making the inputChanged event to be fired only once, after both sides are saved.
Comment 7 Tomasz Zarna CLA 2007-06-26 13:10:03 EDT
One more thing, I didn't touch registerContextMenu/handleMenuAboutToShow, so please don't look for any changes in this area. I hope they are not obligatory at this stage.
Comment 8 Michael Valenta CLA 2007-06-28 16:12:30 EDT
The latest patch is going in the right direction. Here are some comments:

- In the contentsCreated method, you assign two listeners to the same instance variable. This may cause memory to be leaked in the dispose.
- In your createLeftSaveable/createRightSaveable, I think the elements could be null so you would need to accommodate this.
- As you mentioned before, there is a warning prompt when saving both sides that we need to fix. I had a quick look and one problem is that the LocalResourceSaveableComparison#performSave method (for one side) calls CompareEditorInput#flushViewers which triggers the save on the other side. I would suggest we leave this issue to the end.

After you address the first two issues above, I would go ahead with the refactoring you mentioned (i.e. common super class) and we can then go from there.
Comment 9 Tomasz Zarna CLA 2007-07-17 06:24:47 EDT
Created attachment 73935 [details]
Patch v3

 Here is a patch addressing your comments and issues mentioned above. The biggest change is the common super class (named AbstractSaveableCompareInput). I made both SaveableCompareEditorInput (which is still abstract) and TwoSidesSavebaleCompareEditorInput to extend the new abstract class. I pulled up as many methods as possible, some of them had it's access modifier changed. In order to make the number of inherited methods bigger I changed signatures of:
  
1) getFileElement method : first parameter ICompareInput -> ITypedElement
2) handleMenuAboutToShow method : added ITypedElement parameter
3) constructor of InternalResourceSaveableComparison : ITypedElement parameter added
 
 The last thing is an answer to your comment:
 > In your createLeftSaveable/createRightSaveable, I think the elements could be null so you would need to accommodate this.
 The null element is handled the same way as in SaveableCompareEditorInput (i.e. even when an element is null it's passed anyway). If you still think that the elements need an extra check I will add it.
Comment 10 Michael Valenta CLA 2007-07-17 11:42:06 EDT
I've released your patch to branch bug_193324. I changes some of the method you made protected to package private since it's not clear that clients need to access them (especially for the instance variables since I like to keep those private if at all possible). I like to be conservative when providing API. 

I think what we need to do now is develop a manual test plan and put it with the others in the CVS/Test plug-in. We can then use this to drive the final tweaking of the patch. If you can think of some automated tests, that woudl be good too.
Comment 11 Tomasz Zarna CLA 2007-07-25 08:48:24 EDT
Created attachment 74552 [details]
Manual test proposition

This is a proposition of the manul test for Compare with each other action. The patch is created based on the HEAD version of the project.
Comment 12 Michael Valenta CLA 2007-07-25 09:49:08 EDT
I've committed the manual tests to HEAD.
Comment 13 Tomasz Zarna CLA 2007-07-31 11:54:14 EDT
Created attachment 75050 [details]
Automated test draft

This is a very rough, first version of JUnit tests for the bug. I decided to show it do you guys, so can comment on it. It would be great to know if the piece of code I wrote is worth anything. Please, feel free to comment, I'm opened to any criticism.
Comment 14 Tomasz Zarna CLA 2007-08-28 08:17:01 EDT
Created attachment 77123 [details]
The second part of the manual tests

The patch is created based on the HEAD version of the project. 

According the the first part of the manual tests I should add an option to use the Common Ancestor. Basing on the previous patches and comments do you think it's the right moment?
Comment 15 Michael Valenta CLA 2007-09-05 15:29:11 EDT
I've released the update to the manual tests to HEAD. I have not released the automated tests yet. In answer to your question, yes, I think it would be good to add the ancestor selection logic so we can test both the 2-way and three-way cases. I think it would be good to have some automated tests for the three-way case as well.
Comment 16 Tomasz Zarna CLA 2008-04-16 10:45:15 EDT
Postponing to 3.5.
Comment 17 Tomasz Zarna CLA 2008-11-20 11:11:43 EST
Created attachment 118372 [details]
Patch v4

Added 3-way comparison (selecting an ancestor using the same looking dialog as for ResourceCompareEditorInput). Further pulling up methods from both Saveable* and Saveables* inputs to AbstractSaveable* class. There is still an issue with registering a saveable which has been already added to the SaveableList (it's a warning but it shouldn't happen).

This fix improves the experience while working with the patch for bug 250633.
Comment 18 Tomasz Zarna CLA 2008-11-20 11:11:51 EST
Created attachment 118373 [details]
mylyn/context/zip
Comment 19 Szymon Brandys CLA 2008-11-27 06:34:39 EST
Created attachment 118899 [details]
Patch v05
Comment 20 Tomasz Zarna CLA 2008-11-27 11:18:30 EST
Created attachment 118928 [details]
Patch v06

Szymon's patch with some minor changes: getTooltip/getTitle methods, comments.
Comment 21 Tomasz Zarna CLA 2008-11-27 11:18:34 EST
Created attachment 118929 [details]
mylyn/context/zip
Comment 22 Tomasz Zarna CLA 2008-11-27 11:32:04 EST
Released to HEAD but logged bug 256805 and bug 256806. Thanks for helping me with the patch Szymon.
Comment 23 G M Kallidis CLA 2011-10-06 05:24:10 EDT
In Eclipse Version: 3.7.0
Build id: I20110613-1736

I could not save changes in the right and left panel compareto editor, if I edit two files (after selecting in compareto->each other dialog) CHANGING BOTH. If I change only one, this is successfull, but if I am changing both and the try to save (by clicking the multiple or the single save button) changes are ALWAYS LOST on the RIGHT side (focusing on the right does not change this).

Hint: I could not find the class org/eclipse/team/internal/ui/synchronize/TwoSidesSaveableCompareEditorInput.java mentioned above in org.eclipse.team.ui_3.6.100.I20110525-0800.jar...??
Comment 24 Tomasz Zarna CLA 2011-10-10 08:24:18 EDT
(In reply to comment #23)
> I could not save changes in the right and left panel compareto editor, if I edit
> two files (after selecting in compareto->each other dialog) CHANGING BOTH. If I
> change only one, this is successfull, but if I am changing both and the try to
> save (by clicking the multiple or the single save button) changes are ALWAYS
> LOST on the RIGHT side (focusing on the right does not change this).

Good catch, entered bug 360429 for the issue.

> Hint: I could not find the class
> org/eclipse/team/internal/ui/synchronize/TwoSidesSaveableCompareEditorInput.java
> mentioned above in org.eclipse.team.ui_3.6.100.I20110525-0800.jar...??

Not sure what happened to said class, I guess it has been renamed to SaveablesCompareEditorInput. This is the place where I would start looking for the culprit.