]> git.argeo.org Git - gpl/argeo-slc.git/blob - SlcScriptLaunchShortcut.java
b25d303466d17ed3090a123980d0bf769860b8f4
[gpl/argeo-slc.git] / SlcScriptLaunchShortcut.java
1 package org.argeo.slc.ui.launch.script;
2
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;
16
17 public class SlcScriptLaunchShortcut implements ILaunchShortcut {
18
19 public void launch(ISelection selection, String mode) {
20 try {
21 if (!(selection instanceof IStructuredSelection)) {
22 throw new RuntimeException("Unknown selection "
23 + selection.getClass());
24 }
25 IStructuredSelection sSelection = (IStructuredSelection) selection;
26 if (sSelection.size() != 1) {
27 throw new RuntimeException("Can only launch one SLC script.");
28 }
29 Object obj = sSelection.iterator().next();
30 if (!(obj instanceof IFile)) {
31 throw new RuntimeException("Can only launch files.");
32 }
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
38
39 System.out.println(name);
40
41 ILaunchManager manager = DebugPlugin.getDefault()
42 .getLaunchManager();
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) {
50 e.printStackTrace();
51 }
52
53 }
54
55 public void launch(IEditorPart editor, String mode) {
56 // not (yet) implemented
57 }
58
59 }