|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-18
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Remy Chi Jian Suen <remy.suen@gmail.com> - Bug 214696 Expose WorkingDirectoryBlock as API |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.debug.ui.launcher; |
12 |
package org.eclipse.jdt.internal.debug.ui.launcher; |
| 12 |
|
13 |
|
| 13 |
import java.io.File; |
14 |
import java.io.File; |
| 14 |
|
15 |
|
| 15 |
import org.eclipse.core.resources.IContainer; |
16 |
import org.eclipse.core.resources.IContainer; |
|
|
17 |
import org.eclipse.core.resources.IProject; |
| 16 |
import org.eclipse.core.resources.IResource; |
18 |
import org.eclipse.core.resources.IResource; |
| 17 |
import org.eclipse.core.resources.IWorkspaceRoot; |
19 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 18 |
import org.eclipse.core.resources.ResourcesPlugin; |
20 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
Lines 23-36
Link Here
|
| 23 |
import org.eclipse.core.variables.VariablesPlugin; |
25 |
import org.eclipse.core.variables.VariablesPlugin; |
| 24 |
import org.eclipse.debug.core.ILaunchConfiguration; |
26 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 25 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
27 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
|
28 |
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
| 26 |
import org.eclipse.debug.ui.StringVariableSelectionDialog; |
29 |
import org.eclipse.debug.ui.StringVariableSelectionDialog; |
| 27 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
| 28 |
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchTab; |
| 29 |
import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; |
| 30 |
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| 31 |
import org.eclipse.jdt.internal.debug.ui.SWTFactory; |
30 |
import org.eclipse.jdt.internal.debug.ui.SWTFactory; |
| 32 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
31 |
import org.eclipse.jface.util.Assert; |
| 33 |
import org.eclipse.jdt.launching.JavaRuntime; |
|
|
| 34 |
import org.eclipse.swt.events.ModifyEvent; |
32 |
import org.eclipse.swt.events.ModifyEvent; |
| 35 |
import org.eclipse.swt.events.ModifyListener; |
33 |
import org.eclipse.swt.events.ModifyListener; |
| 36 |
import org.eclipse.swt.events.SelectionAdapter; |
34 |
import org.eclipse.swt.events.SelectionAdapter; |
|
Lines 50-56
Link Here
|
| 50 |
* A control for setting the working directory associated with a launch |
48 |
* A control for setting the working directory associated with a launch |
| 51 |
* configuration. |
49 |
* configuration. |
| 52 |
*/ |
50 |
*/ |
| 53 |
public class WorkingDirectoryBlock extends JavaLaunchTab { |
51 |
public abstract class WorkingDirectoryBlock extends AbstractLaunchConfigurationTab { |
| 54 |
|
52 |
|
| 55 |
// Local directory |
53 |
// Local directory |
| 56 |
private Button fWorkspaceButton; |
54 |
private Button fWorkspaceButton; |
|
Lines 103-108
Link Here
|
| 103 |
|
101 |
|
| 104 |
private WidgetListener fListener = new WidgetListener(); |
102 |
private WidgetListener fListener = new WidgetListener(); |
| 105 |
|
103 |
|
|
|
104 |
/** |
| 105 |
* The name of the launch configuration attribute that will be used to save |
| 106 |
* the location of the working directory. |
| 107 |
*/ |
| 108 |
private final String workingDirectoryAttribteName; |
| 109 |
|
| 110 |
/** |
| 111 |
* The help context id to use to connect this working directory block |
| 112 |
* to the help system. |
| 113 |
*/ |
| 114 |
private final String helpContextId; |
| 115 |
|
| 116 |
/** |
| 117 |
* Creates a new WorkingDirectoryBlock for setting a working directory. |
| 118 |
* |
| 119 |
* @param workingDirectoryAttribteName the name of the launch configuration attribute to set the working directory's location, cannot be <tt>null</tt> |
| 120 |
*/ |
| 121 |
public WorkingDirectoryBlock(String workingDirectoryAttribteName) { |
| 122 |
this(workingDirectoryAttribteName, null); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Creates a new WorkingDirectoryBlock for setting a working directory. |
| 127 |
* |
| 128 |
* @param workingDirectoryAttribteName the name of the launch configuration attribute to set the working directory's location, cannot be <tt>null</tt> |
| 129 |
* @param helpContextId the help context id to use to hook onto the help system |
| 130 |
*/ |
| 131 |
public WorkingDirectoryBlock(String workingDirectoryAttribteName, |
| 132 |
String helpContextId) { |
| 133 |
Assert.isNotNull(workingDirectoryAttribteName); |
| 134 |
this.workingDirectoryAttribteName = workingDirectoryAttribteName; |
| 135 |
this.helpContextId = helpContextId; |
| 136 |
} |
| 137 |
|
| 106 |
/* (non-Javadoc) |
138 |
/* (non-Javadoc) |
| 107 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) |
139 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) |
| 108 |
*/ |
140 |
*/ |
|
Lines 110-116
Link Here
|
| 110 |
Font font = parent.getFont(); |
142 |
Font font = parent.getFont(); |
| 111 |
Group group = SWTFactory.createGroup(parent, LauncherMessages.WorkingDirectoryBlock_12, 2, 1, GridData.FILL_HORIZONTAL); |
143 |
Group group = SWTFactory.createGroup(parent, LauncherMessages.WorkingDirectoryBlock_12, 2, 1, GridData.FILL_HORIZONTAL); |
| 112 |
setControl(group); |
144 |
setControl(group); |
| 113 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IJavaDebugHelpContextIds.WORKING_DIRECTORY_BLOCK); |
145 |
|
|
|
146 |
if (helpContextId != null) { |
| 147 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(group, helpContextId); |
| 148 |
} |
| 149 |
|
| 114 |
//default choice |
150 |
//default choice |
| 115 |
Composite comp = SWTFactory.createComposite(group, font, 2, 2, GridData.FILL_BOTH, 0, 0); |
151 |
Composite comp = SWTFactory.createComposite(group, font, 2, 2, GridData.FILL_BOTH, 0, 0); |
| 116 |
fUseDefaultDirButton = SWTFactory.createRadioButton(comp, LauncherMessages.WorkingDirectoryBlock_18); |
152 |
fUseDefaultDirButton = SWTFactory.createRadioButton(comp, LauncherMessages.WorkingDirectoryBlock_18); |
|
Lines 192-198
Link Here
|
| 192 |
res = containers[0]; |
228 |
res = containers[0]; |
| 193 |
} |
229 |
} |
| 194 |
} |
230 |
} |
| 195 |
catch (CoreException e) {} |
231 |
catch (CoreException e) { |
|
|
232 |
log(e); |
| 233 |
} |
| 196 |
} |
234 |
} |
| 197 |
else { |
235 |
else { |
| 198 |
res = root.findMember(path); |
236 |
res = root.findMember(path); |
|
Lines 247-262
Link Here
|
| 247 |
try { |
285 |
try { |
| 248 |
ILaunchConfiguration config = getLaunchConfiguration(); |
286 |
ILaunchConfiguration config = getLaunchConfiguration(); |
| 249 |
if (config != null) { |
287 |
if (config != null) { |
| 250 |
IJavaProject javaProject = JavaRuntime.getJavaProject(config); |
288 |
IProject project = getProject(config); |
| 251 |
if (javaProject != null) { |
289 |
if (project != null) { |
| 252 |
setDefaultWorkingDirectoryText("${workspace_loc:" + javaProject.getPath().makeRelative().toOSString() + "}"); //$NON-NLS-1$//$NON-NLS-2$ |
290 |
setDefaultWorkingDirectoryText("${workspace_loc:" + project.getFullPath().makeRelative().toOSString() + "}"); //$NON-NLS-1$//$NON-NLS-2$ |
| 253 |
return; |
291 |
return; |
| 254 |
} |
292 |
} |
| 255 |
} |
293 |
} |
| 256 |
} |
294 |
} |
| 257 |
catch (CoreException ce) {} |
295 |
catch (CoreException ce) { |
|
|
296 |
log(ce); |
| 297 |
} |
| 258 |
setDefaultWorkingDirectoryText(System.getProperty("user.dir")); //$NON-NLS-1$ |
298 |
setDefaultWorkingDirectoryText(System.getProperty("user.dir")); //$NON-NLS-1$ |
| 259 |
} |
299 |
} |
|
|
300 |
|
| 301 |
/** |
| 302 |
* Retrieves the project that is associated with the specified launch configuration. |
| 303 |
* @param configuration the launch configuration that has been set to this working directory block |
| 304 |
* @return the project specified by the launch configuration, or <tt>null</tt> if nothing has been set |
| 305 |
* @throws CoreException if an error occurred while retrieving the project from the launch configuration |
| 306 |
*/ |
| 307 |
protected abstract IProject getProject(ILaunchConfiguration configuration) throws CoreException; |
| 260 |
|
308 |
|
| 261 |
/* (non-Javadoc) |
309 |
/* (non-Javadoc) |
| 262 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) |
310 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) |
|
Lines 273-278
Link Here
|
| 273 |
} |
321 |
} |
| 274 |
catch (CoreException e) { |
322 |
catch (CoreException e) { |
| 275 |
setErrorMessage(e.getMessage()); |
323 |
setErrorMessage(e.getMessage()); |
|
|
324 |
log(e); |
| 276 |
return false; |
325 |
return false; |
| 277 |
} |
326 |
} |
| 278 |
} |
327 |
} |
|
Lines 299-305
Link Here
|
| 299 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
348 |
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
| 300 |
*/ |
349 |
*/ |
| 301 |
public void setDefaults(ILaunchConfigurationWorkingCopy config) { |
350 |
public void setDefaults(ILaunchConfigurationWorkingCopy config) { |
| 302 |
config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); |
351 |
config.setAttribute(workingDirectoryAttribteName, (String)null); |
| 303 |
} |
352 |
} |
| 304 |
|
353 |
|
| 305 |
/* (non-Javadoc) |
354 |
/* (non-Javadoc) |
|
Lines 308-322
Link Here
|
| 308 |
public void initializeFrom(ILaunchConfiguration configuration) { |
357 |
public void initializeFrom(ILaunchConfiguration configuration) { |
| 309 |
setLaunchConfiguration(configuration); |
358 |
setLaunchConfiguration(configuration); |
| 310 |
try { |
359 |
try { |
| 311 |
String wd = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); |
360 |
String wd = configuration.getAttribute(workingDirectoryAttribteName, (String)null); |
| 312 |
setDefaultWorkingDir(); |
361 |
setDefaultWorkingDir(); |
| 313 |
if (wd != null) { |
362 |
if (wd != null) { |
| 314 |
setOtherWorkingDirectoryText(wd); |
363 |
setOtherWorkingDirectoryText(wd); |
| 315 |
} |
364 |
} |
| 316 |
} |
365 |
} |
| 317 |
catch (CoreException e) { |
366 |
catch (CoreException e) { |
| 318 |
setErrorMessage(LauncherMessages.JavaArgumentsTab_Exception_occurred_reading_configuration___15 + e.getStatus().getMessage()); |
367 |
setErrorMessage(LauncherMessages.JavaArgumentsTab_Exception_occurred_reading_configuration___15 + e.getStatus().getMessage()); |
| 319 |
JDIDebugUIPlugin.log(e); |
368 |
log(e); |
| 320 |
} |
369 |
} |
| 321 |
} |
370 |
} |
| 322 |
|
371 |
|
|
Lines 325-334
Link Here
|
| 325 |
*/ |
374 |
*/ |
| 326 |
public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
375 |
public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 327 |
if(fUseDefaultDirButton.getSelection()) { |
376 |
if(fUseDefaultDirButton.getSelection()) { |
| 328 |
configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null); |
377 |
configuration.setAttribute(workingDirectoryAttribteName, (String)null); |
| 329 |
} |
378 |
} |
| 330 |
else { |
379 |
else { |
| 331 |
configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getWorkingDirectoryText()); |
380 |
configuration.setAttribute(workingDirectoryAttribteName, getWorkingDirectoryText()); |
| 332 |
} |
381 |
} |
| 333 |
} |
382 |
} |
| 334 |
|
383 |
|
|
Lines 340-345
Link Here
|
| 340 |
} |
389 |
} |
| 341 |
|
390 |
|
| 342 |
/** |
391 |
/** |
|
|
392 |
* Logs exceptions that have been caught by this working directory block. |
| 393 |
* The default implementation does nothing. Subclasses should reimplement |
| 394 |
* if they wish to monitor such exceptions. |
| 395 |
* @param e the exception to log |
| 396 |
*/ |
| 397 |
protected void log(CoreException e) { |
| 398 |
// do nothing |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 343 |
* gets the path from the text box that is selected |
402 |
* gets the path from the text box that is selected |
| 344 |
* @return the working directory the user wishes to use |
403 |
* @return the working directory the user wishes to use |
| 345 |
* @since 3.2 |
404 |
* @since 3.2 |
|
Lines 397-403
Link Here
|
| 397 |
* Allows this entire block to be enabled/disabled |
456 |
* Allows this entire block to be enabled/disabled |
| 398 |
* @param enabled whether to enable it or not |
457 |
* @param enabled whether to enable it or not |
| 399 |
*/ |
458 |
*/ |
| 400 |
protected void setEnabled(boolean enabled) { |
459 |
public void setEnabled(boolean enabled) { |
| 401 |
fUseDefaultDirButton.setEnabled(enabled); |
460 |
fUseDefaultDirButton.setEnabled(enabled); |
| 402 |
fUseOtherDirButton.setEnabled(enabled); |
461 |
fUseOtherDirButton.setEnabled(enabled); |
| 403 |
if(fOtherWorkingText.isEnabled()) { |
462 |
if(fOtherWorkingText.isEnabled()) { |