1 package org.eclipse.jdt.internal.junit.launcher; 2 3 7 8 import java.io.File ; 9 10 import org.eclipse.core.resources.IWorkspaceRoot; 11 import org.eclipse.core.resources.ResourcesPlugin; 12 import org.eclipse.core.runtime.CoreException; 13 import org.eclipse.debug.core.ILaunch; 14 import org.eclipse.debug.core.ILaunchConfiguration; 15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 16 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 17 import org.eclipse.debug.ui.ILaunchConfigurationTab; 18 import org.eclipse.jdt.core.IJavaModel; 19 import org.eclipse.jdt.core.JavaCore; 20 import org.eclipse.jdt.debug.ui.JavaDebugUI; 21 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.events.ModifyEvent; 24 import org.eclipse.swt.events.ModifyListener; 25 import org.eclipse.swt.events.SelectionAdapter; 26 import org.eclipse.swt.events.SelectionEvent; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.DirectoryDialog; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Shell; 35 import org.eclipse.swt.widgets.TabItem; 36 import org.eclipse.swt.widgets.Text; 37 38 42 public class JUnitArgumentsTab extends JUnitLaunchConfigurationTab { 43 44 private Label fVMArgumentsLabel; 46 private Text fVMArgumentsText; 47 48 private Label fWorkingDirLabel; 50 private Text fWorkingDirText; 51 private Button fWorkingDirBrowseButton; 52 53 private static final String EMPTY_STRING = ""; 54 55 58 public void createControl(Composite parent) { 59 60 Composite comp = new Composite(parent, SWT.NONE); 61 setControl(comp); 62 GridLayout topLayout = new GridLayout(); 63 comp.setLayout(topLayout); 64 GridData gd; 65 66 createVerticalSpacer(comp); 67 68 Composite workingDirComp = new Composite(comp, SWT.NONE); 69 GridLayout workingDirLayout = new GridLayout(); 70 workingDirLayout.numColumns = 2; 71 workingDirLayout.marginHeight = 0; 72 workingDirLayout.marginWidth = 0; 73 workingDirComp.setLayout(workingDirLayout); 74 gd = new GridData(GridData.FILL_HORIZONTAL); 75 workingDirComp.setLayoutData(gd); 76 77 fWorkingDirLabel = new Label(workingDirComp, SWT.NONE); 78 fWorkingDirLabel.setText("Wor&king directory:"); 79 gd = new GridData(); 80 gd.horizontalSpan = 2; 81 fWorkingDirLabel.setLayoutData(gd); 82 83 fWorkingDirText = new Text(workingDirComp, SWT.SINGLE | SWT.BORDER); 84 gd = new GridData(GridData.FILL_HORIZONTAL); 85 fWorkingDirText.setLayoutData(gd); 86 fWorkingDirText.addModifyListener(new ModifyListener() { 87 public void modifyText(ModifyEvent evt) { 88 refreshStatus(); 89 } 90 }); 91 92 fWorkingDirBrowseButton = new Button(workingDirComp, SWT.PUSH); 93 fWorkingDirBrowseButton.setText("&Browse..."); 94 fWorkingDirBrowseButton.addSelectionListener(new SelectionAdapter() { 95 public void widgetSelected(SelectionEvent evt) { 96 handleWorkingDirBrowseButtonSelected(); 97 } 98 }); 99 100 createVerticalSpacer(comp); 101 102 fVMArgumentsLabel = new Label(comp, SWT.NONE); 103 fVMArgumentsLabel.setText("VM ar&guments:"); 104 105 fVMArgumentsText = new Text(comp, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL); 106 gd = new GridData(GridData.FILL_HORIZONTAL); 107 gd.heightHint = 40; 108 fVMArgumentsText.setLayoutData(gd); 109 fVMArgumentsText.addModifyListener(new ModifyListener() { 110 public void modifyText(ModifyEvent evt) { 111 refreshStatus(); 112 } 113 }); 114 115 } 116 117 120 protected void updateWidgetsFromConfig(ILaunchConfiguration config) { 121 updateVMArgsFromConfig(config); 122 updateWorkingDirectoryFromConfig(config); 123 } 124 125 protected void updateVMArgsFromConfig(ILaunchConfiguration config) { 126 try { 127 String vmArgs = EMPTY_STRING; 128 if (config != null) { 129 vmArgs = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, EMPTY_STRING); 130 } 131 fVMArgumentsText.setText(vmArgs); 132 } catch (CoreException ce) { 133 } 134 } 135 136 protected void updateWorkingDirectoryFromConfig(ILaunchConfiguration config) { 137 try { 138 String workingDir = EMPTY_STRING; 139 if (config != null) { 140 workingDir = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, EMPTY_STRING); 141 } 142 fWorkingDirText.setText(workingDir); 143 } catch (CoreException ce) { 144 } 145 } 146 147 150 public void dispose() { 151 } 152 153 156 protected void createVerticalSpacer(Composite comp) { 157 new Label(comp, SWT.NONE); 158 } 159 160 163 protected void handleWorkingDirBrowseButtonSelected() { 164 DirectoryDialog dialog = new DirectoryDialog(getShell()); 165 dialog.setMessage("Select a working directory for the launch configuration"); 166 String currentWorkingDir = fWorkingDirText.getText(); 167 if (!currentWorkingDir.trim().equals("")) { 168 File path = new File (currentWorkingDir); 169 if (path.exists()) { 170 dialog.setFilterPath(currentWorkingDir); 171 } 172 } 173 174 String selectedDirectory = dialog.open(); 175 if (selectedDirectory != null) { 176 fWorkingDirText.setText(selectedDirectory); 177 } 178 } 179 180 185 private Shell getShell() { 186 return fWorkingDirLabel.getShell(); 187 } 188 189 192 public boolean isValid() { 193 194 setErrorMessage(null); 195 setMessage(null); 196 197 String workingDirPath = fWorkingDirText.getText().trim(); 198 if (workingDirPath.length() > 0) { 199 File dir = new File (workingDirPath); 200 if (!dir.exists()) { 201 setErrorMessage("Working directory does not exist."); 202 return false; 203 } 204 if (!dir.isDirectory()) { 205 setErrorMessage("Working directory is not a directory."); 206 return false; 207 } 208 } 209 210 return true; 211 } 212 213 218 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 219 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String )null); 220 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String )null); 221 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String )null); 222 } 223 224 227 public void initializeFrom(ILaunchConfiguration configuration) { 228 try { 229 fWorkingDirText.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "")); 230 fVMArgumentsText.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "")); 231 } catch (CoreException e) { 232 setErrorMessage("Exception occurred reading configuration: " + e.getStatus().getMessage()); 233 } 234 } 235 236 239 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 240 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, getAttributeValueFrom(fVMArgumentsText)); 241 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getAttributeValueFrom(fWorkingDirText)); 242 } 243 244 249 protected String getAttributeValueFrom(Text text) { 250 String content = text.getText().trim(); 251 if (content.length() > 0) { 252 return content; 253 } 254 return null; 255 } 256 } 257 258 | Popular Tags |