1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2008 IBM Corporation and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * IBM Corporation - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.project.management.install;
\r
13 import org.eclipse.core.runtime.IStatus;
\r
14 import org.eclipse.equinox.internal.provisional.p2.installer.IInstallOperation;
\r
15 import org.eclipse.equinox.internal.provisional.p2.installer.InstallAdvisor;
\r
16 import org.eclipse.equinox.internal.provisional.p2.installer.InstallDescription;
\r
17 import org.eclipse.swt.widgets.Display;
\r
20 * Install context that creates a simple SWT-based UI and interacts with a user.
\r
22 public class SWTInstallAdvisor extends InstallAdvisor {
\r
23 private InstallDialog dialog;
\r
24 private boolean started = false;
\r
25 private boolean stopped = false;
\r
27 public IStatus performInstall(IInstallOperation operation) {
\r
28 return dialog.run(operation);
\r
31 public InstallDescription prepareInstallDescription(InstallDescription description) {
\r
32 if (description.getInstallLocation() == null)
\r
33 dialog.promptForLocations(description);
\r
37 public boolean promptForLaunch(InstallDescription description) {
\r
38 return dialog.promptForLaunch(description);
\r
41 public void setResult(IStatus status) {
\r
43 if (status.getSeverity() == IStatus.CANCEL) {
\r
44 message = "Canceled";
\r
46 message = status.getMessage();
\r
48 dialog.promptForClose(message);
\r
51 public synchronized void start() {
\r
52 if (stopped || started)
\r
55 Display display = Display.getCurrent();
\r
56 if (display == null)
\r
57 display = new Display();
\r
58 dialog = new InstallDialog();
\r
59 dialog.setMessage("Preparing");
\r
62 public synchronized void stop() {
\r
63 if (stopped || !started)
\r
66 final InstallDialog activeDialog = dialog;
\r
67 if (activeDialog == null)
\r
69 //clear the window now, so the reference is gone no matter what happens during cleanup
\r
71 final Display display = activeDialog.getDisplay();
\r
72 if (display == null || display.isDisposed())
\r
74 display.syncExec(new Runnable() {
\r
76 activeDialog.close();
\r