author | Ed Swartz <ed.swartz@nokia.com> |
Wed, 07 Apr 2010 14:37:19 -0500 | |
branch | RCL_2_4 |
changeset 1168 | 8e38fdef1cea |
parent 953 | 68b6a294ab01 |
child 1254 | 0e45b6356eac |
permissions | -rw-r--r-- |
953 | 1 |
package com.nokia.cdt.internal.debug.launch; |
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 | 4 |
import java.util.List; |
5 |
||
6 |
import org.eclipse.cdt.debug.core.executables.Executable; |
|
7 |
import org.eclipse.core.resources.IFile; |
|
8 |
import org.eclipse.core.resources.IProject; |
|
9 |
import org.eclipse.core.resources.IResource; |
|
10 |
import org.eclipse.core.runtime.CoreException; |
|
11 |
import org.eclipse.core.runtime.IAdaptable; |
|
12 |
import org.eclipse.core.runtime.IPath; |
|
13 |
import org.eclipse.debug.core.ILaunchConfiguration; |
|
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 | 16 |
import org.eclipse.debug.ui.ILaunchShortcut2; |
17 |
import org.eclipse.jface.viewers.ISelection; |
|
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 | 20 |
import org.eclipse.ui.IEditorInput; |
21 |
import org.eclipse.ui.IEditorPart; |
|
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 | 24 |
|
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 | 27 |
|
28 |
public abstract class AbstractSymbianLaunchShortcut implements ILaunchShortcut2 { |
|
29 |
||
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 | 41 |
public void launch(IEditorPart editor, String mode) { |
42 |
// launch an existing config if one exists |
|
43 |
ILaunchConfiguration[] configs = getLaunchConfigurations(editor); |
|
44 |
if (configs.length > 0) { |
|
45 |
// just launch the first one that supports the mode |
|
46 |
for (ILaunchConfiguration config : configs) { |
|
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 | 49 |
DebugUITools.launch(configs[0], mode); |
50 |
return; |
|
51 |
} |
|
52 |
} catch (CoreException e) { |
|
53 |
e.printStackTrace(); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
IEditorInput editorInput = editor.getEditorInput(); |
|
59 |
if (editorInput instanceof IFileEditorInput) { |
|
60 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
61 |
if (file != null) { |
|
62 |
launchProject(file.getProject(), null, null, mode); |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
public void launch(ISelection selection, String mode) { |
|
68 |
||
69 |
// launch an existing config if one exists |
|
70 |
ILaunchConfiguration[] configs = getLaunchConfigurations(selection); |
|
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 | 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 | 79 |
} |
80 |
} catch (CoreException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
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 | 96 |
} |
97 |
||
98 |
IPath defaultMMP = null; |
|
99 |
boolean launched = false; |
|
100 |
Executable executable = null; |
|
101 |
||
102 |
if (selection instanceof IStructuredSelection) { |
|
103 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
104 |
if (firstElement != null && firstElement instanceof Executable) |
|
105 |
{ |
|
106 |
launchProject(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP, mode); |
|
107 |
launched = true; |
|
108 |
} |
|
109 |
else |
|
110 |
if (firstElement != null && firstElement instanceof IAdaptable) |
|
111 |
{ |
|
112 |
IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class); |
|
113 |
if (file != null) |
|
114 |
{ |
|
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 | 117 |
{ |
118 |
defaultMMP = filePath; |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
executable = new Executable(file.getLocation(), file.getProject(), file); |
|
123 |
launchProject(file.getProject(), executable, defaultMMP, mode); |
|
124 |
launched = true; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
if (!launched) |
|
131 |
{ |
|
132 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
133 |
if (projects.size() > 0) { |
|
134 |
launchProject(projects.get(0), executable, defaultMMP, mode); |
|
135 |
} |
|
136 |
} |
|
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 | 159 |
|
160 |
public ILaunchConfiguration[] getLaunchConfigurations(ISelection selection) { |
|
161 |
IPath defaultMMP = null; |
|
162 |
if (selection instanceof IStructuredSelection) { |
|
163 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
164 |
if (firstElement != null && firstElement instanceof Executable) |
|
165 |
{ |
|
166 |
return LaunchPlugin.getDefault().getLaunchConfigurations(((Executable)firstElement).getProject(), (Executable)firstElement, defaultMMP); |
|
167 |
} |
|
168 |
else |
|
169 |
if (firstElement != null && firstElement instanceof IAdaptable) |
|
170 |
{ |
|
171 |
IFile file = (IFile) ((IAdaptable) firstElement).getAdapter(IFile.class); |
|
172 |
if (file != null) |
|
173 |
{ |
|
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 | 176 |
{ |
177 |
defaultMMP = filePath; |
|
178 |
} |
|
179 |
Executable executable = new Executable(file.getLocation(), file.getProject(), file); |
|
180 |
return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), executable, defaultMMP); |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
186 |
if (projects.size() > 0) { |
|
187 |
return LaunchPlugin.getDefault().getLaunchConfigurations(projects.get(0), null, defaultMMP); |
|
188 |
} |
|
189 |
return null; |
|
190 |
} |
|
191 |
||
192 |
public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart editorpart) { |
|
193 |
IEditorInput editorInput = editorpart.getEditorInput(); |
|
194 |
if (editorInput instanceof IFileEditorInput) { |
|
195 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
196 |
if (file != null) { |
|
197 |
return LaunchPlugin.getDefault().getLaunchConfigurations(file.getProject(), null, null); |
|
198 |
} |
|
199 |
} |
|
200 |
return null; |
|
201 |
} |
|
202 |
||
203 |
public IResource getLaunchableResource(ISelection selection) { |
|
204 |
if (selection instanceof IStructuredSelection) { |
|
205 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
206 |
if (firstElement != null && firstElement instanceof IFile) |
|
207 |
{ |
|
208 |
IFile file = (IFile) firstElement; |
|
209 |
return file.getProject(); |
|
210 |
} |
|
211 |
if (firstElement != null && firstElement instanceof Executable) |
|
212 |
{ |
|
213 |
return ((Executable)firstElement).getProject(); |
|
214 |
} |
|
215 |
} |
|
216 |
List<IProject> projects = CarbideBuilderPlugin.getProjectsFromSelection(selection); |
|
217 |
if (projects.size() > 0) { |
|
218 |
return projects.get(0); |
|
219 |
} |
|
220 |
return null; |
|
221 |
} |
|
222 |
||
223 |
public IResource getLaunchableResource(IEditorPart editorpart) { |
|
224 |
IEditorInput editorInput = editorpart.getEditorInput(); |
|
225 |
if (editorInput instanceof IFileEditorInput) { |
|
226 |
IFile file = ((IFileEditorInput)editorInput).getFile(); |
|
227 |
if (file != null) { |
|
228 |
return file.getProject(); |
|
229 |
} |
|
230 |
} |
|
231 |
return null; |
|
232 |
} |
|
233 |
} |