1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 import org.eclipse.ant.internal.ui.AntUIPlugin; 14 import org.eclipse.debug.ui.StringVariableSelectionDialog; 15 import org.eclipse.jface.dialogs.Dialog; 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.dialogs.IDialogSettings; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.SelectionAdapter; 20 import org.eclipse.swt.events.SelectionEvent; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.layout.GridLayout; 23 import org.eclipse.swt.widgets.Button; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.swt.widgets.Label; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.swt.widgets.Text; 29 30 31 public class VariableInputDialog extends Dialog { 32 33 private static String DIALOG_SETTINGS_SECTION = "RuntimeClasspathAction.VariableInputDialog"; private Text fText; 35 private String fVariableString; 36 37 public VariableInputDialog(Shell shell) { 38 super(shell); 39 setShellStyle(SWT.RESIZE | getShellStyle()); 40 } 41 42 45 protected Control createDialogArea(Composite parent) { 46 Composite inner= (Composite) super.createDialogArea(parent); 47 ((GridLayout)inner.getLayout()).numColumns= 2; 48 49 Label label = new Label(inner, SWT.NONE); 50 label.setText(AntLaunchConfigurationMessages.AddVariableStringAction_2); 51 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 52 gd.horizontalSpan= 2; 53 label.setLayoutData(gd); 54 55 fText = new Text(inner, SWT.SINGLE | SWT.BORDER); 56 gd = new GridData(GridData.FILL_HORIZONTAL); 57 gd.grabExcessHorizontalSpace = true; 58 gd.widthHint = 200; 59 fText.setLayoutData(gd); 60 61 Button button = new Button(inner, SWT.PUSH); 62 button.setText(AntLaunchConfigurationMessages.AddVariableStringAction_3); 63 button.addSelectionListener(new SelectionAdapter() { 64 public void widgetSelected(SelectionEvent se) { 65 getVariable(); 66 } 67 }); 68 69 applyDialogFont(parent); 70 return inner; 71 } 72 73 protected void createButtonsForButtonBar(Composite parent) { 74 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 75 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 76 } 77 78 81 protected void configureShell(Shell newShell) { 82 super.configureShell(newShell); 83 newShell.setText(AntLaunchConfigurationMessages.AddVariableStringAction_4); 84 } 85 86 private void getVariable() { 87 StringVariableSelectionDialog variableDialog = new StringVariableSelectionDialog(getShell()); 88 int returnCode = variableDialog.open(); 89 if (returnCode == IDialogConstants.OK_ID) { 90 String variable = variableDialog.getVariableExpression(); 91 if (variable != null) { 92 fText.insert(variable); 93 } 94 } 95 } 96 97 100 protected void okPressed() { 101 String variableString = fText.getText(); 102 if (variableString != null && variableString.trim().length() > 0) { 103 fVariableString= variableString; 104 } else { 105 fVariableString= null; 106 } 107 super.okPressed(); 108 } 109 110 public String getVariableString() { 111 return fVariableString; 112 } 113 114 117 protected IDialogSettings getDialogBoundsSettings() { 118 IDialogSettings settings = AntUIPlugin.getDefault().getDialogSettings(); 119 IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION); 120 if (section == null) { 121 section = settings.addNewSection(DIALOG_SETTINGS_SECTION); 122 } 123 return section; 124 } 125 } 126 | Popular Tags |