Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 222378 | Differences between
and this patch

Collapse All | Expand All

(-)src-intro/org/eclipse/platform/internal/LaunchUpdateIntroAction.java (-24 / +60 lines)
Lines 1-40 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 200, 2005 IBM Corporation and others.
2
 * Copyright (c) 200, 2005 IBM Corporation and others. All rights reserved. This
3
 * All rights reserved. This program and the accompanying materials
3
 * program and the accompanying materials are made available under the terms of
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * which accompanies this distribution, and is available at
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 *
7
 * Contributors: IBM Corporation - initial API and implementation
8
 * Contributors:
8
 ******************************************************************************/
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.platform.internal;
9
package org.eclipse.platform.internal;
12
10
13
import java.util.Properties;
11
import java.util.Properties;
14
12
13
import org.eclipse.core.commands.Command;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.NotEnabledException;
17
import org.eclipse.core.commands.NotHandledException;
18
import org.eclipse.core.commands.common.NotDefinedException;
19
import org.eclipse.core.internal.registry.BundleHelper;
20
import org.eclipse.core.internal.runtime.Log;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.internal.adaptor.PluginParser.PluginInfo;
15
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.commands.ICommandService;
28
import org.eclipse.ui.handlers.IHandlerService;
29
import org.eclipse.ui.internal.util.BundleUtility;
17
import org.eclipse.ui.intro.IIntroSite;
30
import org.eclipse.ui.intro.IIntroSite;
18
import org.eclipse.ui.intro.config.IIntroAction;
31
import org.eclipse.ui.intro.config.IIntroAction;
19
import org.eclipse.update.ui.UpdateManagerUI;
32
import org.eclipse.update.ui.UpdateManagerUI;
33
import org.osgi.framework.Bundle;
20
34
21
public class LaunchUpdateIntroAction implements IIntroAction {
35
public class LaunchUpdateIntroAction implements IIntroAction {
22
36
23
    public LaunchUpdateIntroAction() {
37
	private static final String COMMAND_P2 = "org.eclipse.equinox.p2.ui.sdk.update";
24
    }
38
	private static final String COMMAND_UPDATE_MANAGER = "org.eclipse.ui.update.findAndInstallUpdates";
25
39
26
    public void run(IIntroSite site, Properties params) {
40
	public LaunchUpdateIntroAction() {
41
	}
27
42
28
        Runnable r = new Runnable() {
43
	public void run(IIntroSite site, Properties params) {
29
            public void run() {
44
		Runnable r = new Runnable() {
30
                Shell currentShell = PlatformUI.getWorkbench()
45
			public void run() {
31
                    .getActiveWorkbenchWindow().getShell();
46
				if (!executeUpdateCommand(COMMAND_P2)) {
32
                UpdateManagerUI.openInstaller(currentShell);
47
					executeUpdateCommand(COMMAND_UPDATE_MANAGER);
33
            }
48
				}
34
        };
49
			}
35
50
		};
36
        Shell currentShell = PlatformUI.getWorkbench()
51
		Shell currentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
37
            .getActiveWorkbenchWindow().getShell();
52
		currentShell.getDisplay().asyncExec(r);
38
        currentShell.getDisplay().asyncExec(r);
53
	}
39
    }
54
55
	private boolean executeUpdateCommand(String command) {
56
		ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
57
		IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
58
		Command cmd;
59
		cmd = commandService.getCommand(command);
60
		ExecutionEvent executionEvent = handlerService.createExecutionEvent(cmd, null);
61
		try {
62
			cmd.executeWithChecks(executionEvent);
63
		} catch (ExecutionException e) {
64
			String bundleId = "org.eclipse.platform";
65
			Bundle bundle = Platform.getBundle(bundleId);
66
			Status status = new Status(IStatus.ERROR, bundleId, "Exception executing command: " + command, e);
67
			Platform.getLog(bundle).log(status);
68
		} catch (NotDefinedException e) {
69
			return false;
70
		} catch (NotEnabledException e) {
71
		} catch (NotHandledException e) {
72
			return false;
73
		}
74
		return true;
75
	}
40
}
76
}

Return to bug 222378