Skip to main content
summaryrefslogtreecommitdiffstats
blob: d8d884321024ec8b1964290b9ad5edac5d98b228 (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
63
64
65
package org.eclipse.debug.internal.ui;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILauncher;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.help.WorkbenchHelp;

public class LaunchSelectionAction extends Action {

	protected ILauncher fLauncher;
	protected String fMode;
	protected Object fElement;
	
	public LaunchSelectionAction(ILauncher launcher, Object element, String mode) {
		super();
		fLauncher= launcher;
		fMode= mode;
		fElement= element;
		setText(new DelegatingModelPresentation().getText(launcher));
		ImageDescriptor descriptor= null;
		if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
			descriptor= DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_ACT_DEBUG);
		} else {
			descriptor= DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_ACT_RUN);
		}

		if (descriptor != null) {
			setImageDescriptor(descriptor);
		}
		
		WorkbenchHelp.setHelp(
			this,
			new Object[] { IDebugHelpContextIds.LAUNCH_SELECTION_ACTION });
	}

	/**
	 * @see IAction
	 */
	public void run() {
		BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
			public void run() {
				if (fElement != null || !DebugUIPlugin.getDefault().hasWizard(fLauncher)) {
					fLauncher.launch(new Object[] {fElement}, fMode);
				} else {
					Shell shell= DebugUIPlugin.getActiveWorkbenchWindow().getShell();
					if (shell != null) {
						useWizard(new Object[] {fLauncher}, shell, StructuredSelection.EMPTY);
					}
				}
			}
		});
	}

	/**
	 * Use the launch wizard to do the launch.
	 */
	protected void useWizard(Object[] launchers, Shell shell, IStructuredSelection selection) {
		LaunchWizard wizard= new LaunchWizard(launchers, selection, fMode, false);
		LaunchWizardDialog dialog= new LaunchWizardDialog(shell, wizard);
		dialog.open();
	}
}

Back to the top