Bug 546542 - No busy cursor is shown when open perspective from open
perspective dialog or perspective bar after upgrade to 4.6.3

Change-Id: Id5c57ed781bb046288598b55e8591d843734bf33
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java
index d9c1292..3eb97c3 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2016 IBM Corporation and others.
+ * Copyright (c) 2010, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -57,6 +57,7 @@
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.accessibility.AccessibleAdapter;
 import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -512,8 +513,10 @@
 		psItem.addSelectionListener(new SelectionAdapter() {
 			@Override
 			public void widgetSelected(SelectionEvent e) {
-				MPerspective persp = (MPerspective) e.widget.getData();
-				persp.getParent().setSelectedElement(persp);
+				BusyIndicator.showWhile(null, () -> {
+					MPerspective persp = (MPerspective) e.widget.getData();
+					persp.getParent().setSelectedElement(persp);
+				});
 			}
 		});
 
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/handlers/ShowPerspectiveHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/handlers/ShowPerspectiveHandler.java
index 785b295..020819f 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/handlers/ShowPerspectiveHandler.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/handlers/ShowPerspectiveHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -15,13 +15,13 @@
 package org.eclipse.ui.handlers;
 
 import java.util.Map;
-
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.window.Window;
+import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.ui.IPerspectiveDescriptor;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchCommandConstants;
@@ -56,11 +56,20 @@
 		if (value == null) {
 			openOther(window);
 		} else {
-
-			if (newWindow == null || newWindow.equalsIgnoreCase("false")) { //$NON-NLS-1$
-				openPerspective((String) value, window);
-			} else {
-				openNewWindowPerspective((String) value, window);
+			ExecutionException[] exception = new ExecutionException[1];
+			BusyIndicator.showWhile(null, () -> {
+				try {
+					if (newWindow == null || newWindow.equalsIgnoreCase("false")) { //$NON-NLS-1$
+						openPerspective((String) value, window);
+					} else {
+						openNewWindowPerspective((String) value, window);
+					}
+				} catch (ExecutionException e) {
+					exception[0] = e;
+				}
+			});
+			if (exception[0] != null) {
+				throw exception[0];
 			}
 		}
 		return null;
@@ -106,10 +115,20 @@
 			String perspectiveId = descriptor.getId();
 			// only open it in a new window if the preference is set and the
 			// current workbench page doesn't have an active perspective
-			if (IPreferenceConstants.OPM_NEW_WINDOW == openPerspMode && persp != null) {
-				openNewWindowPerspective(perspectiveId, activeWorkbenchWindow);
-			} else {
-				openPerspective(perspectiveId, activeWorkbenchWindow);
+			ExecutionException[] exception = new ExecutionException[1];
+			BusyIndicator.showWhile(null, () -> {
+				try {
+					if (IPreferenceConstants.OPM_NEW_WINDOW == openPerspMode && persp != null) {
+						openNewWindowPerspective(perspectiveId, activeWorkbenchWindow);
+					} else {
+						openPerspective(perspectiveId, activeWorkbenchWindow);
+					}
+				} catch (ExecutionException e) {
+					exception[0] = e;
+				}
+			});
+			if (exception[0] != null) {
+				throw exception[0];
 			}
 		}
 	}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index a02e7a9..a98440c 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -2936,6 +2936,26 @@
 	public IWorkbenchPage showPerspective(String perspectiveId, IWorkbenchWindow targetWindow, IAdaptable input)
 			throws WorkbenchException {
 		Assert.isNotNull(perspectiveId);
+		final Object[] ret = new Object[1];
+		BusyIndicator.showWhile(null, () -> {
+			try {
+				ret[0] = busyShowPerspective(perspectiveId, targetWindow, input);
+			} catch (WorkbenchException e) {
+				ret[0] = e;
+			}
+		});
+		if (ret[0] instanceof IWorkbenchPage) {
+			return (IWorkbenchPage) ret[0];
+		} else if (ret[0] instanceof WorkbenchException) {
+			throw ((WorkbenchException) ret[0]);
+		} else {
+			throw new WorkbenchException(WorkbenchMessages.WorkbenchPage_AbnormalWorkbenchCondition);
+		}
+	}
+
+	private IWorkbenchPage busyShowPerspective(String perspectiveId, IWorkbenchWindow targetWindow, IAdaptable input)
+			throws WorkbenchException {
+		Assert.isNotNull(perspectiveId);
 		IPerspectiveDescriptor targetPerspective = getPerspectiveRegistry().findPerspectiveWithId(perspectiveId);
 		if (targetPerspective == null) {
 			throw new WorkbenchException(
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
index b01164e..9dc9af4 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
@@ -3981,6 +3981,10 @@
 
 	@Override
 	public void setPerspective(IPerspectiveDescriptor perspective) {
+		BusyIndicator.showWhile(null, () -> busySetPerspective(perspective));
+	}
+
+	private void busySetPerspective(IPerspectiveDescriptor perspective) {
 		if (perspective == null) {
 			return;
 		}