1 package org
.argeo
.slc
.ide
.ui
.launch
.script
;
3 import org
.argeo
.slc
.ide
.ui
.SlcIdeUiPlugin
;
4 import org
.eclipse
.core
.resources
.IFile
;
5 import org
.eclipse
.core
.runtime
.CoreException
;
6 import org
.eclipse
.core
.runtime
.IPath
;
7 import org
.eclipse
.core
.runtime
.IStatus
;
8 import org
.eclipse
.core
.runtime
.Status
;
9 import org
.eclipse
.debug
.core
.DebugPlugin
;
10 import org
.eclipse
.debug
.core
.ILaunchConfiguration
;
11 import org
.eclipse
.debug
.core
.ILaunchConfigurationType
;
12 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
13 import org
.eclipse
.debug
.core
.ILaunchManager
;
14 import org
.eclipse
.debug
.ui
.DebugUITools
;
15 import org
.eclipse
.debug
.ui
.IDebugUIConstants
;
16 import org
.eclipse
.debug
.ui
.ILaunchShortcut
;
17 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.ui
.IEditorPart
;
23 public class SlcScriptLaunchShortcut
implements ILaunchShortcut
{
24 private boolean showDialog
= false;
26 public void launch(ISelection selection
, String mode
) {
28 if (!(selection
instanceof IStructuredSelection
)) {
29 throw new RuntimeException("Unknown selection "
30 + selection
.getClass());
32 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
33 if (sSelection
.size() != 1) {
34 throw new RuntimeException("Can only launch one SLC script.");
36 Object obj
= sSelection
.iterator().next();
37 if (!(obj
instanceof IFile
)) {
38 throw new RuntimeException("Can only launch files.");
40 IFile file
= ((IFile
) obj
);
42 ILaunchManager manager
= DebugPlugin
.getDefault()
44 ILaunchConfigurationType type
= manager
45 .getLaunchConfigurationType(SlcScriptLaunchDelegate
.ID
);
47 // Find or create config
48 String configLocation
= SlcScriptUtils
49 .convertToWorkspaceLocation(file
);
50 ILaunchConfiguration config
= findLaunchConfiguration(
51 configLocation
, manager
.getLaunchConfigurations(type
));
53 ILaunchConfigurationWorkingCopy wc
= type
.newInstance(null,
55 wc
.setAttribute(SlcScriptUtils
.ATTR_SCRIPT
, configLocation
);
56 wc
.setMappedResources(new IFile
[] { file
});
62 } catch (CoreException e
) {
63 Shell shell
= SlcIdeUiPlugin
.getDefault().getWorkbench()
64 .getActiveWorkbenchWindow().getShell();
65 ErrorDialog
.openError(shell
, "Error",
66 "Cannot execute SLC launch shortcut", e
.getStatus());
71 protected String
generateName(IFile file
) {
72 IPath relativePath
= file
.getProjectRelativePath();
73 String name
= relativePath
.toString();
74 int idx
= name
.lastIndexOf(".xml");
76 name
= name
.substring(0, idx
);
78 if (name
.startsWith("src/main/slc/root/"))
79 name
= name
.substring("src/main/slc/root/".length());
80 else if (name
.startsWith("src/main/slc/"))
81 name
= name
.substring("src/main/slc/".length());
83 name
= name
.replace('/', '.');// otherwise not properly saved
87 protected ILaunchConfiguration
findLaunchConfiguration(
88 String configLocation
, ILaunchConfiguration
[] configs
)
89 throws CoreException
{
90 for (ILaunchConfiguration config
: configs
) {
91 String loc
= config
.getAttribute(SlcScriptUtils
.ATTR_SCRIPT
, "");
92 if (loc
.equals(configLocation
)) {
99 protected void launch(ILaunchConfiguration configuration
, String mode
)
100 throws CoreException
{
102 IStatus status
= new Status(IStatus
.INFO
, SlcIdeUiPlugin
.ID
,
103 "Configure SLC Launch");
105 if (mode
.equals(ILaunchManager
.DEBUG_MODE
)) {
106 groupId
= IDebugUIConstants
.ID_DEBUG_LAUNCH_GROUP
;
108 groupId
= IDebugUIConstants
.ID_RUN_LAUNCH_GROUP
;
110 DebugUITools
.openLaunchConfigurationDialog(SlcIdeUiPlugin
111 .getDefault().getWorkbench().getActiveWorkbenchWindow()
112 .getShell(), configuration
, groupId
, status
);
114 DebugUITools
.launch(configuration
, mode
);
119 public void launch(IEditorPart editor
, String mode
) {
120 // not (yet) implemented
123 public void setShowDialog(boolean showDialog
) {
124 this.showDialog
= showDialog
;