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

Bug 110684

Summary: [PresentationAPI] [RCP] [EditorMgmt] Workbench sometimes restores multiple empty editor folders
Product: [Eclipse Project] Platform Reporter: Boris Bokowski <bokowski>
Component: UIAssignee: Paul Webster <pwebster>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: balouin.c, daniel.stein, daniel_megert, ECOMAR, emoffatt, jean-michel_lemieux, jflicke, mole.moore, rafi.dar, remy.suen
Version: 3.2Keywords: helpwanted
Target Milestone: 3.7 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 372273    
Attachments:
Description Flags
screenshot
none
patch for IDEWorkbenchWindowAdvisor
pwebster: iplog+
patch for too many editor areas v02 none

Description Boris Bokowski CLA 2005-09-26 14:27:44 EDT
Steps:

Check out the adventurebuilder example, by expanding
platform-ui-home/jaoo/tutorial in the CVS repository explorer, selecting the
following plug-ins and then choosing "Check out" from the context menu.
org.eclipse.ui.examples.rcp.adventurebuilder.feature
org.eclipse.ui.examples.rcp.adventurebuilder.jnlp
org.eclipse.ui.examples.rcp.adventurebuilder.complete
org.eclipse.ui.examples.rcp.adventurebuilder
org.eclipse.ui.examples.rcp.adventurebuilder.axis
org.eclipse.ui.examples.rcp.adventurebuilder.model
org.eclipse.ui.examples.rcp.adventurebuilder.webservices

Start by opening /org.eclipse.ui.examples.rcp.adventurebuilder/Adventure
Builder.product and clicking on "Launch the product."

Expand nodes in the catalog and open two editors by double-clicking on adventure
names.

Put one editor below the other.

Close the application and restart.

Note that there are two empty editor areas (screenshot to follow).

Expected behaviour: just one editor area.
Comment 1 Boris Bokowski CLA 2005-09-26 14:28:08 EDT
Created attachment 27530 [details]
screenshot
Comment 2 Boris Bokowski CLA 2005-09-26 14:32:39 EDT
I found this in my log, I think it is related and happens when you open an
editor after you restart the application and start to drag it around.

!ENTRY org.eclipse.ui 4 0 2005-09-26 14:30:06.593
!MESSAGE -1
!STACK 0
java.lang.ArrayIndexOutOfBoundsException: -1
	at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.getItem(AbstractTabFolder.java:151)
	at
org.eclipse.ui.internal.presentations.util.ReplaceDragHandler.dragOver(ReplaceDragHandler.java:59)
	at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.dragOver(TabbedStackPresentation.java:398)
	at org.eclipse.ui.internal.PartStack.getDropTarget(PartStack.java:551)
	at org.eclipse.ui.internal.PartSashContainer.drag(PartSashContainer.java:986)
	at org.eclipse.ui.internal.dnd.DragUtil.getDropTarget(DragUtil.java:337)
	at org.eclipse.ui.internal.dnd.DragUtil.getDropTarget(DragUtil.java:360)
	at org.eclipse.ui.internal.dnd.DragUtil$2.run(DragUtil.java:216)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:152)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:28)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:3413)
	at org.eclipse.ui.internal.dnd.DragUtil$1.handleEvent(DragUtil.java:210)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:867)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:852)
	at org.eclipse.swt.widgets.Tracker.wmMouse(Tracker.java:1030)
	at org.eclipse.swt.widgets.Tracker.open(Tracker.java:509)
	at org.eclipse.ui.internal.dnd.DragUtil.dragToTarget(DragUtil.java:291)
	at org.eclipse.ui.internal.dnd.DragUtil.performDrag(DragUtil.java:123)
	at org.eclipse.ui.internal.PartStack.dragStart(PartStack.java:1368)
	at org.eclipse.ui.internal.PartStack$1.dragStart(PartStack.java:107)
	at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:111)
	at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:267)
	at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:280)
	at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.handleDragStarted(AbstractTabFolder.java:364)
	at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder$2.handleEvent(AbstractTabFolder.java:68)
	at
org.eclipse.ui.presentations.PresentationUtil.handleMouseMove(PresentationUtil.java:96)
	at org.eclipse.ui.presentations.PresentationUtil.access$4(PresentationUtil.java:89)
	at
org.eclipse.ui.presentations.PresentationUtil$2.handleEvent(PresentationUtil.java:61)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3080)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at org.eclipse.ui.examples.rcp.adventurebuilder.GoWild.run(GoWild.java:34)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
	at org.eclipse.core.launcher.Main.run(Main.java:973)
	at org.eclipse.core.launcher.Main.main(Main.java:948)
Comment 3 Eric Moffatt CLA 2007-09-11 15:05:18 EDT
*** Bug 74899 has been marked as a duplicate of this bug. ***
Comment 4 Paul Webster CLA 2008-03-05 10:52:20 EST
I suspect that this happens because we save the EditorStacks and save the editors ... on restore we restore the editor stacks but if the editor wasn't persistable they're not restored.

