]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java
Improve ergonomics
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ui.launch / src / main / java / org / argeo / slc / ui / launch / script / SlcScriptLaunchShortcut.java
index a5311ed2d8fb3241206839f84def168875efd2fc..755ba760b54f71f4f4cf79f8b6a7ac60ad9fe519 100644 (file)
@@ -2,14 +2,17 @@ package org.argeo.slc.ui.launch.script;
 \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
@@ -18,6 +21,7 @@ import org.eclipse.swt.widgets.Shell;
 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
@@ -41,17 +45,20 @@ public class SlcScriptLaunchShortcut implements ILaunchShortcut {
                                        .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
@@ -77,22 +84,44 @@ public class SlcScriptLaunchShortcut implements ILaunchShortcut {
                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