X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=ide%2Fplugins%2Forg.argeo.slc.ide.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fide%2Fui%2Flaunch%2Fscript%2FSlcScriptLaunchShortcut.java;fp=ide%2Fplugins%2Forg.argeo.slc.ide.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fide%2Fui%2Flaunch%2Fscript%2FSlcScriptLaunchShortcut.java;h=0000000000000000000000000000000000000000;hb=49f14f0278277e965b3f96cc9b7419e67c584957;hp=dfb0044f5ea21ae79b680e149f215191ec435edd;hpb=a3da22317feef5352e22368d6a30fa9b6e848d37;p=gpl%2Fargeo-slc.git diff --git a/ide/plugins/org.argeo.slc.ide.ui/src/org/argeo/slc/ide/ui/launch/script/SlcScriptLaunchShortcut.java b/ide/plugins/org.argeo.slc.ide.ui/src/org/argeo/slc/ide/ui/launch/script/SlcScriptLaunchShortcut.java deleted file mode 100644 index dfb0044f5..000000000 --- a/ide/plugins/org.argeo.slc.ide.ui/src/org/argeo/slc/ide/ui/launch/script/SlcScriptLaunchShortcut.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.argeo.slc.ide.ui.launch.script; - -import org.argeo.slc.ide.ui.SlcIdeUiPlugin; -import org.eclipse.core.resources.IFile; -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; -import org.eclipse.jface.viewers.IStructuredSelection; -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 { - if (!(selection instanceof IStructuredSelection)) { - throw new RuntimeException("Unknown selection " - + selection.getClass()); - } - IStructuredSelection sSelection = (IStructuredSelection) selection; - if (sSelection.size() != 1) { - throw new RuntimeException("Can only launch one SLC script."); - } - Object obj = sSelection.iterator().next(); - if (!(obj instanceof IFile)) { - throw new RuntimeException("Can only launch files."); - } - IFile file = ((IFile) obj); - - ILaunchManager manager = DebugPlugin.getDefault() - .getLaunchManager(); - ILaunchConfigurationType type = manager - .getLaunchConfigurationType(SlcScriptLaunchDelegate.ID); - - // Find or create config - 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 - launch(config, mode); - } catch (CoreException e) { - Shell shell = SlcIdeUiPlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getShell(); - ErrorDialog.openError(shell, "Error", - "Cannot execute SLC launch shortcut", e.getStatus()); - } - - } - - protected String generateName(IFile file) { - IPath relativePath = file.getProjectRelativePath(); - String name = relativePath.toString(); - int idx = name.lastIndexOf(".xml"); - if (idx > 0) - name = name.substring(0, idx); - - if (name.startsWith("src/main/slc/root/")) - name = name.substring("src/main/slc/root/".length()); - else if (name.startsWith("src/main/slc/")) - name = name.substring("src/main/slc/".length()); - - name = name.replace('/', '.');// otherwise not properly saved - return name; - } - - protected ILaunchConfiguration findLaunchConfiguration( - String configLocation, ILaunchConfiguration[] configs) - throws CoreException { - for (ILaunchConfiguration config : configs) { - 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, SlcIdeUiPlugin.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(SlcIdeUiPlugin - .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; - } - -}