author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 23 Aug 2010 09:55:57 -0700 | |
changeset 471 | 06589bf52fa7 |
permissions | -rw-r--r-- |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
* Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
* Description: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
* Overview: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
* Details: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
* Failures and causes: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
*******************************************************************************/ |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
package org.symbian.tools.tmw.debug.ui.launch; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
import org.eclipse.core.resources.IProject; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
import org.eclipse.core.resources.IResource; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
import org.eclipse.core.runtime.CoreException; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
import org.eclipse.core.runtime.IAdaptable; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
import org.eclipse.debug.core.DebugPlugin; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
import org.eclipse.debug.core.ILaunchConfiguration; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
import org.eclipse.debug.core.ILaunchConfigurationType; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
import org.eclipse.debug.core.ILaunchManager; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
import org.eclipse.debug.ui.DebugUITools; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
import org.eclipse.debug.ui.ILaunchShortcut2; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
import org.eclipse.jface.viewers.ISelection; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
import org.eclipse.jface.viewers.IStructuredSelection; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
import org.eclipse.ui.IEditorInput; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
35 |
import org.eclipse.ui.IEditorPart; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
import org.symbian.tools.tmw.debug.internal.Activator; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
import org.symbian.tools.tmw.debug.internal.IConstants; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
import org.symbian.tools.tmw.debug.internal.launch.WidgetLaunchDelegate; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
public class WidgetLaunchShortcut implements ILaunchShortcut2 { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
public IResource getLaunchableResource(IEditorPart editorpart) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
IEditorInput input = editorpart.getEditorInput(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
return (IResource) input.getAdapter(IResource.class); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
public IResource getLaunchableResource(ISelection selection) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
48 |
if (!selection.isEmpty() && selection instanceof IStructuredSelection) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
Object object = ((IStructuredSelection) selection).getFirstElement(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
IResource resource = null; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
if (object instanceof IResource) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
resource = (IResource) object; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
} else if (object instanceof IAdaptable) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
resource = (IResource) ((IAdaptable) object).getAdapter(IResource.class); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
return resource; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
return null; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart editorpart) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
return getLaunchConfigurations(getLaunchableResource(editorpart)); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
65 |
private ILaunchConfiguration getLaunchConfigurations(IProject project) throws CoreException { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(WidgetLaunchDelegate.ID); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
68 |
ILaunchConfiguration configuration = null; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
ILaunchConfiguration[] configurations = launchManager.getLaunchConfigurations(type); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
for (ILaunchConfiguration c : configurations) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
if (project.getName().equals(c.getAttribute(IConstants.PROP_PROJECT_NAME, (String) null))) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
configuration = c; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
break; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
74 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
75 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
76 |
return configuration; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
79 |
private ILaunchConfiguration[] getLaunchConfigurations(IResource resource) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
if (resource != null) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
try { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
ILaunchConfiguration launchConfigurations = getLaunchConfigurations(resource.getProject()); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
if (launchConfigurations != null) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
return new ILaunchConfiguration[] { launchConfigurations }; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
86 |
} catch (CoreException e) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
Activator.log(e); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
88 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
89 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
90 |
return null; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
public ILaunchConfiguration[] getLaunchConfigurations(ISelection selection) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
return getLaunchConfigurations(getLaunchableResource(selection)); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
public void launch(IEditorPart editor, String mode) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
launch(getLaunchableResource(editor), mode); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
private void launch(IResource launchableResource, String mode) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
try { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
103 |
IProject project = launchableResource.getProject(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
104 |
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(WidgetLaunchDelegate.ID); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
106 |
ILaunchConfiguration configuration = getLaunchConfigurations(project); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
107 |
if (configuration == null) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
108 |
ILaunchConfigurationWorkingCopy copy = type.newInstance(null, launchManager |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
109 |
.generateLaunchConfigurationName(project.getName())); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
110 |
copy.setAttribute(IConstants.PROP_PROJECT_NAME, project.getName()); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
111 |
copy.setMappedResources(new IResource[] { project }); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
112 |
configuration = copy.doSave(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
113 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
114 |
DebugUITools.launch(configuration, mode); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
115 |
} catch (CoreException e) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
116 |
Activator.log(e); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
117 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
118 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
119 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
120 |
public void launch(ISelection selection, String mode) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
121 |
launch(getLaunchableResource(selection), mode); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
122 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
123 |
} |