debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AbstractSymbianLaunchShortcut.java
author Ed Swartz <ed.swartz@nokia.com>
Wed, 07 Apr 2010 14:37:19 -0500
branchRCL_2_4
changeset 1168 8e38fdef1cea
parent 953 68b6a294ab01
child 1254 0e45b6356eac
permissions -rw-r--r--
Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     1
package com.nokia.cdt.internal.debug.launch;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     2
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
     3
import java.util.ArrayList;
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     4
import java.util.List;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     5
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     6
import org.eclipse.cdt.debug.core.executables.Executable;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     7
import org.eclipse.core.resources.IFile;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     8
import org.eclipse.core.resources.IProject;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
     9
import org.eclipse.core.resources.IResource;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    10
import org.eclipse.core.runtime.CoreException;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    11
import org.eclipse.core.runtime.IAdaptable;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    12
import org.eclipse.core.runtime.IPath;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    13
import org.eclipse.debug.core.ILaunchConfiguration;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    14
import org.eclipse.debug.ui.DebugUITools;
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    15
import org.eclipse.debug.ui.IDebugModelPresentation;
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    16
import org.eclipse.debug.ui.ILaunchShortcut2;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    17
import org.eclipse.jface.viewers.ISelection;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    18
import org.eclipse.jface.viewers.IStructuredSelection;
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    19
import org.eclipse.jface.window.Window;
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    20
import org.eclipse.ui.IEditorInput;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    21
import org.eclipse.ui.IEditorPart;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    22
import org.eclipse.ui.IFileEditorInput;
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    23
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    24
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    26
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    27
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    28
public abstract class AbstractSymbianLaunchShortcut implements ILaunchShortcut2 {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    29
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    30
	protected abstract void launchProject(IProject project, Executable executable, IPath defaultMMP, String mode);
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    31
	
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    32
	/**
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    33
	 * Override to tell whether this existing configuration matches the type of
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    34
	 * one the shortcut would create. The default implementation returns true
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    35
	 * for all configurations.
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    36
	 */
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    37
	protected boolean isSupportedConfiguration(ILaunchConfiguration config) throws CoreException {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    38
		return true;
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    39
	}
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    40
 	
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    41
	public void launch(IEditorPart editor, String mode) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    42
		// launch an existing config if one exists
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    43
		ILaunchConfiguration[] configs = getLaunchConfigurations(editor);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    44
		if (configs.length > 0) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    45
			// just launch the first one that supports the mode
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    46
			for (ILaunchConfiguration config : configs) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    47
				try {
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    48
					if (config.supportsMode(mode) && isSupportedConfiguration(config)) {
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    49
						DebugUITools.launch(configs[0], mode);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    50
						return;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    51
					}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    52
				} catch (CoreException e) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    53
					e.printStackTrace();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    54
				}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    55
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    56
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    57
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    58
		IEditorInput editorInput = editor.getEditorInput();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    59
		if (editorInput instanceof IFileEditorInput) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    60
			IFile file = ((IFileEditorInput)editorInput).getFile();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    61
			if (file != null) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    62
				launchProject(file.getProject(), null, null, mode);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    63
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    64
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    65
	}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    66
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    67
	public void launch(ISelection selection, String mode) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    68
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    69
		// launch an existing config if one exists
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    70
		ILaunchConfiguration[] configs = getLaunchConfigurations(selection);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    71
		if (configs.length > 0) {
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    72
			// find all the ones that support the mode and shortcut (#11013)
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    73
			List<ILaunchConfiguration> matches = new ArrayList<ILaunchConfiguration>();
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    74
			for (int i = 0; i < configs.length; i++) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    75
				ILaunchConfiguration config = configs[i];
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    76
				try {
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    77
					if (config.supportsMode(mode) && isSupportedConfiguration(config)) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    78
						matches.add(config);
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    79
					}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    80
				} catch (CoreException e) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    81
					e.printStackTrace();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    82
				}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    83
			}
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    84
			// if only one matches, just launch
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    85
			if (matches.size() > 0) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    86
				if (matches.size() == 1 || WorkbenchUtils.isJUnitRunning()) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    87
					DebugUITools.launch(matches.get(0), mode);
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    88
				} else {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    89
					// else, ask the user
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    90
					ILaunchConfiguration selected = chooseConfiguration(matches, mode);
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    91
					if (selected != null)
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    92
						DebugUITools.launch(selected, mode);
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    93
				}
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    94
				return;
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
    95
			}
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    96
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    98
		IPath defaultMMP = null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
    99
		boolean launched = false;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   100
		Executable executable = null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   101
		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   102
		if (selection instanceof IStructuredSelection) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   103
			Object firstElement = ((IStructuredSelection) selection).getFirstElement();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   104
			if (firstElement != null && firstElement instanceof Executable)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   105
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   106
				launchProject(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP, mode);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   107
				launched = true;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   108
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   109
			else
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   110
			if (firstElement != null && firstElement instanceof IAdaptable)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   111
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   112
				IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   113
				if (file != null)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   114
				{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   115
					IPath filePath = file.getLocation();
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   116
					if ("mmp".equalsIgnoreCase(filePath.getFileExtension())) //$NON-NLS-1$
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   117
					{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   118
						defaultMMP = filePath;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   119
					}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   120
					else
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   121
					{		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   122
						executable = new Executable(file.getLocation(), file.getProject(), file);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   123
						launchProject(file.getProject(), executable, defaultMMP, mode);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   124
						launched = true;					
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   125
					}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   126
				}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   127
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   128
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   130
		if (!launched)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   131
		{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   132
			List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection);		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   133
			if (projects.size() > 0) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   134
				launchProject(projects.get(0), executable, defaultMMP, mode);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   135
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   136
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   137
	}
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   138
	
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   139
	/**
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   140
	 * Show a selection dialog that allows the user to choose one of the specified
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   141
	 * launch configurations.  Return the chosen config, or <code>null</code> if the
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   142
	 * user cancelled the dialog.
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   143
	 */
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   144
	protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   145
		IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   146
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(WorkbenchUtils.getSafeShell(), labelProvider);
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   147
		dialog.setElements(configList.toArray());
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   148
		dialog.setTitle(Messages.getString("AbstractSymbianLaunchShortcut.ChooseConfigTitle"));  //$NON-NLS-1$
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   149
		dialog.setMessage(Messages.getString("AbstractSymbianLaunchShortcut.ChooseConfigLabel"));  //$NON-NLS-1$
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   150
		dialog.setMultipleSelection(false);
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   151
		int result = dialog.open();
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   152
		labelProvider.dispose();
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   153
		if (result == Window.OK) {
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   154
			return (ILaunchConfiguration) dialog.getFirstResult();
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   155
		}
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   156
		return null;
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   157
	}
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   158
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   159
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   160
	public ILaunchConfiguration[] getLaunchConfigurations(ISelection selection) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   161
		IPath defaultMMP = null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   162
		if (selection instanceof IStructuredSelection) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   163
			Object firstElement = ((IStructuredSelection) selection).getFirstElement();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   164
			if (firstElement != null && firstElement instanceof Executable)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   165
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   166
				return LaunchPlugin.getDefault().getLaunchConfigurations(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   167
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   168
			else
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   169
			if (firstElement != null && firstElement instanceof IAdaptable)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   170
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   171
				IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   172
				if (file != null)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   173
				{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   174
					IPath filePath = file.getLocation();
1168
8e38fdef1cea Bug 11013: choose appropriate launch configs when using Run/Debug As... shortcut
Ed Swartz <ed.swartz@nokia.com>
parents: 953
diff changeset
   175
					if ("mmp".equalsIgnoreCase(filePath.getFileExtension())) //$NON-NLS-1$
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   176
					{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   177
						defaultMMP = filePath;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   178
					}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   179
					Executable executable = new Executable(file.getLocation(), file.getProject(), file);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   180
					return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), executable, defaultMMP);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   181
				}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   182
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   183
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   184
		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   185
		List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection);		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   186
		if (projects.size() > 0) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   187
			return LaunchPlugin.getDefault().getLaunchConfigurations(projects.get(0), null, defaultMMP);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   188
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   189
		return null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   190
	}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   191
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   192
	public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart editorpart) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   193
		IEditorInput editorInput = editorpart.getEditorInput();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   194
		if (editorInput instanceof IFileEditorInput) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   195
			IFile file = ((IFileEditorInput)editorInput).getFile();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   196
			if (file != null) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   197
				return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), null, null);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   198
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   199
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   200
		return null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   201
	}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   202
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   203
	public IResource getLaunchableResource(ISelection selection) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   204
		if (selection instanceof IStructuredSelection) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   205
			Object firstElement = ((IStructuredSelection) selection).getFirstElement();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   206
			if (firstElement != null && firstElement instanceof IFile)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   207
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   208
				IFile file = (IFile) firstElement;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   209
				return file.getProject();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   210
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   211
			if (firstElement != null && firstElement instanceof Executable)
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   212
			{
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   213
				return ((Executable)firstElement).getProject();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   214
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   215
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   216
		List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection);		
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   217
		if (projects.size() > 0) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   218
			return projects.get(0);
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   219
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   220
		return null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   221
	}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   222
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   223
	public IResource getLaunchableResource(IEditorPart editorpart) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   224
		IEditorInput editorInput = editorpart.getEditorInput();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   225
		if (editorInput instanceof IFileEditorInput) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   226
			IFile file = ((IFileEditorInput)editorInput).getFile();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   227
			if (file != null) {
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   228
				return file.getProject();
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   229
			}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   230
		}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   231
		return null;
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   232
	}
68b6a294ab01 new launch wizard implementation
dadubrow
parents:
diff changeset
   233
}