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