Skip to main content
summaryrefslogtreecommitdiffstats
blob: be79a20b0418047cea7e7fcff435f8cff57c9049 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 *  Copyright (c) 2008, 2009 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
 *  http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.ui.dialogs;

import org.eclipse.core.commands.*;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.equinox.p2.tests.ui.AbstractProvisioningUITest;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;

/**
 * Tests for invoking the p2 wizards by command id.
 * Other plug-ins do this, this test reminds us that if the handler
 * ids change, there are repercussions.
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=263262
 */
public class InvokeByHandlerTests extends AbstractProvisioningUITest {

	private static final String INSTALL = "org.eclipse.equinox.p2.ui.sdk.install";
	private static final String UPDATE = "org.eclipse.equinox.p2.ui.sdk.update";

	public void testInstallHandler() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				Display.getDefault().getActiveShell().close();
			}

		});
		runCommand(INSTALL);

	}

	public void testUpdateHandler() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				Display.getDefault().getActiveShell().close();
			}

		});
		runCommand(UPDATE);
	}

	private void runCommand(String commandId) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
		ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
		Command command = commandService.getCommand(commandId);
		if (!command.isDefined()) {
			return;
		}
		IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
		handlerService.executeCommand(commandId, null);
	}
}

Back to the top