From de2e12af3fe6250ab511099652dc3d90243c01a3 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 29 Jun 2008 13:16:28 +0000 Subject: [PATCH] Improve ergonomics git-svn-id: https://svn.argeo.org/slc/trunk@1324 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 4 +- .../org.argeo.slc.ui.launch/plugin.xml | 61 ++++++++++----- .../SlcScriptLaunchConfigurationTab.java | 76 ++++++++++++++----- .../script/SlcScriptLaunchDelegate.java | 54 ++++++++----- .../script/SlcScriptLaunchShortcut.java | 55 ++++++++++---- .../SlcScriptLaunchShortcutWithDialog.java | 11 +++ .../slc/ui/launch/script/SlcScriptUtils.java | 23 ++++++ 7 files changed, 211 insertions(+), 73 deletions(-) create mode 100644 eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcutWithDialog.java create mode 100644 eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptUtils.java diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF index 54b67af0d..1f0acfd14 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF @@ -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 diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml b/eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml index 6dc3226c3..da77f3a96 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml @@ -11,27 +11,46 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java index d79986690..be957302c 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java @@ -1,10 +1,12 @@ package org.argeo.slc.ui.launch.script; -import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -16,11 +18,12 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ResourceSelectionDialog; public class SlcScriptLaunchConfigurationTab extends AbstractLaunchConfigurationTab { - private Text scriptL; + private Text scriptTF; private Text propertiesTF; private Text runtimeTF; private Text targetsTF; @@ -33,9 +36,8 @@ public class SlcScriptLaunchConfigurationTab extends body.setFont(parent.getFont()); createLabel(body, "Script location"); - scriptL = createSingleText(body); - scriptL.setEditable(false); - scriptL.setBackground(body.getBackground()); + scriptTF = createSingleText(body); + createWorkspaceButton(body); createLabel(body, "Runtime"); runtimeTF = createSingleText(body); @@ -55,18 +57,18 @@ public class SlcScriptLaunchConfigurationTab extends public void initializeFrom(ILaunchConfiguration configuration) { try { - IFile script = (IFile) configuration.getMappedResources()[0]; - scriptL.setText(script.getLocation().toFile().getAbsolutePath()); + scriptTF.setText(configuration.getAttribute( + SlcScriptUtils.ATTR_SCRIPT, "")); boolean pre093 = configuration.getAttribute( - SlcScriptLaunchDelegate.ATTR_PRE093, false); + SlcScriptUtils.ATTR_PRE093, false); propertiesTF.setText(configuration.getAttribute( - SlcScriptLaunchDelegate.ATTR_PROPERTIES, "")); + SlcScriptUtils.ATTR_PROPERTIES, "")); runtimeTF.setText(configuration.getAttribute( - SlcScriptLaunchDelegate.ATTR_RUNTIME, "")); + SlcScriptUtils.ATTR_RUNTIME, "")); targetsTF.setText(configuration.getAttribute( - SlcScriptLaunchDelegate.ATTR_TARGETS, "")); + SlcScriptUtils.ATTR_TARGETS, "")); pre093B.setSelection(pre093); } catch (CoreException e) { throw new RuntimeException("Cannot initialize tab", e); @@ -75,17 +77,24 @@ public class SlcScriptLaunchConfigurationTab extends } public void performApply(ILaunchConfigurationWorkingCopy configuration) { - configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PROPERTIES, - propertiesTF.getText()); - configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_RUNTIME, - runtimeTF.getText()); - configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_TARGETS, - targetsTF.getText()); - configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PRE093, pre093B + configuration.setAttribute(SlcScriptUtils.ATTR_SCRIPT, scriptTF + .getText()); + configuration.setAttribute(SlcScriptUtils.ATTR_PROPERTIES, propertiesTF + .getText()); + configuration.setAttribute(SlcScriptUtils.ATTR_RUNTIME, runtimeTF + .getText()); + configuration.setAttribute(SlcScriptUtils.ATTR_TARGETS, targetsTF + .getText()); + configuration.setAttribute(SlcScriptUtils.ATTR_PRE093, pre093B .getSelection()); } public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + configuration.setAttribute(SlcScriptUtils.ATTR_SCRIPT, ""); + configuration.setAttribute(SlcScriptUtils.ATTR_PROPERTIES, ""); + configuration.setAttribute(SlcScriptUtils.ATTR_RUNTIME, ""); + configuration.setAttribute(SlcScriptUtils.ATTR_TARGETS, ""); + configuration.setAttribute(SlcScriptUtils.ATTR_PRE093, false); } // UI Utils @@ -129,6 +138,37 @@ public class SlcScriptLaunchConfigurationTab extends } + protected Button createWorkspaceButton(Composite parent) { + Button b = new Button(parent, SWT.PUSH); + b.setFont(parent.getFont()); + b.setText("Workspace..."); + b.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + + public void widgetSelected(SelectionEvent e) { + handleWorkspaceLocationButtonSelected(); + } + }); + return b; + } + + protected void handleWorkspaceLocationButtonSelected() { + ResourceSelectionDialog dialog; + dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin + .getWorkspace().getRoot(), "Select a file"); + if (dialog.open() == Window.OK) { + Object[] results = dialog.getResult(); + if (results == null || results.length < 1) { + return; + } + IResource resource = (IResource) results[0]; + scriptTF.setText(SlcScriptUtils + .convertToWorkspaceLocation(resource)); + updateLaunchConfigurationDialog(); + } + } + // LISTENERS /** * Modify listener that simply updates the owning launch configuration diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java index a6569b911..dfd956177 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java @@ -13,11 +13,15 @@ import org.argeo.slc.ui.launch.SlcUiLaunchPlugin; import org.argeo.slc.ui.launch.preferences.SlcPreferencePage; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.core.variables.IStringVariableManager; +import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; @@ -35,29 +39,37 @@ public class SlcScriptLaunchDelegate extends AbstractJavaLaunchConfigurationDelegate { public static final String ID = "org.argeo.slc.launch.slcScriptLaunchType"; - 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 final static String ANT_MAIN = "org.apache.tools.ant.Main"; public final static String SLC_MAIN = "org.argeo.slc.cli.SlcMain"; public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { - IResource[] resources = configuration.getMappedResources(); + if (!saveBeforeLaunch(configuration, mode, monitor)) + return; - if (resources.length != 1) { - throw new RuntimeException("Can only launch one script."); - } - if (!(resources[0] instanceof IFile)) { - throw new RuntimeException("Can only launch file."); - } - IFile file = (IFile) resources[0]; - System.out.println("Launched " + file.getLocation().toFile()); + String scriptLocation = configuration.getAttribute( + SlcScriptUtils.ATTR_SCRIPT, ""); + if (scriptLocation.equals("")) + abort("Script has to be provided", null, 1); + + IStringVariableManager manager = VariablesPlugin.getDefault() + .getStringVariableManager(); + scriptLocation = manager.performStringSubstitution(scriptLocation); + System.out.println("Script location " + scriptLocation); + + IPath path = new Path(scriptLocation); + System.out.println("Script path " + path); + IFile[] files = ResourcesPlugin.getWorkspace().getRoot() + .findFilesForLocation(path); + + if (files.length == 0) + abort("Coulkd not find related file", null, 1); + + IFile file = (IFile) files[0]; + System.out.println("Launching " + file.getLocation().toFile()); - boolean pre093 = configuration.getAttribute(ATTR_PRE093, false); + boolean pre093 = configuration.getAttribute(SlcScriptUtils.ATTR_PRE093, + false); // Retrieve SLC Runtime SlcSystem slcSystem = findSlcSystem(file, pre093); @@ -153,14 +165,16 @@ public class SlcScriptLaunchDelegate extends list.add(file.getLocation().toFile().getAbsolutePath()); // Runtime - String runtime = configuration.getAttribute(ATTR_RUNTIME, ""); + String runtime = configuration.getAttribute( + SlcScriptUtils.ATTR_RUNTIME, ""); if (!runtime.equals("")) { list.add("--runtime"); list.add(runtime); } // Targets - String targets = configuration.getAttribute(ATTR_RUNTIME, ""); + String targets = configuration.getAttribute( + SlcScriptUtils.ATTR_TARGETS, ""); if (!runtime.equals("")) { list.add("--targets"); list.add(targets); @@ -169,7 +183,7 @@ public class SlcScriptLaunchDelegate extends // Properties Properties properties = new Properties(); StringReader reader = new StringReader(configuration.getAttribute( - ATTR_PROPERTIES, "")); + SlcScriptUtils.ATTR_PROPERTIES, "")); try { properties.load(reader); } catch (IOException e) { diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java index a5311ed2d..755ba760b 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcut.java @@ -2,14 +2,17 @@ package org.argeo.slc.ui.launch.script; import org.argeo.slc.ui.launch.SlcUiLaunchPlugin; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.ILaunchShortcut; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; @@ -18,6 +21,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; public class SlcScriptLaunchShortcut implements ILaunchShortcut { + private boolean showDialog = false; public void launch(ISelection selection, String mode) { try { @@ -41,17 +45,20 @@ public class SlcScriptLaunchShortcut implements ILaunchShortcut { .getLaunchConfigurationType(SlcScriptLaunchDelegate.ID); // Find or create config - ILaunchConfiguration config = findLaunchConfiguration(file, manager - .getLaunchConfigurations(type)); + String configLocation = SlcScriptUtils + .convertToWorkspaceLocation(file); + ILaunchConfiguration config = findLaunchConfiguration( + configLocation, manager.getLaunchConfigurations(type)); if (config == null) { ILaunchConfigurationWorkingCopy wc = type.newInstance(null, generateName(file)); + wc.setAttribute(SlcScriptUtils.ATTR_SCRIPT, configLocation); wc.setMappedResources(new IFile[] { file }); config = wc.doSave(); } - + // Launch - config.launch(mode, null); + launch(config, mode); } catch (CoreException e) { Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow().getShell(); @@ -77,22 +84,44 @@ public class SlcScriptLaunchShortcut implements ILaunchShortcut { return name; } - protected ILaunchConfiguration findLaunchConfiguration(IFile file, - ILaunchConfiguration[] configs) throws CoreException { + protected ILaunchConfiguration findLaunchConfiguration( + String configLocation, ILaunchConfiguration[] configs) + throws CoreException { for (ILaunchConfiguration config : configs) { - IResource[] res = config.getMappedResources(); - if (res.length > 1) { - IFile fileT = (IFile) res[0]; - if (fileT.equals(file)) { - return config; - } + String loc = config.getAttribute(SlcScriptUtils.ATTR_SCRIPT, ""); + if (loc.equals(configLocation)) { + return config; } } return null; } + protected void launch(ILaunchConfiguration configuration, String mode) + throws CoreException { + if (showDialog) { + IStatus status = new Status(IStatus.INFO, SlcUiLaunchPlugin.ID, + "Configure SLC Launch"); + String groupId; + if (mode.equals(ILaunchManager.DEBUG_MODE)) { + groupId = IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP; + } else { + groupId = IDebugUIConstants.ID_RUN_LAUNCH_GROUP; + } + DebugUITools.openLaunchConfigurationDialog(SlcUiLaunchPlugin + .getDefault().getWorkbench().getActiveWorkbenchWindow() + .getShell(), configuration, groupId, status); + } else { + DebugUITools.launch(configuration, mode); + } + + } + public void launch(IEditorPart editor, String mode) { // not (yet) implemented } + public void setShowDialog(boolean showDialog) { + this.showDialog = showDialog; + } + } 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 index 000000000..ae12ed064 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchShortcutWithDialog.java @@ -0,0 +1,11 @@ +package org.argeo.slc.ui.launch.script; + + +public class SlcScriptLaunchShortcutWithDialog extends SlcScriptLaunchShortcut { + + public SlcScriptLaunchShortcutWithDialog() { + super(); + setShowDialog(true); + } + +} 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 index 000000000..76a684fc1 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptUtils.java @@ -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() { + + } +} -- 2.39.2