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

Bug 371100

Summary: "IllegalArgumentException: Widget has the wrong parent" if use showPart-Method on unvisible Part
Product: [Eclipse Project] Platform Reporter: Peter Weihrauch <Peter_Weihrauch>
Component: UIAssignee: Remy Suen <remy.suen>
Status: VERIFIED FIXED QA Contact: Eric Moffatt <emoffatt>
Severity: normal    
Priority: P3 CC: dimitar.georgiev, emoffatt, Lars.Vogel, remy.suen, tom.schindl
Version: 4.2   
Target Milestone: 4.2 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
PartRenderingEngineTests patch v1 none

Description Peter Weihrauch CLA 2012-02-09 11:12:23 EST
Build Identifier:  I20120127-1145

I have a Part, declared as unvisible, in the aplication model file "application.e4xmi"

in the part i declare an Selectionlistner per DI. 
Example:

@Inject
public void setTodo(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Todo obj {
...
}

if i use the showPart(...)-Method from the EPartService, to set the unvisible part visible, the part will not show ui elements.

next i fire a selection event which is targeted to the listener in the part i got the following Error Stacktrace.

java.lang.IllegalArgumentException: Widget has the wrong parent
	at org.eclipse.swt.SWT.error(SWT.java:4281)
	at org.eclipse.swt.SWT.error(SWT.java:4215)
	at org.eclipse.swt.SWT.error(SWT.java:4186)
	at org.eclipse.e4.ui.widgets.CTabItem.setControl(CTabItem.java:284)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.createTab(StackRenderer.java:574)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.childRendered(StackRenderer.java:624)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:640)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:718)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:689)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:683)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:668)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:803)
	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:66)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)

workaround is, to use the Method setVisible(...) at the Part-object to set the isVisible flag in the Model just before i call showPart(...).

Example:

MPart part = pService.findPart(...);
if (part != null ) {
   part.setVisible(true);
   pService.showPart(part, PartState.VISIBLE);
}

with the setVisible(...) Method everything works fine.

Reproducible: Always

Steps to Reproduce:
1. create a unvisible Part in the Model

2. create a class for the Part with a selectionlistener (for example active selection) per DI

3. make the part visible in a SelectionAdapter implementation of a button for example (the gui of the part shouldn't display)

4. fire a selectionevent to test the selectionlistener.

5. the error occurs if the event is fired.
Comment 1 Remy Suen CLA 2012-02-09 12:20:59 EST
Created attachment 210815 [details]
PartRenderingEngineTests patch v1
Comment 2 Remy Suen CLA 2012-02-09 12:22:01 EST
Eric, this seems to me like a problem in either LazyStackRenderer or StackRenderer.
Comment 3 Remy Suen CLA 2012-02-15 13:45:12 EST
Fix pushed to master.
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=feb8869ccc667cf3c69487fa917c6a3b3615f235

Peter, I think what you might want is to have your part start off as toBeRendered="false" and then have it shown later?
Comment 4 Peter Weihrauch CLA 2012-02-17 15:04:14 EST
yes thats right
Comment 5 Remy Suen CLA 2012-02-22 07:44:03 EST
*** Bug 372211 has been marked as a duplicate of this bug. ***
Comment 6 Remy Suen CLA 2012-03-13 09:26:47 EDT
Verified by source code inspection with I20120312-1730.