|
Removed
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.debug.ui.jres; |
| 12 |
|
| 13 |
|
| 14 |
import java.io.File; |
| 15 |
import java.io.IOException; |
| 16 |
import java.net.URL; |
| 17 |
import java.util.Arrays; |
| 18 |
import java.util.Comparator; |
| 19 |
|
| 20 |
import org.eclipse.core.resources.IResource; |
| 21 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 22 |
import org.eclipse.core.runtime.IPath; |
| 23 |
import org.eclipse.core.runtime.IStatus; |
| 24 |
import org.eclipse.core.runtime.Path; |
| 25 |
import org.eclipse.core.runtime.Platform; |
| 26 |
import org.eclipse.debug.core.DebugPlugin; |
| 27 |
import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; |
| 28 |
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| 29 |
import org.eclipse.jdt.internal.debug.ui.SWTFactory; |
| 30 |
import org.eclipse.jdt.internal.debug.ui.StatusInfo; |
| 31 |
import org.eclipse.jdt.internal.launching.StandardVMType; |
| 32 |
import org.eclipse.jdt.launching.AbstractVMInstallType; |
| 33 |
import org.eclipse.jdt.launching.IVMInstall; |
| 34 |
import org.eclipse.jdt.launching.IVMInstall2; |
| 35 |
import org.eclipse.jdt.launching.IVMInstallType; |
| 36 |
import org.eclipse.jdt.launching.VMStandin; |
| 37 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 38 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 39 |
import org.eclipse.jface.dialogs.StatusDialog; |
| 40 |
import org.eclipse.swt.SWT; |
| 41 |
import org.eclipse.swt.custom.BusyIndicator; |
| 42 |
import org.eclipse.swt.events.ModifyEvent; |
| 43 |
import org.eclipse.swt.events.ModifyListener; |
| 44 |
import org.eclipse.swt.events.SelectionEvent; |
| 45 |
import org.eclipse.swt.events.SelectionListener; |
| 46 |
import org.eclipse.swt.graphics.Point; |
| 47 |
import org.eclipse.swt.layout.GridData; |
| 48 |
import org.eclipse.swt.layout.GridLayout; |
| 49 |
import org.eclipse.swt.widgets.Button; |
| 50 |
import org.eclipse.swt.widgets.Combo; |
| 51 |
import org.eclipse.swt.widgets.Composite; |
| 52 |
import org.eclipse.swt.widgets.Control; |
| 53 |
import org.eclipse.swt.widgets.DirectoryDialog; |
| 54 |
import org.eclipse.swt.widgets.FileDialog; |
| 55 |
import org.eclipse.swt.widgets.Shell; |
| 56 |
import org.eclipse.swt.widgets.Text; |
| 57 |
import org.eclipse.ui.PlatformUI; |
| 58 |
|
| 59 |
import com.ibm.icu.text.MessageFormat; |
| 60 |
|
| 61 |
/** |
| 62 |
* Provides the Add VM dialog |
| 63 |
*/ |
| 64 |
public class AddVMDialog extends StatusDialog { |
| 65 |
|
| 66 |
/** |
| 67 |
* VM install type id for OSX VMs |
| 68 |
*/ |
| 69 |
public static final String MACOSX_VM_TYPE_ID = "org.eclipse.jdt.internal.launching.macosx.MacOSXType"; //$NON-NLS-1$ |
| 70 |
|
| 71 |
private IAddVMDialogRequestor fRequestor; |
| 72 |
private IVMInstall fEditedVM; |
| 73 |
private IVMInstallType[] fVMTypes; |
| 74 |
private IVMInstallType fSelectedVMType; |
| 75 |
private Combo fVMCombo; |
| 76 |
private Text fVMName; |
| 77 |
private Text fVMArgs; |
| 78 |
private Text fJRERoot; |
| 79 |
private Button fFileButton; |
| 80 |
private VMLibraryBlock fLibraryBlock; |
| 81 |
// the VM install's javadoc location |
| 82 |
private URL fJavadocLocation = null; |
| 83 |
private boolean fAutoDetectAttributes = false; |
| 84 |
private IStatus[] fStatus; |
| 85 |
private int fPrevIndex = -1; |
| 86 |
|
| 87 |
/** |
| 88 |
* Constructor |
| 89 |
* @param requestor dialog validation requester |
| 90 |
* @param shell the parent shell |
| 91 |
* @param vmInstallTypes the types of VM installs |
| 92 |
* @param editedVM the editedVM |
| 93 |
*/ |
| 94 |
public AddVMDialog(IAddVMDialogRequestor requestor, Shell shell, IVMInstallType[] vmInstallTypes, IVMInstall editedVM) { |
| 95 |
super(shell); |
| 96 |
setShellStyle(getShellStyle() | SWT.RESIZE); |
| 97 |
fRequestor = requestor; |
| 98 |
fStatus = new IStatus[5]; |
| 99 |
for (int i= 0; i < fStatus.length; i++) { |
| 100 |
fStatus[i] = new StatusInfo(); |
| 101 |
} |
| 102 |
fVMTypes = vmInstallTypes; |
| 103 |
sortVMTypes(); |
| 104 |
int typeIndex = 0; |
| 105 |
if (Platform.OS_MACOSX.equals(Platform.getOS())) { |
| 106 |
// select OSX VM type by default |
| 107 |
for (int i = 0; i < fVMTypes.length; i++) { |
| 108 |
IVMInstallType type = fVMTypes[i]; |
| 109 |
if (type.getId().equals(MACOSX_VM_TYPE_ID)) { |
| 110 |
typeIndex = i; |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
fSelectedVMType = editedVM != null ? editedVM.getVMInstallType() : vmInstallTypes[typeIndex]; |
| 116 |
fEditedVM = editedVM; |
| 117 |
//only detect the javadoc location if not already set |
| 118 |
fAutoDetectAttributes = fEditedVM == null || fEditedVM.getJavadocLocation() == null; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* This method is used to sort the array of VM install types, placing |
| 123 |
* the 'Standard VM' type first, if it exists |
| 124 |
* |
| 125 |
* @since 3.3.0 |
| 126 |
*/ |
| 127 |
private void sortVMTypes() { |
| 128 |
Comparator compare = new Comparator() { |
| 129 |
public int compare(Object o1, Object o2) { |
| 130 |
if(o1 instanceof IVMInstallType && o2 instanceof IVMInstallType) { |
| 131 |
return ((IVMInstallType) o1).getName().compareTo(((IVMInstallType) o2).getName()); |
| 132 |
} |
| 133 |
return 0; |
| 134 |
} |
| 135 |
}; |
| 136 |
//first find the 'Standard VM' and set it at position 0 |
| 137 |
for(int i = 0; i < fVMTypes.length; i++) { |
| 138 |
if(fVMTypes[i].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$ |
| 139 |
if(i > 0) { |
| 140 |
IVMInstallType tmp = fVMTypes[0]; |
| 141 |
fVMTypes[0] = fVMTypes[i]; |
| 142 |
fVMTypes[i] = tmp; |
| 143 |
break; |
| 144 |
} |
| 145 |
else { |
| 146 |
break; |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
if(fVMTypes[0].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$ |
| 151 |
Arrays.sort(fVMTypes, 1, fVMTypes.length, compare); |
| 152 |
} |
| 153 |
else { |
| 154 |
Arrays.sort(fVMTypes, compare); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
/* (non-Javadoc) |
| 159 |
* @see org.eclipse.jface.dialogs.StatusDialog#configureShell(org.eclipse.swt.widgets.Shell) |
| 160 |
*/ |
| 161 |
protected void configureShell(Shell newShell) { |
| 162 |
super.configureShell(newShell); |
| 163 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaDebugHelpContextIds.EDIT_JRE_DIALOG); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Returns the VM name from the text control |
| 168 |
* @return |
| 169 |
*/ |
| 170 |
protected String getVMName() { |
| 171 |
return fVMName.getText(); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Returns the installation location as a file from the JRE root text control |
| 176 |
* @return the installation location as a file |
| 177 |
*/ |
| 178 |
protected File getInstallLocation() { |
| 179 |
return new File(fJRERoot.getText()); |
| 180 |
} |
| 181 |
|
| 182 |
/* (non-Javadoc) |
| 183 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
| 184 |
*/ |
| 185 |
protected Control createDialogArea(Composite ancestor) { |
| 186 |
Composite parent = (Composite)super.createDialogArea(ancestor); |
| 187 |
((GridLayout)parent.getLayout()).numColumns = 3; |
| 188 |
//VM type |
| 189 |
SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreType, 1); |
| 190 |
fVMCombo = SWTFactory.createCombo(parent, SWT.READ_ONLY, 2, getVMTypeNames()); |
| 191 |
// VM location |
| 192 |
SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreHome, 1); |
| 193 |
fJRERoot = SWTFactory.createSingleText(parent, 2); |
| 194 |
Composite buttons = SWTFactory.createComposite(parent, parent.getFont(), 2, 4, GridData.HORIZONTAL_ALIGN_END, 0, 0); |
| 195 |
Button folders = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_22, null); |
| 196 |
GridData data = (GridData) folders.getLayoutData(); |
| 197 |
data.horizontalAlignment = GridData.END; |
| 198 |
fFileButton = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_21, null); |
| 199 |
data = (GridData) fFileButton.getLayoutData(); |
| 200 |
data.horizontalAlignment = GridData.END; |
| 201 |
//VM name |
| 202 |
SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreName, 1); |
| 203 |
fVMName = SWTFactory.createSingleText(parent, 2); |
| 204 |
//VM arguments |
| 205 |
SWTFactory.createLabel(parent, JREMessages.AddVMDialog_23, 1); |
| 206 |
fVMArgs = SWTFactory.createSingleText(parent, 2); |
| 207 |
//VM libraries block |
| 208 |
SWTFactory.createLabel(parent, JREMessages.AddVMDialog_JRE_system_libraries__1, 3); |
| 209 |
fLibraryBlock = new VMLibraryBlock(this); |
| 210 |
Control block = fLibraryBlock.createControl(parent); |
| 211 |
GridData gd = new GridData(GridData.FILL_BOTH); |
| 212 |
gd.horizontalSpan = 3; |
| 213 |
block.setLayoutData(gd); |
| 214 |
|
| 215 |
//initialize the fields |
| 216 |
initializeFields(); |
| 217 |
|
| 218 |
//add the listeners now to prevent them from monkeying with initialized settings |
| 219 |
fVMCombo.addSelectionListener(new SelectionListener() { |
| 220 |
public void widgetDefaultSelected(SelectionEvent e) {} |
| 221 |
public void widgetSelected(SelectionEvent e) { |
| 222 |
updateVMType(); |
| 223 |
} |
| 224 |
}); |
| 225 |
fVMName.addModifyListener(new ModifyListener() { |
| 226 |
public void modifyText(ModifyEvent e) { |
| 227 |
validateVMName(); |
| 228 |
updateStatusLine(); |
| 229 |
} |
| 230 |
}); |
| 231 |
fJRERoot.addModifyListener(new ModifyListener() { |
| 232 |
public void modifyText(ModifyEvent e) { |
| 233 |
validateJRELocation(); |
| 234 |
updateStatusLine(); |
| 235 |
} |
| 236 |
}); |
| 237 |
folders.addSelectionListener(new SelectionListener() { |
| 238 |
public void widgetDefaultSelected(SelectionEvent e) {} |
| 239 |
public void widgetSelected(SelectionEvent e) { |
| 240 |
DirectoryDialog dialog = new DirectoryDialog(getShell()); |
| 241 |
File file = new File(fJRERoot.getText()); |
| 242 |
String text = fJRERoot.getText(); |
| 243 |
if (file.isFile()) { |
| 244 |
text = file.getParentFile().getAbsolutePath(); |
| 245 |
} |
| 246 |
dialog.setFilterPath(text); |
| 247 |
dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); |
| 248 |
String newPath = dialog.open(); |
| 249 |
if (newPath != null) { |
| 250 |
fJRERoot.setText(newPath); |
| 251 |
} |
| 252 |
} |
| 253 |
}); |
| 254 |
fFileButton.addSelectionListener(new SelectionListener() { |
| 255 |
public void widgetDefaultSelected(SelectionEvent e) {} |
| 256 |
public void widgetSelected(SelectionEvent e) { |
| 257 |
FileDialog dialog = new FileDialog(getShell()); |
| 258 |
dialog.setFilterExtensions(new String[]{"*.ee"}); //$NON-NLS-1$ |
| 259 |
dialog.setFilterPath(fJRERoot.getText()); |
| 260 |
String newPath = dialog.open(); |
| 261 |
if (newPath != null) { |
| 262 |
fJRERoot.setText(newPath); |
| 263 |
} |
| 264 |
} |
| 265 |
}); |
| 266 |
applyDialogFont(parent); |
| 267 |
return parent; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Updates the JRE location status and initializes the library block |
| 272 |
*/ |
| 273 |
private void updateVMType() { |
| 274 |
int selIndex = fVMCombo.getSelectionIndex(); |
| 275 |
if (selIndex == fPrevIndex) { |
| 276 |
return; |
| 277 |
} |
| 278 |
fPrevIndex = selIndex; |
| 279 |
if (selIndex >= 0 && selIndex < fVMTypes.length) { |
| 280 |
fSelectedVMType= fVMTypes[selIndex]; |
| 281 |
} |
| 282 |
validateJRELocation(); |
| 283 |
fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType); |
| 284 |
updateFileButton(); |
| 285 |
updateStatusLine(); |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Updates enabled state of the "Definition File..." button. |
| 290 |
*/ |
| 291 |
private void updateFileButton() { |
| 292 |
fFileButton.setEnabled(fSelectedVMType.getId().equals(StandardVMType.ID_STANDARD_VM_TYPE)); |
| 293 |
} |
| 294 |
|
| 295 |
/* (non-Javadoc) |
| 296 |
* @see org.eclipse.jface.dialogs.StatusDialog#create() |
| 297 |
*/ |
| 298 |
public void create() { |
| 299 |
super.create(); |
| 300 |
if (fJRERoot.getText().length() == 0) { |
| 301 |
fJRERoot.setFocus(); |
| 302 |
} else { |
| 303 |
fVMName.setFocus(); |
| 304 |
} |
| 305 |
selectVMType(); |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Returns the VM type names |
| 310 |
* @return an array of strings with the names of the applicable VMs |
| 311 |
*/ |
| 312 |
private String[] getVMTypeNames() { |
| 313 |
String[] names = new String[fVMTypes.length]; |
| 314 |
for (int i = 0; i < fVMTypes.length; i++) { |
| 315 |
names[i]= fVMTypes[i].getName(); |
| 316 |
} |
| 317 |
return names; |
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* Selects the corresponding VM for fSelectedVMType |
| 322 |
*/ |
| 323 |
private void selectVMType() { |
| 324 |
for (int i= 0; i < fVMTypes.length; i++) { |
| 325 |
if (fSelectedVMType == fVMTypes[i]) { |
| 326 |
if(i < fVMCombo.getItemCount()) { |
| 327 |
fVMCombo.select(i); |
| 328 |
return; |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Initialize the dialogs fields |
| 336 |
*/ |
| 337 |
private void initializeFields() { |
| 338 |
if (fEditedVM == null) { |
| 339 |
fVMName.setText(""); //$NON-NLS-1$ |
| 340 |
fJRERoot.setText(""); //$NON-NLS-1$ |
| 341 |
fLibraryBlock.initializeFrom(null, fSelectedVMType); |
| 342 |
fVMArgs.setText(""); //$NON-NLS-1$ |
| 343 |
} else { |
| 344 |
fVMCombo.setEnabled(false); |
| 345 |
fVMName.setText(fEditedVM.getName()); |
| 346 |
fJRERoot.setText(fEditedVM.getInstallLocation().getAbsolutePath()); |
| 347 |
fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType); |
| 348 |
if (fEditedVM instanceof IVMInstall2) { |
| 349 |
IVMInstall2 vm2 = (IVMInstall2) fEditedVM; |
| 350 |
String vmArgs = vm2.getVMArgs(); |
| 351 |
if (vmArgs != null) { |
| 352 |
fVMArgs.setText(vmArgs); |
| 353 |
} |
| 354 |
} else { |
| 355 |
String[] vmArgs = fEditedVM.getVMArguments(); |
| 356 |
if (vmArgs != null) { |
| 357 |
StringBuffer buffer = new StringBuffer(); |
| 358 |
int length= vmArgs.length; |
| 359 |
if (length > 0) { |
| 360 |
buffer.append(vmArgs[0]); |
| 361 |
for (int i = 1; i < length; i++) { |
| 362 |
buffer.append(' ').append(vmArgs[i]); |
| 363 |
} |
| 364 |
} |
| 365 |
fVMArgs.setText(buffer.toString()); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
updateFileButton(); |
| 370 |
validateVMName(); |
| 371 |
updateStatusLine(); |
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* Validates the JRE location |
| 376 |
* @return the status after validating the JRE location |
| 377 |
*/ |
| 378 |
private IStatus validateJRELocation() { |
| 379 |
String locationName = fJRERoot.getText(); |
| 380 |
IStatus s = null; |
| 381 |
File file = null; |
| 382 |
if (locationName.length() == 0) { |
| 383 |
s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); |
| 384 |
} |
| 385 |
else { |
| 386 |
file = new File(locationName); |
| 387 |
if (!file.exists()) { |
| 388 |
s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); |
| 389 |
} |
| 390 |
else { |
| 391 |
final IStatus[] temp = new IStatus[1]; |
| 392 |
final File tempFile = file; |
| 393 |
Runnable r = new Runnable() { |
| 394 |
public void run() { |
| 395 |
temp[0] = fSelectedVMType.validateInstallLocation(tempFile); |
| 396 |
} |
| 397 |
}; |
| 398 |
BusyIndicator.showWhile(getShell().getDisplay(), r); |
| 399 |
s = temp[0]; |
| 400 |
} |
| 401 |
} |
| 402 |
if (s.isOK()) { |
| 403 |
fLibraryBlock.setHomeDirectory(file); |
| 404 |
String name = fVMName.getText(); |
| 405 |
if (name == null || name.trim().length() == 0) { |
| 406 |
// auto-generate VM name |
| 407 |
if (file.isFile()) { |
| 408 |
String fileName = file.getName(); |
| 409 |
int index = fileName.lastIndexOf(".ee"); //$NON-NLS-1$ |
| 410 |
if (index > 0) { |
| 411 |
fileName = fileName.substring(0, index); |
| 412 |
} |
| 413 |
fVMName.setText(fileName); |
| 414 |
} else { |
| 415 |
try { |
| 416 |
String genName = null; |
| 417 |
IPath path = new Path(file.getCanonicalPath()); |
| 418 |
int segs = path.segmentCount(); |
| 419 |
if (segs == 1) { |
| 420 |
genName = path.segment(0); |
| 421 |
} |
| 422 |
else if (segs >= 2) { |
| 423 |
String last = path.lastSegment(); |
| 424 |
if ("jre".equalsIgnoreCase(last)) { //$NON-NLS-1$ |
| 425 |
genName = path.segment(segs - 2); |
| 426 |
} |
| 427 |
else { |
| 428 |
genName = last; |
| 429 |
} |
| 430 |
} |
| 431 |
if (genName != null) { |
| 432 |
fVMName.setText(genName); |
| 433 |
} |
| 434 |
} catch (IOException e) {} |
| 435 |
} |
| 436 |
} |
| 437 |
} else { |
| 438 |
fLibraryBlock.setHomeDirectory(null); |
| 439 |
} |
| 440 |
fLibraryBlock.restoreDefaultLibraries(); |
| 441 |
detectJavadocLocation(); |
| 442 |
fStatus[1] = s; |
| 443 |
return s; |
| 444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* Auto-detects the default javadoc location |
| 448 |
*/ |
| 449 |
private void detectJavadocLocation() { |
| 450 |
if (fAutoDetectAttributes) { |
| 451 |
if (fSelectedVMType instanceof AbstractVMInstallType) { |
| 452 |
AbstractVMInstallType type = (AbstractVMInstallType)fSelectedVMType; |
| 453 |
fJavadocLocation = type.getDefaultJavadocLocation(getInstallLocation()); |
| 454 |
String args = type.getDefaultVMArguments(getInstallLocation()); |
| 455 |
if (args != null) { |
| 456 |
fVMArgs.setText(args); |
| 457 |
} |
| 458 |
} |
| 459 |
} else { |
| 460 |
fJavadocLocation = fEditedVM.getJavadocLocation(); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* Validates the entered name of the VM |
| 466 |
* @return the status of the name validation |
| 467 |
*/ |
| 468 |
private IStatus validateVMName() { |
| 469 |
StatusInfo status= new StatusInfo(); |
| 470 |
String name= fVMName.getText(); |
| 471 |
if (name == null || name.trim().length() == 0) { |
| 472 |
status.setInfo(JREMessages.addVMDialog_enterName); |
| 473 |
} else { |
| 474 |
if (fRequestor.isDuplicateName(name) && (fEditedVM == null || !name.equals(fEditedVM.getName()))) { |
| 475 |
status.setError(JREMessages.addVMDialog_duplicateName); |
| 476 |
} else { |
| 477 |
IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE); |
| 478 |
if (!s.isOK()) { |
| 479 |
status.setError(MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); |
| 480 |
} |
| 481 |
} |
| 482 |
} |
| 483 |
fStatus[0] = status; |
| 484 |
return status; |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Updates the status line to show/hide messages to the user |
| 489 |
*/ |
| 490 |
protected void updateStatusLine() { |
| 491 |
IStatus max= null; |
| 492 |
for (int i = 0; i < fStatus.length; i++) { |
| 493 |
IStatus curr = fStatus[i]; |
| 494 |
if (curr.matches(IStatus.ERROR)) { |
| 495 |
updateStatus(curr); |
| 496 |
return; |
| 497 |
} |
| 498 |
if (max == null || curr.getSeverity() > max.getSeverity()) { |
| 499 |
max = curr; |
| 500 |
} |
| 501 |
} |
| 502 |
updateStatus(max); |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Returns the URL for the javadoc location |
| 507 |
* @return the URL for the javadoc location |
| 508 |
*/ |
| 509 |
protected URL getURL() { |
| 510 |
return fJavadocLocation; |
| 511 |
} |
| 512 |
|
| 513 |
/* (non-Javadoc) |
| 514 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed() |
| 515 |
*/ |
| 516 |
protected void okPressed() { |
| 517 |
if (fEditedVM == null) { |
| 518 |
IVMInstall vm = new VMStandin(fSelectedVMType, createUniqueId(fSelectedVMType)); |
| 519 |
setFieldValuesToVM(vm); |
| 520 |
fRequestor.vmAdded(vm); |
| 521 |
} else { |
| 522 |
setFieldValuesToVM(fEditedVM); |
| 523 |
} |
| 524 |
super.okPressed(); |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Creates a unique name for the VMInstallType |
| 529 |
* @param vmType the vm install type |
| 530 |
* @return a unique name |
| 531 |
*/ |
| 532 |
private String createUniqueId(IVMInstallType vmType) { |
| 533 |
String id = null; |
| 534 |
do { |
| 535 |
id = String.valueOf(System.currentTimeMillis()); |
| 536 |
} while (vmType.findVMInstall(id) != null); |
| 537 |
return id; |
| 538 |
} |
| 539 |
|
| 540 |
/** |
| 541 |
* initialize fields to the specified VM |
| 542 |
* @param vm the VM to initialize from |
| 543 |
*/ |
| 544 |
protected void setFieldValuesToVM(IVMInstall vm) { |
| 545 |
File dir = new File(fJRERoot.getText()); |
| 546 |
try { |
| 547 |
vm.setInstallLocation(dir.getCanonicalFile()); |
| 548 |
} |
| 549 |
catch (IOException e) { |
| 550 |
vm.setInstallLocation(dir.getAbsoluteFile()); |
| 551 |
} |
| 552 |
vm.setName(fVMName.getText()); |
| 553 |
vm.setJavadocLocation(getURL()); |
| 554 |
|
| 555 |
String argString = fVMArgs.getText().trim(); |
| 556 |
if (vm instanceof IVMInstall2) { |
| 557 |
IVMInstall2 vm2 = (IVMInstall2) vm; |
| 558 |
if (argString != null && argString.length() > 0) { |
| 559 |
vm2.setVMArgs(argString); |
| 560 |
} |
| 561 |
else { |
| 562 |
vm2.setVMArgs(null); |
| 563 |
} |
| 564 |
} |
| 565 |
else { |
| 566 |
if (argString != null && argString.length() > 0) { |
| 567 |
vm.setVMArguments(DebugPlugin.parseArguments(argString)); |
| 568 |
} |
| 569 |
else { |
| 570 |
vm.setVMArguments(null); |
| 571 |
} |
| 572 |
} |
| 573 |
fLibraryBlock.performApply(vm); |
| 574 |
} |
| 575 |
|
| 576 |
/** |
| 577 |
* returns an absolute file or an empty file if the path is either null or zero length |
| 578 |
* @param path the path to the file |
| 579 |
* @return a new file |
| 580 |
*/ |
| 581 |
protected File getAbsoluteFileOrEmpty(String path) { |
| 582 |
if (path == null || path.length() == 0) { |
| 583 |
return new File(""); //$NON-NLS-1$ |
| 584 |
} |
| 585 |
return new File(path).getAbsoluteFile(); |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* @return the status of the system library |
| 590 |
*/ |
| 591 |
protected IStatus getSystemLibraryStatus() { |
| 592 |
return fStatus[3]; |
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* Allows the VM page to set the status of the current system library |
| 597 |
* @param status the specified status |
| 598 |
*/ |
| 599 |
protected void setSystemLibraryStatus(IStatus status) { |
| 600 |
fStatus[3] = status; |
| 601 |
} |
| 602 |
|
| 603 |
/** |
| 604 |
* Updates the status of the OK button to reflect the given status. |
| 605 |
* Subclasses may override this method to update additional buttons. |
| 606 |
* @param status the status. |
| 607 |
*/ |
| 608 |
protected void updateButtonsEnableState(IStatus status) { |
| 609 |
Button ok = getButton(IDialogConstants.OK_ID); |
| 610 |
if (ok != null && !ok.isDisposed()) |
| 611 |
ok.setEnabled(status.getSeverity() == IStatus.OK); |
| 612 |
} |
| 613 |
|
| 614 |
/** |
| 615 |
* Returns the name of the section that this dialog stores its settings in |
| 616 |
* |
| 617 |
* @return String |
| 618 |
*/ |
| 619 |
protected String getDialogSettingsSectionName() { |
| 620 |
return "ADD_VM_DIALOG_SECTION"; //$NON-NLS-1$ |
| 621 |
} |
| 622 |
|
| 623 |
/* (non-Javadoc) |
| 624 |
* @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings() |
| 625 |
*/ |
| 626 |
protected IDialogSettings getDialogBoundsSettings() { |
| 627 |
IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings(); |
| 628 |
IDialogSettings section = settings.getSection(getDialogSettingsSectionName()); |
| 629 |
if (section == null) { |
| 630 |
section = settings.addNewSection(getDialogSettingsSectionName()); |
| 631 |
} |
| 632 |
return section; |
| 633 |
} |
| 634 |
|
| 635 |
/* (non-Javadoc) |
| 636 |
* @see org.eclipse.jface.dialogs.Dialog#getInitialSize() |
| 637 |
*/ |
| 638 |
protected Point getInitialSize() { |
| 639 |
IDialogSettings settings = getDialogBoundsSettings(); |
| 640 |
if(settings != null) { |
| 641 |
try { |
| 642 |
int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$ |
| 643 |
int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$ |
| 644 |
if(width > 0 & height > 0) { |
| 645 |
return new Point(width, height); |
| 646 |
} |
| 647 |
} |
| 648 |
catch (NumberFormatException nfe) { |
| 649 |
return new Point(500, 570); |
| 650 |
} |
| 651 |
} |
| 652 |
return new Point(500, 570); |
| 653 |
} |
| 654 |
|
| 655 |
protected void setButtonLayoutData(Button button) { |
| 656 |
super.setButtonLayoutData(button); |
| 657 |
} |
| 658 |
|
| 659 |
} |