Bug 312397 - Run Configuration Command Line to Clipboard

Change-Id: I19d054bed10f834c52bc00f0397255f870b4d6c8
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
index 45a43f2..30764a4 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
@@ -1553,12 +1553,7 @@
 	 * Dialog to Show the Command line
 	 */
 	protected void handleShowCommandLinePressed() {
-		ShowCommandLineDialog dialog = new ShowCommandLineDialog(getShell(),
-				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Title, null, null, 0,
-				new String[] { LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Copy,
-						IDialogConstants.CANCEL_LABEL },
-				0,
-				fOriginal);
+		ShowCommandLineDialog dialog = new ShowCommandLineDialog(getShell(), fOriginal);
 		dialog.open();
 	}
 
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
index 3414bbb..edaf3c9 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
@@ -107,6 +107,7 @@
 	public static String LaunchConfigurationDialog_ShowCommandLine;
 	public static String LaunchConfigurationDialog_ShowCommandLine_Title;
 	public static String LaunchConfigurationDialog_ShowCommandLine_Copy;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Default;
 	public static String LaunchConfigurationSelectionDialog_0;
 	public static String LaunchConfigurationSelectionDialog_1;
 	public static String LaunchConfigurationSelectionDialog_deleteButtonLabel;
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
index b48e01d..de89a84 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
@@ -118,6 +118,7 @@
 LaunchConfigurationDialog_ShowCommandLine=Sho&w Command Line
 LaunchConfigurationDialog_ShowCommandLine_Title=Command Line
 LaunchConfigurationDialog_ShowCommandLine_Copy=C&opy
+LaunchConfigurationDialog_ShowCommandLine_Default=Command Line could not be retrieved.
 LaunchConfigurationsDialog_0=New launch configuration
 LaunchConfigurationsDialog_1=Delete selected launch configuration(s)
 LaunchConfigurationsDialog_2=New launch configuration prototype
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
index fc3a3b4..f11ab8a 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
@@ -24,13 +24,15 @@
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
 import org.eclipse.debug.internal.core.DebugCoreMessages;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.dnd.TextTransfer;
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
@@ -44,23 +46,37 @@
 /**
  * Allows the user to specify to see and copy the command line to be executed
  * for the launch.
- * 
+ *
  * @since 3.13
  */
-public class ShowCommandLineDialog extends MessageDialog {
+public class ShowCommandLineDialog extends Dialog {
 	Text fModuleArgumentsText;
 	ILaunchConfiguration flaunchConfiguration;
 
 
-	public ShowCommandLineDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, ILaunchConfiguration config) {
-		super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
+	public ShowCommandLineDialog(Shell parentShell, ILaunchConfiguration config) {
+		super(parentShell);
+		setShellStyle(SWT.RESIZE | getShellStyle());
 		flaunchConfiguration = config;
 	}
 
+
 	@Override
-	protected Control createCustomArea(Composite parent) {
-		Composite comp = new Composite(parent, SWT.NONE);
-		comp.setLayout(new GridLayout());
+	protected void configureShell(Shell newShell) {
+		super.configureShell(newShell);
+		newShell.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Title);
+	}
+
+	@Override
+	protected void createButtonsForButtonBar(Composite parent) {
+		createButton(parent, IDialogConstants.OK_ID,
+				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Copy, true);
+		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+	}
+
+	@Override
+	protected Control createDialogArea(Composite parent) {
+		Composite comp = (Composite) super.createDialogArea(parent);
 		Font font = parent.getFont();
 
 		Group group = new Group(comp, SWT.NONE);
@@ -72,16 +88,13 @@
 		group.setLayoutData(gd);
 		group.setFont(font);
 
-
-		// Label description = new Label(group, SWT.WRAP);
-		// description.setText(ActionMessages.Override_Dependencies_label1);
 		fModuleArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
 		gd = new GridData(GridData.FILL_BOTH);
 		gd.heightHint = convertHeightInCharsToPixels(10);
 		gd.widthHint = convertWidthInCharsToPixels(60);
 		fModuleArgumentsText.setLayoutData(gd);
 
-		String command = "Could not retrieve the command"; //$NON-NLS-1$
+		String command = ""; //$NON-NLS-1$
 		try {
 			Set<String> modes = flaunchConfiguration.getModes();
 			modes.add(ILaunchManager.RUN_MODE);
@@ -108,11 +121,16 @@
 						}
 					}
 				}
-				command = delegate.showCommandLine(flaunchConfiguration, ILaunchManager.RUN_MODE, launch, null);
+				command = delegate.showCommandLine(flaunchConfiguration, ILaunchManager.RUN_MODE, launch,
+						null);
+
 			}
 		} catch (CoreException e) {
 			e.printStackTrace();
 		}
+		if (command == null || (command != null && command.length() == 0)) {
+			command = LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Default;
+		}
 		fModuleArgumentsText.setText(command);
 		fModuleArgumentsText.setEditable(false);
 
@@ -135,6 +153,21 @@
 		super.buttonPressed(buttonId);
 	}
 
+	@Override
+	protected IDialogSettings getDialogBoundsSettings() {
+		IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
+		IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
+		if (section == null) {
+			section = settings.addNewSection(getDialogSettingsSectionName());
+		}
+		return section;
+	}
 
+	/**
+	 * @return the name to use to save the dialog settings
+	 */
+	protected String getDialogSettingsSectionName() {
+		return "SHOW_COMMAND_LINE_DIALOG"; //$NON-NLS-1$
+	}
 
 }