Improve ergonomics
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 29 Jun 2008 13:16:28 +0000 (13:16 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 29 Jun 2008 13:16:28 +0000 (13:16 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1324 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcutWithDialog.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptUtils.java [new file with mode: 0644]

index 54b67af0d7320e5cd56ce583178379b14452b5fb..1f0acfd14b7a78f24f4ed438930dbb082d427dd4 100644 (file)
@@ -11,5 +11,7 @@ Require-Bundle: org.eclipse.ui,
  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
index 6dc3226c303459e94b9bd9b0d4450d805e75b989..da77f3a96ccefd4c7c8c83dbe9e28d30d9a3c730 100644 (file)
 </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
index d7998669032aaaa432e3a594dbc5793aa5390900..be957302cf8713304ae1f23b15270739c5100ec9 100644 (file)
@@ -1,10 +1,12 @@
 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
@@ -16,11 +18,12 @@ import org.eclipse.swt.widgets.Button;
 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
@@ -33,9 +36,8 @@ public class SlcScriptLaunchConfigurationTab extends
                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
@@ -55,18 +57,18 @@ public class SlcScriptLaunchConfigurationTab extends
 \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
@@ -75,17 +77,24 @@ public class SlcScriptLaunchConfigurationTab extends
        }\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
@@ -129,6 +138,37 @@ public class SlcScriptLaunchConfigurationTab extends
 \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
index a6569b911a582176720ed236dee97115a22f8226..dfd956177dfce70cc8ecae8e9017be16733b6b4f 100644 (file)
@@ -13,11 +13,15 @@ import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;
 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
@@ -35,29 +39,37 @@ public class SlcScriptLaunchDelegate extends
                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
@@ -153,14 +165,16 @@ public class SlcScriptLaunchDelegate extends
                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
@@ -169,7 +183,7 @@ public class SlcScriptLaunchDelegate extends
                // 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
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
diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcutWithDialog.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcutWithDialog.java
new file mode 100644 (file)
index 0000000..ae12ed0
--- /dev/null
@@ -0,0 +1,11 @@
+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
diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptUtils.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptUtils.java
new file mode 100644 (file)
index 0000000..76a684f
--- /dev/null
@@ -0,0 +1,23 @@
+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() {
+
+       }
+}