Bug 378835 - Toggle Toolbar Visibility missing in 4.2

Removed confusing visibleWhen logic for Show/Hide Toolbar.
Re-incorporated preference-based solution for persisting
coolbar and perspective switcher status.
diff --git a/bundles/org.eclipse.ui.ide/plugin.xml b/bundles/org.eclipse.ui.ide/plugin.xml
index fe4ab59..2a02a22 100644
--- a/bundles/org.eclipse.ui.ide/plugin.xml
+++ b/bundles/org.eclipse.ui.ide/plugin.xml
@@ -1636,23 +1636,6 @@
                commandId="org.eclipse.ui.ToggleCoolbarAction"
                tooltip="%menu.toggleCoolbar.tooltip"
                style="push">
-            <visibleWhen
-                  checkEnabled="false">
-                  <or>
-               		<with
-                  	   variable="activeWorkbenchWindow.isCoolbarVisible">
-                  		<equals
-                        	value="false">
-                  		</equals>
-               		</with>
-               		<with
-                    	 variable="activeWorkbenchWindow.isPerspectiveBarVisible">
-                  		<equals
-                        	value="false">
-                  		</equals>
-               		</with>
-               </or>
-            </visibleWhen>
          </command>
       </menuContribution>
       <menuContribution
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index 40cd86a..56547b2 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -409,6 +409,12 @@
 
 	@PostConstruct
 	public void setup() {
+		// Initialize a previous 'saved' state if applicable.
+		this.coolBarVisible = PrefUtil.getInternalPreferenceStore().getBoolean(
+				IPreferenceConstants.COOLBAR_VISIBLE);
+		this.perspectiveBarVisible = PrefUtil.getInternalPreferenceStore().getBoolean(
+				IPreferenceConstants.PERSPECTIVEBAR_VISIBLE);
+
 		final IEclipseContext windowContext = model.getContext();
 		IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
 				.getService(IServiceLocatorCreator.class);
@@ -694,7 +700,7 @@
 
 		// render now after everything has been added so contributions can be
 		// inserted in the right place
-		trimBar.setToBeRendered(true);
+		updateLayoutDataForContents();
 	}
 
 	private void populateStandardTrim(MTrimBar bottomTrim) {
@@ -751,7 +757,7 @@
 		if (items.size() == 0)
 			return;
 
-		// Iterate over the items until they've all been placed or unril
+		// Iterate over the items until they've all been placed or until
 		// an iteration doesn't place anything
 		List<IConfigurationElement> handledElements = new ArrayList<IConfigurationElement>();
 		handledElements.add(items.get(0)); // Hack!! startup seeding
@@ -2092,7 +2098,7 @@
 		boolean oldValue = coolBarVisible;
 		coolBarVisible = visible;
 		if (oldValue != coolBarVisible) {
-
+			updateLayoutDataForContents();
 			firePropertyChanged(PROP_COOLBAR_VISIBLE, oldValue ? Boolean.TRUE : Boolean.FALSE,
 					coolBarVisible ? Boolean.TRUE : Boolean.FALSE);
 		}
@@ -2126,7 +2132,7 @@
 		boolean oldValue = perspectiveBarVisible;
 		perspectiveBarVisible = visible;
 		if (oldValue != perspectiveBarVisible) {
-
+			updateLayoutDataForContents();
 			firePropertyChanged(PROP_PERSPECTIVEBAR_VISIBLE, oldValue ? Boolean.TRUE
 					: Boolean.FALSE, perspectiveBarVisible ? Boolean.TRUE : Boolean.FALSE);
 		}
@@ -2357,18 +2363,39 @@
 	 * @since 3.3
 	 */
 	public void toggleToolbarVisibility() {
+		boolean coolbarVisible = getCoolBarVisible();
+		boolean perspectivebarVisible = getPerspectiveBarVisible();
+		IPreferenceStore prefs = PrefUtil.getInternalPreferenceStore();
+
+		// only toggle the visibility of the components that
+		// were on initially
+		if (getWindowConfigurer().getShowCoolBar()) {
+			setCoolBarVisible(!coolbarVisible);
+			prefs.setValue(IPreferenceConstants.COOLBAR_VISIBLE, !coolbarVisible);
+		}
+		if (getWindowConfigurer().getShowPerspectiveBar()) {
+			setPerspectiveBarVisible(!perspectivebarVisible);
+			prefs.setValue(IPreferenceConstants.PERSPECTIVEBAR_VISIBLE, !perspectivebarVisible);
+		}
+	}
+
+	private void updateLayoutDataForContents() {
 		MTrimBar topTrim = getTopTrim();
 		if (topTrim != null) {
-			if (topTrim.isToBeRendered()) {
+			if ((getCoolBarVisible() && getWindowConfigurer().getShowCoolBar())
+					|| (getPerspectiveBarVisible() && getWindowConfigurer()
+							.getShowPerspectiveBar())) {
+				if (!topTrim.isToBeRendered()) {
+					IPresentationEngine presentationEngine = model.getContext().get(
+							IPresentationEngine.class);
+					topTrim.setToBeRendered(true);
+					presentationEngine.createGui(topTrim, model.getWidget(), model.getContext());
+				}
+			} else {
 				IPresentationEngine presentationEngine = model.getContext().get(
 						IPresentationEngine.class);
 				topTrim.setToBeRendered(false);
 				presentationEngine.removeGui(topTrim);
-			} else {
-				IPresentationEngine presentationEngine = model.getContext().get(
-						IPresentationEngine.class);
-				topTrim.setToBeRendered(true);
-				presentationEngine.createGui(topTrim, model.getWidget(), model.getContext());
 			}
 			getShell().layout();
 		}