Bug 38829 - [EditorMgmt] closing editors as a side-effect of resource deletion
Summary: [EditorMgmt] closing editors as a side-effect of resource deletion
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.0 M2   Edit
Assignee: Simon Arsenault CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 38830 38863 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-12 08:22 EDT by John Vlissides CLA
Modified: 2003-06-16 10:44 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Vlissides CLA 2003-06-12 08:22:17 EDT
1. Create a simple Java project with two trivial classes, Class1
    and Class2.

 2. Open a Java editor on each class, ensuring that **Class2's**
    editor totally obscures **Class1's** (i.e., don't tile the
    editors).

 3. Shut down Eclipse and restart it. Things should look pretty
    much the same as before.

 4. Choose "New Window" from the Window menu.

 5. In the new window, delete Class1 using the Package Explorer.

 6. Go to the original window. You'll notice the editor for Class1
    is still there. Click on its tab. Kablooie.

Obscured editors aren't instantiated on startup---only when they're
revealed. The error comes from FileEditorInputFactory when it tries
to reload the editor's memento information: the memento's path
points to the now-deleted resource.
Comment 1 John Vlissides CLA 2003-06-12 08:25:28 EDT
*** Bug 38830 has been marked as a duplicate of this bug. ***
Comment 2 Debbie Wilson CLA 2003-06-12 09:21:43 EDT
You seem to have already done some digging on this problem.  Where exactly in 
FileEditorInputFactory is the problem - createElement?  What error message did 
you see?  Was there anything in the .log file?  Which build, exactly, were you 
using?
Comment 3 John Vlissides CLA 2003-06-12 10:25:29 EDT
> Where exactly in FileEditorInputFactory is the problem -
> createElement?

Right:

  public IAdaptable createElement(IMemento memento) {
    // Get the file name.
    String fileName = memento.getString(TAG_PATH);
    if (fileName == null)
      return null;

    // Create an IResource.
    IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path
(fileName));
    if (res instanceof IFile)
      return new FileEditorInput((IFile)res);
    else
      return null;
  }

"res" ends up being null because the file has been deleted at this point.

> What error message did you see?

An "Unable to Restore Editor" dialog containing:

   Unable to restore: Class1.java

   Reason":
     Unable to create editor: Class1.java.

> Was there anything in the .log file?  

Yes, but the stack trace isn't useful because the error is reported
asynchronously.

> Which build, exactly, were you using?

200303272130
Comment 4 Simon Arsenault CLA 2003-06-13 11:33:48 EDT
We should improve the message displayed to the user. We will not be able to 
restore the editor, so we can at least tell the user the real reason why - its 
because the file no longer exist.

Its not quite the same behavior as when the editor is restored before the file 
is deleted. In that case, the editor already has its content and be shown. Only 
on save do we warn the user the file is was deleted and has the option of 
saving under a new name (or the existing name to recreate the file).
Comment 5 John Vlissides CLA 2003-06-13 13:58:16 EDT
I'm not sure why you want to notify the user at all. You close visible editors 
silently; why not close obscured editors silently too?
Comment 6 Simon Arsenault CLA 2003-06-13 14:00:35 EDT
What do you mean that we close visible editors silently? Can you provide a 
scenario where that happens?
Comment 7 John Vlissides CLA 2003-06-13 14:12:26 EDT
An example lives in my original description of the problem: The editor of 
Class1 will close automatically when you delete Class.java. In fact, any editor 
of Class1, in any top-level view of the Eclipse workbench, will close silently--
-that is, iff it has been restored.  If not, then you get the dreaded error 
dialog.
Comment 8 Simon Arsenault CLA 2003-06-13 14:38:21 EDT
Changed the FileEditorInputFactory to return a handle to an IFile instead of 
actually checking for the existance of an IFile. The editor then can handle the 
case of a file handle to a resource that does not exist in the workspace 
anymore.

With this fix, the Java editor will come to the top, and display in its text 
area that the file <file name> does not exist. The user can then close the 
editor.

As for your previous comment, you'll need to open a bug report against 
Platform - Text. The workbench makes no attempt to close editors when resources 
are deleted. The text editor (which the Java editor is based on) must do this 
on its own.
Comment 9 Debbie Wilson CLA 2003-06-16 10:44:43 EDT
*** Bug 38863 has been marked as a duplicate of this bug. ***