Bug 506432 - [ui] p2 install dialog shouldn't be modal

Checks if the dialog is already open and activates the corresponding
shell. This way we keep the existing flow of having only one open
installation dialog, we we decided is a nicer user flow.

Change-Id: I3542e122312ad756011123a4bf1adf3054023fab
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java
index 0a526f5..b52071e 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     Sonatype, Inc. - ongoing development
  *     Red Hat Inc. - Bug 460967
+ *     Lars Vogel <Lars.Vogel@vogella.com> - Bug 506432
  ******************************************************************************/
 
 package org.eclipse.equinox.p2.ui;
@@ -34,6 +35,7 @@
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
 import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.*;
@@ -221,6 +223,15 @@
 	public int openInstallWizard(Collection<IInstallableUnit> initialSelections, InstallOperation operation, RemediationOperation remediationOperation, LoadMetadataRepositoryJob job) {
 		if (operation == null) {
 			InstallWizard wizard = new InstallWizard(this, operation, initialSelections, job);
+			// check if provitiondialog is already open and give focus to it, if that is the case
+			Shell[] shells = Display.getCurrent().getShells();
+			for (Shell shell : shells) {
+				if (shell.getData() instanceof ProvisioningWizardDialog) {
+					shell.forceActive();
+					shell.setFocus();
+					return Window.OK;
+				}
+			}
 			WizardDialog dialog = new ProvisioningWizardDialog(ProvUI.getDefaultParentShell(), wizard);
 			dialog.create();
 			PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IProvHelpContextIds.INSTALL_WIZARD);