Project: Eclipse_Platform_UI
Bug 371100 "IllegalArgumentException: Widget has the wrong parent" if use showPart-Method on unvisible Part
Reported: 2012-02-09 11:12:23 | Status: verified fixed

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.

Files changed in fix:
bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java