Bug 38770 - CompareEditor should implement IReusableEditor
Summary: CompareEditor should implement IReusableEditor
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M3   Edit
Assignee: Andre Weinand CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-11 09:29 EDT by Jean-Michel Lemieux CLA
Modified: 2003-08-25 12:42 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Michel Lemieux CLA 2003-06-11 09:29:52 EDT
3.0 M1
We are rewritting the sync view and are using compare editors instead of
embedding the text merge views into the view. I've implemented editor re-use so
that you can browse changes and re-use non-dirty editors. The compare editor
doesn't implement IReusableEditor hence I have to close a compare editor an open
another to support the reuse case. A better solution would be to simply call
CompareEditor.setInput.

Dirty compare editors are kept open until saved.
Comment 1 Andre Weinand CLA 2003-06-23 09:35:04 EDT
IReusableEditor implemented for I20030624
Comment 2 Jean-Michel Lemieux CLA 2003-06-27 09:22:30 EDT
20030625
I tried calling setInput and the open compare editor went blank and the new
input was not shown. This is the code that re-uses the editor:

private void openEditor() {
 CompareEditorInput input = getCompareInput();
 if(input != null) { 
  IEditorPart editor = reuseCompareEditor((SyncInfoCompareInput)input);
   if(editor != null && editor instanceof IReusableEditor) {
    ((IReusableEditor)editor).setInput(input);
   } else {
    CompareUI.openCompareEditor(input);
   }
 }		
}
Comment 3 Andre Weinand CLA 2003-07-14 13:23:26 EDT
I tried to reproduce the problem by using your code in the implementation of
CompareUI.openCompareEditor as follows:

public void openCompareEditor(CompareEditorInput input, IWorkbenchPage page) {
  if (compareResultOK(input)) {
    if (page == null)
       page= getActivePage();
    if (page != null) {
      if (CompareEditor.fgCurrentCompareEditor instanceof IReusableEditor) {
        IReusableEditor e= (IReusableEditor) CompareEditor.fgCurrentCompareEditor;
        e.setInput(input);
      } else {
        try {
          page.openEditor(input, COMPARE_EDITOR);
        } catch (PartInitException e) {
          MessageDialog.openError(getShell(), Utilities.getString("CompareUIPlugin.openEditorError"), 
e.getMessage()); //$NON-NLS-1$
        }					
      }
    } else {
      MessageDialog.openError(getShell(),
		Utilities.getString("CompareUIPlugin.openEditorError"), //$NON-NLS-1$
		Utilities.getString("CompareUIPlugin.noActiveWorkbenchPage")); //$NON-NLS-1$
	}
  }
}

But this worked for me both on Windows and on Mac OS X.
Will have to debug on the real plugin...
Comment 4 Andre Weinand CLA 2003-07-14 17:51:26 EDT
fix released for M2
Comment 5 Jean-Michel Lemieux CLA 2003-07-21 22:34:18 EDT
The interesting line in your code, that was missing from mine, is:
if(compareResultOK(input)) {
  ...
}

CompareResultOK() will end up running the prepareInput() in the progress monitor
and creating the actual input. If this method isn't called the input is never
*really* set in CompareEditor.setInput(). That was why it wasn't working with
the code I submitted.

How should a client of compare prime the input? Would it make sense to add a
openCompareEditor() method that would a boolean indicating re-use? Then running
the prepareInput would remain as is and clients won't have to figure out how to
prepare the input before calling CompareEditor.setInput().
Comment 6 Andre Weinand CLA 2003-08-25 12:42:11 EDT
released to HEAD for N20030826:

added new method to CompareUI:
     reuseCompareEditor(CompareEditorInput input, IReusableEditor editor)

A boolean arg to openCompareEditor wasn't sufficient because it wouldn't be clear what 
CompareEditor to reuse.