1 package org
.argeo
.slc
.ui
.launch
.script
;
3 import org
.eclipse
.core
.resources
.IFile
;
4 import org
.eclipse
.core
.resources
.IProject
;
5 import org
.eclipse
.core
.runtime
.CoreException
;
6 import org
.eclipse
.core
.runtime
.IPath
;
7 import org
.eclipse
.debug
.core
.DebugPlugin
;
8 import org
.eclipse
.debug
.core
.ILaunchConfiguration
;
9 import org
.eclipse
.debug
.core
.ILaunchConfigurationType
;
10 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
11 import org
.eclipse
.debug
.core
.ILaunchManager
;
12 import org
.eclipse
.debug
.ui
.ILaunchShortcut
;
13 import org
.eclipse
.jface
.viewers
.ISelection
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.ui
.IEditorPart
;
17 public class SlcScriptLaunchShortcut
implements ILaunchShortcut
{
19 public void launch(ISelection selection
, String mode
) {
21 if (!(selection
instanceof IStructuredSelection
)) {
22 throw new RuntimeException("Unknown selection "
23 + selection
.getClass());
25 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
26 if (sSelection
.size() != 1) {
27 throw new RuntimeException("Can only launch one SLC script.");
29 Object obj
= sSelection
.iterator().next();
30 if (!(obj
instanceof IFile
)) {
31 throw new RuntimeException("Can only launch files.");
33 IFile file
= ((IFile
) obj
);
34 IProject project
= file
.getProject();
35 IPath relativePath
= file
.getProjectRelativePath();
36 String name
= "["+project
.getName() + "] - " + relativePath
.toString();
37 name
= name
.replace('/', '_');// otherwise not properly saved
39 System
.out
.println(name
);
41 ILaunchManager manager
= DebugPlugin
.getDefault()
43 ILaunchConfigurationType type
= manager
44 .getLaunchConfigurationType(SlcScriptLaunchDelegate
.ID
);
45 ILaunchConfigurationWorkingCopy wc
= type
.newInstance(null, name
);
46 wc
.setMappedResources(new IFile
[] { file
});
47 ILaunchConfiguration config
= wc
.doSave();
48 config
.launch(mode
, null);
49 } catch (CoreException e
) {
55 public void launch(IEditorPart editor
, String mode
) {
56 // not (yet) implemented