org.eclipse.debug.ui,
org.eclipse.jdt.core,
org.eclipse.ui.console,
- org.eclipse.jdt.debug.ui
+ org.eclipse.jdt.debug.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.core.variables
Eclipse-LazyStart: true
</extension>\r
<extension\r
point="org.eclipse.debug.ui.launchShortcuts">\r
- <shortcut\r
- class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcut"\r
- icon="icons/slcScriptLaunch.gif"\r
- id="org.argeo.slc.ui.launch.slcScriptLaunchShortcut"\r
- label="SLC script"\r
- modes="run,debug">\r
- \r
- <contextualLaunch>\r
- <enablement>\r
- <with variable="selection">\r
- <count value="1"/>\r
- <iterate>\r
- <or>\r
- <test property="org.eclipse.debug.ui.matchesPattern" value="*.xml"/>\r
- </or>\r
- </iterate>\r
- </with>\r
- </enablement>\r
- </contextualLaunch>\r
- \r
- </shortcut>\r
+ <shortcut
+ class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcut"
+ icon="icons/slcScriptLaunch.gif"
+ id="org.argeo.slc.ui.launch.slcScriptLaunchShortcut"
+ label="SLC script"
+ modes="run,debug">
+
+ <contextualLaunch>
+ <enablement>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate>
+ <or>
+ <test property="org.eclipse.debug.ui.matchesPattern" value="*.xml"/>
+ </or>
+ </iterate>
+ </with>
+ </enablement>
+ </contextualLaunch>
+ </shortcut>
+ <shortcut
+ class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcutWithDialog"
+ icon="icons/slcScriptLaunch.gif"
+ id="org.argeo.slc.ui.launch.slcScriptLaunchShortcutWithDialog"
+ label="SLC script..."
+ modes="run,debug">
+
+ <contextualLaunch>
+ <enablement>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate>
+ <or>
+ <test property="org.eclipse.debug.ui.matchesPattern" value="*.xml"/>
+ </or>
+ </iterate>
+ </with>
+ </enablement>
+ </contextualLaunch>
+ </shortcut>
</extension>\r
<extension\r
point="org.eclipse.debug.ui.launchConfigurationTabGroups">\r
package org.argeo.slc.ui.launch.script;\r
\r
-import org.eclipse.core.resources.IFile;\r
+import org.eclipse.core.resources.IResource;\r
+import org.eclipse.core.resources.ResourcesPlugin;\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.debug.core.ILaunchConfiguration;\r
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;\r
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;\r
+import org.eclipse.jface.window.Window;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.events.ModifyEvent;\r
import org.eclipse.swt.events.ModifyListener;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Label;\r
import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.dialogs.ResourceSelectionDialog;\r
\r
public class SlcScriptLaunchConfigurationTab extends\r
AbstractLaunchConfigurationTab {\r
\r
- private Text scriptL;\r
+ private Text scriptTF;\r
private Text propertiesTF;\r
private Text runtimeTF;\r
private Text targetsTF;\r
body.setFont(parent.getFont());\r
\r
createLabel(body, "Script location");\r
- scriptL = createSingleText(body);\r
- scriptL.setEditable(false);\r
- scriptL.setBackground(body.getBackground());\r
+ scriptTF = createSingleText(body);\r
+ createWorkspaceButton(body);\r
\r
createLabel(body, "Runtime");\r
runtimeTF = createSingleText(body);\r
\r
public void initializeFrom(ILaunchConfiguration configuration) {\r
try {\r
- IFile script = (IFile) configuration.getMappedResources()[0];\r
- scriptL.setText(script.getLocation().toFile().getAbsolutePath());\r
+ scriptTF.setText(configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_SCRIPT, ""));\r
\r
boolean pre093 = configuration.getAttribute(\r
- SlcScriptLaunchDelegate.ATTR_PRE093, false);\r
+ SlcScriptUtils.ATTR_PRE093, false);\r
\r
propertiesTF.setText(configuration.getAttribute(\r
- SlcScriptLaunchDelegate.ATTR_PROPERTIES, ""));\r
+ SlcScriptUtils.ATTR_PROPERTIES, ""));\r
runtimeTF.setText(configuration.getAttribute(\r
- SlcScriptLaunchDelegate.ATTR_RUNTIME, ""));\r
+ SlcScriptUtils.ATTR_RUNTIME, ""));\r
targetsTF.setText(configuration.getAttribute(\r
- SlcScriptLaunchDelegate.ATTR_TARGETS, ""));\r
+ SlcScriptUtils.ATTR_TARGETS, ""));\r
pre093B.setSelection(pre093);\r
} catch (CoreException e) {\r
throw new RuntimeException("Cannot initialize tab", e);\r
}\r
\r
public void performApply(ILaunchConfigurationWorkingCopy configuration) {\r
- configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PROPERTIES,\r
- propertiesTF.getText());\r
- configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_RUNTIME,\r
- runtimeTF.getText());\r
- configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_TARGETS,\r
- targetsTF.getText());\r
- configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PRE093, pre093B\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_SCRIPT, scriptTF\r
+ .getText());\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_PROPERTIES, propertiesTF\r
+ .getText());\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_RUNTIME, runtimeTF\r
+ .getText());\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_TARGETS, targetsTF\r
+ .getText());\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_PRE093, pre093B\r
.getSelection());\r
}\r
\r
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_SCRIPT, "");\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_PROPERTIES, "");\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_RUNTIME, "");\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_TARGETS, "");\r
+ configuration.setAttribute(SlcScriptUtils.ATTR_PRE093, false);\r
}\r
\r
// UI Utils\r
\r
}\r
\r
+ protected Button createWorkspaceButton(Composite parent) {\r
+ Button b = new Button(parent, SWT.PUSH);\r
+ b.setFont(parent.getFont());\r
+ b.setText("Workspace...");\r
+ b.addSelectionListener(new SelectionListener() {\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ }\r
+\r
+ public void widgetSelected(SelectionEvent e) {\r
+ handleWorkspaceLocationButtonSelected();\r
+ }\r
+ });\r
+ return b;\r
+ }\r
+\r
+ protected void handleWorkspaceLocationButtonSelected() {\r
+ ResourceSelectionDialog dialog;\r
+ dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin\r
+ .getWorkspace().getRoot(), "Select a file");\r
+ if (dialog.open() == Window.OK) {\r
+ Object[] results = dialog.getResult();\r
+ if (results == null || results.length < 1) {\r
+ return;\r
+ }\r
+ IResource resource = (IResource) results[0];\r
+ scriptTF.setText(SlcScriptUtils\r
+ .convertToWorkspaceLocation(resource));\r
+ updateLaunchConfigurationDialog();\r
+ }\r
+ }\r
+\r
// LISTENERS\r
/**\r
* Modify listener that simply updates the owning launch configuration\r
import org.argeo.slc.ui.launch.preferences.SlcPreferencePage;\r
import org.eclipse.core.resources.IFile;\r
import org.eclipse.core.resources.IProject;\r
-import org.eclipse.core.resources.IResource;\r
+import org.eclipse.core.resources.ResourcesPlugin;\r
import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IPath;\r
import org.eclipse.core.runtime.IProgressMonitor;\r
import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Path;\r
import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.variables.IStringVariableManager;\r
+import org.eclipse.core.variables.VariablesPlugin;\r
import org.eclipse.debug.core.ILaunch;\r
import org.eclipse.debug.core.ILaunchConfiguration;\r
import org.eclipse.debug.core.ILaunchManager;\r
AbstractJavaLaunchConfigurationDelegate {\r
public static final String ID = "org.argeo.slc.launch.slcScriptLaunchType";\r
\r
- public final static String ATTR_SCRIPT = "script";\r
- public final static String ATTR_PROPERTIES = "properties";\r
- public final static String ATTR_RUNTIME = "runtime";\r
- public final static String ATTR_TARGETS = "targets";\r
- public final static String ATTR_PRE093 = "pre093";\r
-\r
public final static String ANT_MAIN = "org.apache.tools.ant.Main";\r
public final static String SLC_MAIN = "org.argeo.slc.cli.SlcMain";\r
\r
public void launch(ILaunchConfiguration configuration, String mode,\r
ILaunch launch, IProgressMonitor monitor) throws CoreException {\r
- IResource[] resources = configuration.getMappedResources();\r
+ if (!saveBeforeLaunch(configuration, mode, monitor))\r
+ return;\r
\r
- if (resources.length != 1) {\r
- throw new RuntimeException("Can only launch one script.");\r
- }\r
- if (!(resources[0] instanceof IFile)) {\r
- throw new RuntimeException("Can only launch file.");\r
- }\r
- IFile file = (IFile) resources[0];\r
- System.out.println("Launched " + file.getLocation().toFile());\r
+ String scriptLocation = configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_SCRIPT, "");\r
+ if (scriptLocation.equals(""))\r
+ abort("Script has to be provided", null, 1);\r
+\r
+ IStringVariableManager manager = VariablesPlugin.getDefault()\r
+ .getStringVariableManager();\r
+ scriptLocation = manager.performStringSubstitution(scriptLocation);\r
+ System.out.println("Script location " + scriptLocation);\r
+\r
+ IPath path = new Path(scriptLocation);\r
+ System.out.println("Script path " + path);\r
+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot()\r
+ .findFilesForLocation(path);\r
+\r
+ if (files.length == 0)\r
+ abort("Coulkd not find related file", null, 1);\r
+\r
+ IFile file = (IFile) files[0];\r
+ System.out.println("Launching " + file.getLocation().toFile());\r
\r
- boolean pre093 = configuration.getAttribute(ATTR_PRE093, false);\r
+ boolean pre093 = configuration.getAttribute(SlcScriptUtils.ATTR_PRE093,\r
+ false);\r
\r
// Retrieve SLC Runtime\r
SlcSystem slcSystem = findSlcSystem(file, pre093);\r
list.add(file.getLocation().toFile().getAbsolutePath());\r
\r
// Runtime\r
- String runtime = configuration.getAttribute(ATTR_RUNTIME, "");\r
+ String runtime = configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_RUNTIME, "");\r
if (!runtime.equals("")) {\r
list.add("--runtime");\r
list.add(runtime);\r
}\r
\r
// Targets\r
- String targets = configuration.getAttribute(ATTR_RUNTIME, "");\r
+ String targets = configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_TARGETS, "");\r
if (!runtime.equals("")) {\r
list.add("--targets");\r
list.add(targets);\r
// Properties\r
Properties properties = new Properties();\r
StringReader reader = new StringReader(configuration.getAttribute(\r
- ATTR_PROPERTIES, ""));\r
+ SlcScriptUtils.ATTR_PROPERTIES, ""));\r
try {\r
properties.load(reader);\r
} catch (IOException e) {\r
\r
import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;\r
import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IResource;\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.core.runtime.IPath;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
import org.eclipse.debug.core.DebugPlugin;\r
import org.eclipse.debug.core.ILaunchConfiguration;\r
import org.eclipse.debug.core.ILaunchConfigurationType;\r
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;\r
import org.eclipse.debug.core.ILaunchManager;\r
+import org.eclipse.debug.ui.DebugUITools;\r
+import org.eclipse.debug.ui.IDebugUIConstants;\r
import org.eclipse.debug.ui.ILaunchShortcut;\r
import org.eclipse.jface.dialogs.ErrorDialog;\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.ui.IEditorPart;\r
\r
public class SlcScriptLaunchShortcut implements ILaunchShortcut {\r
+ private boolean showDialog = false;\r
\r
public void launch(ISelection selection, String mode) {\r
try {\r
.getLaunchConfigurationType(SlcScriptLaunchDelegate.ID);\r
\r
// Find or create config\r
- ILaunchConfiguration config = findLaunchConfiguration(file, manager\r
- .getLaunchConfigurations(type));\r
+ String configLocation = SlcScriptUtils\r
+ .convertToWorkspaceLocation(file);\r
+ ILaunchConfiguration config = findLaunchConfiguration(\r
+ configLocation, manager.getLaunchConfigurations(type));\r
if (config == null) {\r
ILaunchConfigurationWorkingCopy wc = type.newInstance(null,\r
generateName(file));\r
+ wc.setAttribute(SlcScriptUtils.ATTR_SCRIPT, configLocation);\r
wc.setMappedResources(new IFile[] { file });\r
config = wc.doSave();\r
}\r
- \r
+\r
// Launch\r
- config.launch(mode, null);\r
+ launch(config, mode);\r
} catch (CoreException e) {\r
Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench()\r
.getActiveWorkbenchWindow().getShell();\r
return name;\r
}\r
\r
- protected ILaunchConfiguration findLaunchConfiguration(IFile file,\r
- ILaunchConfiguration[] configs) throws CoreException {\r
+ protected ILaunchConfiguration findLaunchConfiguration(\r
+ String configLocation, ILaunchConfiguration[] configs)\r
+ throws CoreException {\r
for (ILaunchConfiguration config : configs) {\r
- IResource[] res = config.getMappedResources();\r
- if (res.length > 1) {\r
- IFile fileT = (IFile) res[0];\r
- if (fileT.equals(file)) {\r
- return config;\r
- }\r
+ String loc = config.getAttribute(SlcScriptUtils.ATTR_SCRIPT, "");\r
+ if (loc.equals(configLocation)) {\r
+ return config;\r
}\r
}\r
return null;\r
}\r
\r
+ protected void launch(ILaunchConfiguration configuration, String mode)\r
+ throws CoreException {\r
+ if (showDialog) {\r
+ IStatus status = new Status(IStatus.INFO, SlcUiLaunchPlugin.ID,\r
+ "Configure SLC Launch");\r
+ String groupId;\r
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {\r
+ groupId = IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP;\r
+ } else {\r
+ groupId = IDebugUIConstants.ID_RUN_LAUNCH_GROUP;\r
+ }\r
+ DebugUITools.openLaunchConfigurationDialog(SlcUiLaunchPlugin\r
+ .getDefault().getWorkbench().getActiveWorkbenchWindow()\r
+ .getShell(), configuration, groupId, status);\r
+ } else {\r
+ DebugUITools.launch(configuration, mode);\r
+ }\r
+\r
+ }\r
+\r
public void launch(IEditorPart editor, String mode) {\r
// not (yet) implemented\r
}\r
\r
+ public void setShowDialog(boolean showDialog) {\r
+ this.showDialog = showDialog;\r
+ }\r
+\r
}\r
--- /dev/null
+package org.argeo.slc.ui.launch.script;\r
+\r
+\r
+public class SlcScriptLaunchShortcutWithDialog extends SlcScriptLaunchShortcut {\r
+\r
+ public SlcScriptLaunchShortcutWithDialog() {\r
+ super();\r
+ setShowDialog(true);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.argeo.slc.ui.launch.script;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.variables.VariablesPlugin;
+
+public class SlcScriptUtils {
+
+ public final static String ATTR_SCRIPT = "script";
+ public final static String ATTR_PROPERTIES = "properties";
+ public final static String ATTR_RUNTIME = "runtime";
+ public final static String ATTR_TARGETS = "targets";
+ public final static String ATTR_PRE093 = "pre093";
+
+ public static String convertToWorkspaceLocation(IResource resource) {
+ return VariablesPlugin.getDefault().getStringVariableManager()
+ .generateVariableExpression("workspace_loc",
+ resource.getFullPath().toString());
+ }
+
+ private SlcScriptUtils() {
+
+ }
+}