I'm not sure what's valid ... right now, we restore what was there.  The DND could be modified to accept the first editor in an empty editor area, but that might not be consistent with current DND (where dragging out the last editor closes the editor stack, right).

Another option would be have post-restore code that closes all editor stacks until there's only one empty one left or all stacks left have editors open in them.

Another option would be to try not to save editor stacks unless we can find at least one matching "part" that is also saved.

That being said, this is not on the plan for 3.4

PW
Comment 5 Edoardo Comar CLA 2010-09-29 12:24:49 EDT
A workaround is on startup to look for empty editor workbooks and remove them from the editor area.

this appears to work on 3.4.2:

WorkbenchPage activePage = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
EditorAreaHelper editorAreaHelper = activePage.getEditorPresentation();
EditorSashContainer editorSashContainer =  (EditorSashContainer) editorAreaHelper.getLayoutPart();

ArrayList workbooks = editorAreaHelper.getWorkbooks();
for (int i = 0; i < workbooks.size(); i++) {
   EditorStack editorStack = (EditorStack) workbooks.get(i);
   if(editorStack.getChildren().length==0) {
	editorSashContainer.remove(editorStack);
   }
}
Comment 6 Boris Bokowski CLA 2010-09-30 10:24:59 EDT
Edoardo, would you be able to contribute this as a patch (against the current 3.7 development stream)? See http://wiki.eclipse.org/Platform_UI/How_to_Contribute
Comment 7 Edoardo Comar CLA 2010-09-30 12:08:39 EDT
(In reply to comment #6)
> Edoardo, would you be able to contribute this as a patch (against the current
> 3.7 development stream)? See

Boris, yes I think so, but ... patch to what ?
I added that code to my RCP's 
WorkbenchWindowAdvisor.postWindowOpen()

would you want it added to the Eclipse SDK IDE's WorkbenchWindowAdvisor ?
Comment 8 Boris Bokowski CLA 2010-09-30 15:17:13 EDT
It should probably be in org.eclipse.ui.workbench, close to the place that calls postWindowOpen.
Comment 9 Edoardo Comar CLA 2010-10-01 06:09:49 EDT
(In reply to comment #8)
> It should probably be in org.eclipse.ui.workbench, close to the place that
> calls postWindowOpen.

Ok, will do a patch - cheers
Comment 10 Edoardo Comar CLA 2010-10-03 07:53:50 EDT
Created attachment 180115 [details]
patch for IDEWorkbenchWindowAdvisor
Comment 11 Edoardo Comar CLA 2010-10-03 07:57:36 EDT
I have attached a patch that I manually tested against one of the latest nightly 3.7 builds, following the approach of the duplicate bug:
Just opened two text editors off a CVS repository and dragged them side by side,
and restarted the SDK.
Without the patch you get two 'ghost' panes, with the patch all is good.

The code is maybe too defensive with redundant NPE checks, but hey that won't hurt performance as this method is invoked once per workbench window being opened.

Edoardo
Comment 12 Paul Webster CLA 2010-10-28 08:39:16 EDT
Sorry, I'll get this in M4
PW
Comment 13 Paul Webster CLA 2010-11-09 15:25:15 EST
Created attachment 182769 [details]
patch for too many editor areas v02

Make the behaviour a protected method in WorkbenchWindowAdvisor, and call it from IDEWorkbenchWindowAdvisor's postWindowRestore() method.
Comment 14 Paul Webster CLA 2010-11-09 15:26:11 EST
Edoardo, thanx for the patch.  Could you take a look at my revised patch and see that it still addresses your usecase?

Just a note, this will be an opt-in scenario, as a regular RCP app won't get this for free.

PW
Comment 15 Edoardo Comar CLA 2010-11-11 06:41:51 EST
(In reply to comment #14)
> Edoardo, thanx for the patch.  Could you take a look at my revised patch and
> see that it still addresses your usecase?
> 
> Just a note, this will be an opt-in scenario, as a regular RCP app won't get
> this for free.
> 
> PW

looks ok to me. I see the need for the explicit call.
Comment 16 Paul Webster CLA 2010-12-06 09:43:03 EST
Released for M4
PW
Comment 17 Paul Webster CLA 2010-12-07 13:49:49 EST
In I20101206-1800
PW
Comment 18 Prakash Rangaraj CLA 2011-03-08 03:00:40 EST
*** Bug 339032 has been marked as a duplicate of this bug. ***
Comment 19 Daniel Stein CLA 2011-11-03 03:02:54 EDT
*** Bug 362037 has been marked as a duplicate of this bug. ***
Comment 20 Markus Keller CLA 2011-12-02 10:52:36 EST
*** Bug 365382 has been marked as a duplicate of this bug. ***
Comment 21 Dani Megert CLA 2012-02-22 02:58:27 EST
*** Bug 369900 has been marked as a duplicate of this bug. ***