Fix for Bug 374121 - AIOOBE when restoring a window with no perspectives
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java
index 853a1a5..371aca4 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java
@@ -76,7 +76,10 @@
 				toolControl.getContributionURI(), parentContext, localContext);
 		toolControl.setObject(tcImpl);
 		Control[] kids = parentComp.getChildren();
-		assert (kids.length > 0);
+
+		// No kids means that the trim failed curing creation
+		if (kids.length == 0)
+			return null;
 
 		// The new control is assumed to be the last child created
 		// We could safe this up even more by asserting that the
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/StandardTrim.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/StandardTrim.java
index 77b0d63..18cb3fd 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/StandardTrim.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/StandardTrim.java
@@ -20,6 +20,7 @@
 import org.eclipse.jface.action.StatusLineManager;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.internal.progress.ProgressRegion;
 import org.eclipse.ui.internal.util.PrefUtil;
 
@@ -79,7 +80,20 @@
 		IEclipseContext context = modelService.getContainingContext(toolControl);
 		WorkbenchWindow wbw = (WorkbenchWindow) context.get(IWorkbenchWindow.class);
 		// wbw may be null if workspace is started with no open perspectives.
+		if (wbw == null) {
+			// Create one assuming there's no defined perspective
+			Workbench wb = (Workbench) PlatformUI.getWorkbench();
+			wb.createWorkbenchWindow(wb.getDefaultPageInput(), null,
+					modelService.getTopLevelWindowFor(toolControl), false);
+			wbw = (WorkbenchWindow) context.get(IWorkbenchWindow.class);
+		}
+
 		if (wbw != null) {
+			Workbench wb = (Workbench) PlatformUI.getWorkbench();
+			wb.createWorkbenchWindow(wb.getDefaultPageInput(), null,
+					modelService.getTopLevelWindowFor(toolControl), false);
+			wbw = (WorkbenchWindow) context.get(IWorkbenchWindow.class);
+
 			manager = wbw.getStatusLineManager();
 			manager.createControl(parent);
 		}