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