| 43 | | public class AddVMDialog extends StatusDialog { |
|---|
| 44 | | |
|---|
| 45 | | private IAddVMDialogRequestor fRequestor; |
|---|
| 46 | | |
|---|
| 47 | | private IVMInstall fEditedVM; |
|---|
| 48 | | |
|---|
| 49 | | private IVMInstallType[] fVMTypes; |
|---|
| 50 | | private IVMInstallType fSelectedVMType; |
|---|
| 51 | | |
|---|
| 52 | | private ComboDialogField fVMTypeCombo; |
|---|
| 53 | | private VMLibraryBlock fLibraryBlock; |
|---|
| 54 | | |
|---|
| 55 | | private StringButtonDialogField fJRERoot; |
|---|
| 56 | | private StringDialogField fVMName; |
|---|
| 57 | | |
|---|
| 58 | | // the VM install's javadoc location |
|---|
| 59 | | private URL fJavadocLocation = null; |
|---|
| 60 | | private boolean fAutoDetectJavadocLocation = false; |
|---|
| 61 | | |
|---|
| 62 | | private IStatus[] fStati; |
|---|
| 63 | | private int fPrevIndex = -1; |
|---|
| 64 | | |
|---|
| 65 | | public AddVMDialog(IAddVMDialogRequestor requestor, Shell shell, IVMInstallType[] vmInstallTypes, IVMInstall editedVM) { |
|---|
| 66 | | super(shell); |
|---|
| 67 | | setShellStyle(getShellStyle() | SWT.RESIZE); |
|---|
| 68 | | fRequestor= requestor; |
|---|
| 69 | | fStati= new IStatus[5]; |
|---|
| 70 | | for (int i= 0; i < fStati.length; i++) { |
|---|
| 71 | | fStati[i]= new StatusInfo(); |
|---|
| | 44 | /** |
|---|
| | 45 | * Dialog that allows the user to add or edit compiler definitions. |
|---|
| | 46 | * |
|---|
| | 47 | * @author oranda |
|---|
| | 48 | * |
|---|
| | 49 | */ |
|---|
| | 50 | public class AddCompilerDialog extends StatusDialog |
|---|
| | 51 | { |
|---|
| | 52 | private IAddCompilerDialogRequestor fRequestor; |
|---|
| | 53 | |
|---|
| | 54 | private ICompilerInstall fEditedCompiler; |
|---|
| | 55 | |
|---|
| | 56 | private ICompilerInstallType[] fCompilerTypes; |
|---|
| | 57 | |
|---|
| | 58 | private ICompilerInstallType fSelectedCompilerType; |
|---|
| | 59 | |
|---|
| | 60 | private ComboDialogField fCompilerTypeCombo; |
|---|
| | 61 | |
|---|
| | 62 | private CompilerDirectoryBlock fSourceDirectoryBlock; |
|---|
| | 63 | |
|---|
| | 64 | private CompilerDirectoryBlock fLibraryDirectoryBlock; |
|---|
| | 65 | |
|---|
| | 66 | private CompilerDirectoryBlock fExecutableDirectoryBlock; |
|---|
| | 67 | |
|---|
| | 68 | private TabFolder tabFolder; |
|---|
| | 69 | |
|---|
| | 70 | private StringButtonDialogField fCompilerExecutable; |
|---|
| | 71 | |
|---|
| | 72 | private StringDialogField fCompilerName; |
|---|
| | 73 | |
|---|
| | 74 | // the VM install's javadoc location |
|---|
| | 75 | private URL fJavadocLocation = null; |
|---|
| | 76 | |
|---|
| | 77 | private boolean fAutoDetectJavadocLocation = false; |
|---|
| | 78 | |
|---|
| | 79 | private IStatus[] fStati; |
|---|
| | 80 | |
|---|
| | 81 | private int fPrevIndex = -1; |
|---|
| | 82 | |
|---|
| | 83 | public AddCompilerDialog(IAddCompilerDialogRequestor requestor, Shell shell, |
|---|
| | 84 | ICompilerInstallType[] compilerInstallTypes, ICompilerInstall editedCompiler) |
|---|
| | 85 | { |
|---|
| | 86 | super(shell); |
|---|
| | 87 | setShellStyle(getShellStyle() | SWT.RESIZE); |
|---|
| | 88 | fRequestor = requestor; |
|---|
| | 89 | fStati = new IStatus[5]; |
|---|
| | 90 | for (int i = 0; i < fStati.length; i++) |
|---|
| | 91 | { |
|---|
| | 92 | fStati[i] = new StatusInfo(); |
|---|
| | 93 | } |
|---|
| | 94 | |
|---|
| | 95 | fCompilerTypes = compilerInstallTypes; |
|---|
| | 96 | fSelectedCompilerType = editedCompiler != null ? editedCompiler.getVMInstallType() |
|---|
| | 97 | : compilerInstallTypes[0]; |
|---|
| | 98 | |
|---|
| | 99 | fEditedCompiler = editedCompiler; |
|---|
| | 100 | |
|---|
| | 101 | //only detect the javadoc location if not already set |
|---|
| | 102 | fAutoDetectJavadocLocation = fEditedCompiler == null |
|---|
| | 103 | || fEditedCompiler.getJavadocLocation() == null; |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | /** |
|---|
| | 107 | * @see Windows#configureShell |
|---|
| | 108 | */ |
|---|
| | 109 | protected void configureShell(Shell newShell) |
|---|
| | 110 | { |
|---|
| | 111 | super.configureShell(newShell); |
|---|
| | 112 | PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, |
|---|
| | 113 | IJavaDebugHelpContextIds.EDIT_JRE_DIALOG); |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 116 | protected void createDialogFields() |
|---|
| | 117 | { |
|---|
| | 118 | fCompilerTypeCombo = new ComboDialogField(SWT.READ_ONLY); |
|---|
| | 119 | fCompilerTypeCombo.setLabelText("Compiler &type:"); |
|---|
| | 120 | fCompilerTypeCombo.setItems(getCompilerTypeNames()); |
|---|
| | 121 | |
|---|
| | 122 | fCompilerName = new StringDialogField(); |
|---|
| | 123 | fCompilerName.setLabelText("Compiler &name:"); |
|---|
| | 124 | |
|---|
| | 125 | fCompilerExecutable = new StringButtonDialogField(new IStringButtonAdapter() |
|---|
| | 126 | { |
|---|
| | 127 | public void changeControlPressed(DialogField field) |
|---|
| | 128 | { |
|---|
| | 129 | browseForInstallDir(); |
|---|
| | 130 | } |
|---|
| | 131 | }); |
|---|
| | 132 | fCompilerExecutable.setLabelText("&Compiler home directory:"); |
|---|
| | 133 | fCompilerExecutable.setButtonLabel("&Browse..."); |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | protected void createFieldListeners() |
|---|
| | 137 | { |
|---|
| | 138 | fCompilerTypeCombo.setDialogFieldListener(new IDialogFieldListener() |
|---|
| | 139 | { |
|---|
| | 140 | public void dialogFieldChanged(DialogField field) |
|---|
| | 141 | { |
|---|
| | 142 | updateCompilerType(); |
|---|
| | 143 | } |
|---|
| | 144 | }); |
|---|
| | 145 | |
|---|
| | 146 | fCompilerName.setDialogFieldListener(new IDialogFieldListener() |
|---|
| | 147 | { |
|---|
| | 148 | public void dialogFieldChanged(DialogField field) |
|---|
| | 149 | { |
|---|
| | 150 | setVMNameStatus(validateCompilerName()); |
|---|
| | 151 | updateStatusLine(); |
|---|
| | 152 | } |
|---|
| | 153 | }); |
|---|
| | 154 | |
|---|
| | 155 | fCompilerExecutable.setDialogFieldListener(new IDialogFieldListener() |
|---|
| | 156 | { |
|---|
| | 157 | public void dialogFieldChanged(DialogField field) |
|---|
| | 158 | { |
|---|
| | 159 | setJRELocationStatus(validateCompilerExecutableLocation()); |
|---|
| | 160 | updateStatusLine(); |
|---|
| | 161 | } |
|---|
| | 162 | }); |
|---|
| | 163 | |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | protected String getVMName() |
|---|
| | 167 | { |
|---|
| | 168 | return fCompilerName.getText(); |
|---|
| | 169 | } |
|---|
| | 170 | |
|---|
| | 171 | protected File getInstallLocation() |
|---|
| | 172 | { |
|---|
| | 173 | return new File(fCompilerExecutable.getText()); |
|---|
| | 174 | } |
|---|
| | 175 | |
|---|
| | 176 | protected Control createDialogArea(Composite ancestor) |
|---|
| | 177 | { |
|---|
| | 178 | createDialogFields(); |
|---|
| | 179 | Composite parent = (Composite) super.createDialogArea(ancestor); |
|---|
| | 180 | |
|---|
| | 181 | //create the general settings area |
|---|
| | 182 | ((GridLayout) parent.getLayout()).numColumns = 3; |
|---|
| | 183 | |
|---|
| | 184 | fCompilerTypeCombo.doFillIntoGrid(parent, 3); |
|---|
| | 185 | ((GridData) fCompilerTypeCombo.getComboControl(null).getLayoutData()).widthHint = convertWidthInCharsToPixels(50); |
|---|
| | 186 | |
|---|
| | 187 | fCompilerName.doFillIntoGrid(parent, 3); |
|---|
| | 188 | |
|---|
| | 189 | fCompilerExecutable.doFillIntoGrid(parent, 3); |
|---|
| | 190 | |
|---|
| | 191 | //create the tab folder for the directory lists |
|---|
| | 192 | tabFolder = new TabFolder(parent, SWT.BORDER); |
|---|
| | 193 | GridData gd = new GridData(GridData.FILL_BOTH); |
|---|
| | 194 | gd.horizontalSpan = 3; |
|---|
| | 195 | tabFolder.setLayoutData(gd); |
|---|
| | 196 | |
|---|
| | 197 | //create the source files directory list |
|---|
| | 198 | fSourceDirectoryBlock = new CompilerDirectoryBlock(this); |
|---|
| | 199 | Control block = fSourceDirectoryBlock.createControl(tabFolder); |
|---|
| | 200 | block.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|---|
| | 201 | |
|---|
| | 202 | TabItem item = new TabItem(tabFolder, SWT.NULL); |
|---|
| | 203 | item.setText("Source Dirs"); |
|---|
| | 204 | item.setControl(block); |
|---|
| | 205 | |
|---|
| | 206 | //create the library files directory list |
|---|
| | 207 | fLibraryDirectoryBlock = new CompilerDirectoryBlock(this); |
|---|
| | 208 | block = fLibraryDirectoryBlock.createControl(tabFolder); |
|---|
| | 209 | block.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|---|
| | 210 | |
|---|
| | 211 | item = new TabItem(tabFolder, SWT.NULL); |
|---|
| | 212 | item.setText("Library Dirs"); |
|---|
| | 213 | item.setControl(block); |
|---|
| | 214 | |
|---|
| | 215 | //create the executable files directory list |
|---|
| | 216 | fExecutableDirectoryBlock = new CompilerDirectoryBlock(this); |
|---|
| | 217 | block = fExecutableDirectoryBlock.createControl(tabFolder); |
|---|
| | 218 | block.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|---|
| | 219 | |
|---|
| | 220 | item = new TabItem(tabFolder, SWT.NULL); |
|---|
| | 221 | item.setText("Executable Dirs"); |
|---|
| | 222 | item.setControl(block); |
|---|
| | 223 | |
|---|
| | 224 | //create stuff below the directories area |
|---|
| | 225 | Text t = fCompilerExecutable.getTextControl(parent); |
|---|
| | 226 | gd = (GridData) t.getLayoutData(); |
|---|
| | 227 | gd.grabExcessHorizontalSpace = true; |
|---|
| | 228 | gd.widthHint = convertWidthInCharsToPixels(50); |
|---|
| | 229 | |
|---|
| | 230 | initializeFields(); |
|---|
| | 231 | createFieldListeners(); |
|---|
| | 232 | applyDialogFont(parent); |
|---|
| | 233 | return parent; |
|---|
| | 234 | } |
|---|
| | 235 | |
|---|
| | 236 | private void updateCompilerType() |
|---|
| | 237 | { |
|---|
| | 238 | int selIndex = fCompilerTypeCombo.getSelectionIndex(); |
|---|
| | 239 | if (selIndex == fPrevIndex) |
|---|
| | 240 | { |
|---|
| | 241 | return; |
|---|
| | 242 | } |
|---|
| | 243 | fPrevIndex = selIndex; |
|---|
| | 244 | if (selIndex >= 0 && selIndex < fCompilerTypes.length) |
|---|
| | 245 | { |
|---|
| | 246 | fSelectedCompilerType = fCompilerTypes[selIndex]; |
|---|
| | 247 | } |
|---|
| | 248 | setJRELocationStatus(validateCompilerExecutableLocation()); |
|---|
| | 249 | fSourceDirectoryBlock.initializeFrom(fEditedCompiler, fSelectedCompilerType); |
|---|
| | 250 | updateStatusLine(); |
|---|
| | 251 | } |
|---|
| | 252 | |
|---|
| | 253 | public void create() |
|---|
| | 254 | { |
|---|
| | 255 | super.create(); |
|---|
| | 256 | fCompilerName.setFocus(); |
|---|
| | 257 | selectCompilerType(); |
|---|
| | 258 | } |
|---|
| | 259 | |
|---|
| | 260 | private String[] getCompilerTypeNames() |
|---|
| | 261 | { |
|---|
| | 262 | String[] names = new String[fCompilerTypes.length]; |
|---|
| | 263 | for (int i = 0; i < fCompilerTypes.length; i++) |
|---|
| | 264 | { |
|---|
| | 265 | names[i] = fCompilerTypes[i].getName(); |
|---|
| | 266 | } |
|---|
| | 267 | return names; |
|---|
| | 268 | } |
|---|
| | 269 | |
|---|
| | 270 | private void selectCompilerType() |
|---|
| | 271 | { |
|---|
| | 272 | for (int i = 0; i < fCompilerTypes.length; i++) |
|---|
| | 273 | { |
|---|
| | 274 | if (fSelectedCompilerType == fCompilerTypes[i]) |
|---|
| | 275 | { |
|---|
| | 276 | fCompilerTypeCombo.selectItem(i); |
|---|
| | 277 | return; |
|---|
| | 278 | } |
|---|
| | 279 | } |
|---|
| | 280 | } |
|---|
| | 281 | |
|---|
| | 282 | private void initializeFields() |
|---|
| | 283 | { |
|---|
| | 284 | fCompilerTypeCombo.setItems(getCompilerTypeNames()); |
|---|
| | 285 | if (fEditedCompiler == null) |
|---|
| | 286 | { |
|---|
| | 287 | fCompilerName.setText(""); |
|---|
| | 288 | fCompilerExecutable.setText(""); |
|---|
| | 289 | fSourceDirectoryBlock.initializeFrom(null, fSelectedCompilerType); |
|---|
| | 290 | } |
|---|
| | 291 | else |
|---|
| | 292 | { |
|---|
| | 293 | fCompilerTypeCombo.setEnabled(false); |
|---|
| | 294 | fCompilerName.setText(fEditedCompiler.getName()); |
|---|
| | 295 | fCompilerExecutable.setText(fEditedCompiler.getInstallLocation().getAbsolutePath()); |
|---|
| | 296 | fSourceDirectoryBlock.initializeFrom(fEditedCompiler, fSelectedCompilerType); |
|---|
| | 297 | } |
|---|
| | 298 | setVMNameStatus(validateCompilerName()); |
|---|
| | 299 | updateStatusLine(); |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | private ICompilerInstallType getVMType() |
|---|
| | 303 | { |
|---|
| | 304 | return fSelectedCompilerType; |
|---|
| | 305 | } |
|---|
| | 306 | |
|---|
| | 307 | private IStatus validateCompilerExecutableLocation() |
|---|
| | 308 | { |
|---|
| | 309 | String locationName = fCompilerExecutable.getText().trim(); |
|---|
| | 310 | IStatus s = null; |
|---|
| | 311 | File file = null; |
|---|
| | 312 | if (locationName.length() == 0) |
|---|
| | 313 | { |
|---|
| | 314 | s = new StatusInfo(IStatus.INFO, |
|---|
| | 315 | "Enter the location of the compiler."); |
|---|
| | 316 | } |
|---|
| | 317 | else |
|---|
| | 318 | { |
|---|
| | 319 | file = new File(locationName); |
|---|
| | 320 | if (!file.exists()) |
|---|
| | 321 | { |
|---|
| | 322 | s = new StatusInfo(IStatus.ERROR, |
|---|
| | 323 | "The location does not exist."); |
|---|
| | 324 | } |
|---|
| | 325 | else |
|---|
| | 326 | { |
|---|
| | 327 | final IStatus[] temp = new IStatus[1]; |
|---|
| | 328 | final File tempFile = file; |
|---|
| | 329 | Runnable r = new Runnable() |
|---|
| | 330 | { |
|---|
| | 331 | /** |
|---|
| | 332 | * @see java.lang.Runnable#run() |
|---|
| | 333 | */ |
|---|
| | 334 | public void run() |
|---|
| | 335 | { |
|---|
| | 336 | temp[0] = getVMType().validateInstallLocation(tempFile); |
|---|
| | 337 | } |
|---|
| | 338 | }; |
|---|
| | 339 | BusyIndicator.showWhile(getShell().getDisplay(), r); |
|---|
| | 340 | s = temp[0]; |
|---|
| | 341 | } |
|---|
| | 342 | } |
|---|
| | 343 | if (s.isOK()) |
|---|
| | 344 | { |
|---|
| | 345 | fSourceDirectoryBlock.setHomeDirectory(file); |
|---|
| | 346 | String name = fCompilerName.getText(); |
|---|
| | 347 | if (name == null || name.trim().length() == 0) |
|---|
| | 348 | { |
|---|
| | 349 | // auto-generate VM name |
|---|
| | 350 | fCompilerName.setText(VMInstallTypeUtil.getVMInstallName( |
|---|
| | 351 | fSelectedCompilerType, file)); |
|---|
| | 352 | } |
|---|
| | 353 | } |
|---|
| | 354 | else |
|---|
| | 355 | { |
|---|
| | 356 | fSourceDirectoryBlock.setHomeDirectory(null); |
|---|
| | 357 | } |
|---|
| | 358 | fSourceDirectoryBlock.restoreDefaultDirectories(); |
|---|
| | 359 | detectJavadocLocation(); |
|---|
| | 360 | return s; |
|---|
| | 361 | } |
|---|
| | 362 | |
|---|
| | 363 | /** |
|---|
| | 364 | * Auto-detects the default javadoc location |
|---|
| | 365 | */ |
|---|
| | 366 | private void detectJavadocLocation() |
|---|
| | 367 | { |
|---|
| | 368 | if (fAutoDetectJavadocLocation) |
|---|
| | 369 | { |
|---|
| | 370 | if (getVMType() instanceof AbstractVMInstallType) |
|---|
| | 371 | { |
|---|
| | 372 | AbstractVMInstallType type = (AbstractVMInstallType) getVMType(); |
|---|
| | 373 | fJavadocLocation = type |
|---|
| | 374 | .getDefaultJavadocLocation(getInstallLocation()); |
|---|
| | 375 | } |
|---|
| | 376 | } |
|---|
| | 377 | else |
|---|
| | 378 | { |
|---|
| | 379 | fJavadocLocation = fEditedCompiler.getJavadocLocation(); |
|---|
| | 380 | } |
|---|
| | 381 | } |
|---|
| | 382 | |
|---|
| | 383 | private IStatus validateCompilerName() |
|---|
| | 384 | { |
|---|
| | 385 | StatusInfo status = new StatusInfo(); |
|---|
| | 386 | String name = fCompilerName.getText(); |
|---|
| | 387 | if (name == null || name.trim().length() == 0) |
|---|
| | 388 | { |
|---|
| | 389 | status.setInfo("Enter a name for the compiler."); |
|---|
| | 390 | } |
|---|
| | 391 | else |
|---|
| | 392 | { |
|---|
| | 393 | if (fRequestor.isDuplicateName(name) |
|---|
| | 394 | && (fEditedCompiler == null || !name.equals(fEditedCompiler.getName()))) |
|---|
| | 395 | { |
|---|
| | 396 | status.setError("The name is already used."); |
|---|
| | 397 | } |
|---|
| | 398 | else |
|---|
| | 399 | { |
|---|
| | 400 | IStatus s = ResourcesPlugin.getWorkspace().validateName(name, |
|---|
| | 401 | IResource.FILE); |
|---|
| | 402 | if (!s.isOK()) |
|---|
| | 403 | { |
|---|
| | 404 | status.setError(MessageFormat.format( |
|---|
| | 405 | "Compiler name must be a valid file name: {0}", |
|---|
| | 406 | new String[] |
|---|
| | 407 | { s.getMessage() })); |
|---|
| 73 | | |
|---|
| 74 | | fVMTypes= vmInstallTypes; |
|---|
| 75 | | fSelectedVMType= editedVM != null ? editedVM.getVMInstallType() : vmInstallTypes[0]; |
|---|
| 76 | | |
|---|
| 77 | | fEditedVM= editedVM; |
|---|
| 78 | | |
|---|
| 79 | | //only detect the javadoc location if not already set |
|---|
| 80 | | fAutoDetectJavadocLocation = fEditedVM == null || fEditedVM.getJavadocLocation() == null; |
|---|
| 81 | | } |
|---|
| 82 | | |
|---|
| 83 | | /** |
|---|
| 84 | | * @see Windows#configureShell |
|---|
| 85 | | */ |
|---|
| 86 | | protected void configureShell(Shell newShell) { |
|---|
| 87 | | super.configureShell(newShell); |
|---|
| 88 | | PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaDebugHelpContextIds.EDIT_JRE_DIALOG); |
|---|
| 89 | | } |
|---|
| 90 | | |
|---|
| 91 | | protected void createDialogFields() { |
|---|
| 92 | | fVMTypeCombo= new ComboDialogField(SWT.READ_ONLY); |
|---|
| 93 | | fVMTypeCombo.setLabelText(JREMessages.addVMDialog_jreType); |
|---|
| 94 | | fVMTypeCombo.setItems(getVMTypeNames()); |
|---|
| 95 | | |
|---|
| 96 | | fVMName= new StringDialogField(); |
|---|
| 97 | | fVMName.setLabelText(JREMessages.addVMDialog_jreName); |
|---|
| 98 | | |
|---|
| 99 | | fJRERoot= new StringButtonDialogField(new IStringButtonAdapter() { |
|---|
| 100 | | public void changeControlPressed(DialogField field) { |
|---|
| 101 | | browseForInstallDir(); |
|---|
| 102 | | } |
|---|
| 103 | | }); |
|---|
| 104 | | fJRERoot.setLabelText(JREMessages.addVMDialog_jreHome); |
|---|
| 105 | | fJRERoot.setButtonLabel(JREMessages.addVMDialog_browse1); |
|---|
| 106 | | } |
|---|
| 107 | | |
|---|
| 108 | | protected void createFieldListeners() { |
|---|
| 109 | | fVMTypeCombo.setDialogFieldListener(new IDialogFieldListener() { |
|---|
| 110 | | public void dialogFieldChanged(DialogField field) { |
|---|
| 111 | | updateVMType(); |
|---|
| 112 | | } |
|---|
| 113 | | }); |
|---|
| 114 | | |
|---|
| 115 | | fVMName.setDialogFieldListener(new IDialogFieldListener() { |
|---|
| 116 | | public void dialogFieldChanged(DialogField field) { |
|---|
| 117 | | setVMNameStatus(validateVMName()); |
|---|
| 118 | | updateStatusLine(); |
|---|
| 119 | | } |
|---|
| 120 | | }); |
|---|
| 121 | | |
|---|
| 122 | | fJRERoot.setDialogFieldListener(new IDialogFieldListener() { |
|---|
| 123 | | public void dialogFieldChanged(DialogField field) { |
|---|
| 124 | | setJRELocationStatus(validateJRELocation()); |
|---|
| 125 | | updateStatusLine(); |
|---|
| 126 | | } |
|---|
| 127 | | }); |
|---|
| 128 | | |
|---|
| 129 | | } |
|---|
| 130 | | |
|---|
| 131 | | protected String getVMName() { |
|---|
| 132 | | return fVMName.getText(); |
|---|
| 133 | | } |
|---|
| 134 | | |
|---|
| 135 | | protected File getInstallLocation() { |
|---|
| 136 | | return new File(fJRERoot.getText()); |
|---|
| 137 | | } |
|---|
| 138 | | |
|---|
| 139 | | protected Control createDialogArea(Composite ancestor) { |
|---|
| 140 | | createDialogFields(); |
|---|
| 141 | | Composite parent = (Composite)super.createDialogArea(ancestor); |
|---|
| 142 | | ((GridLayout)parent.getLayout()).numColumns= 3; |
|---|
| 143 | | |
|---|
| 144 | | fVMTypeCombo.doFillIntoGrid(parent, 3); |
|---|
| 145 | | ((GridData)fVMTypeCombo.getComboControl(null).getLayoutData()).widthHint= convertWidthInCharsToPixels(50); |
|---|
| 146 | | |
|---|
| 147 | | fVMName.doFillIntoGrid(parent, 3); |
|---|
| 148 | | |
|---|
| 149 | | fJRERoot.doFillIntoGrid(parent, 3); |
|---|
| 150 | | |
|---|
| 151 | | Label l = new Label(parent, SWT.NONE); |
|---|
| 152 | | l.setText(JREMessages.AddVMDialog_JRE_system_libraries__1); |
|---|
| 153 | | GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
|---|
| 154 | | gd.horizontalSpan = 3; |
|---|
| 155 | | l.setLayoutData(gd); |
|---|
| 156 | | |
|---|
| 157 | | fLibraryBlock = new VMLibraryBlock(this); |
|---|
| 158 | | Control block = fLibraryBlock.createControl(parent); |
|---|
| 159 | | gd = new GridData(GridData.FILL_BOTH); |
|---|
| 160 | | gd.horizontalSpan = 3; |
|---|
| 161 | | block.setLayoutData(gd); |
|---|
| 162 | | |
|---|
| 163 | | Text t= fJRERoot.getTextControl(parent); |
|---|
| 164 | | gd= (GridData)t.getLayoutData(); |
|---|
| 165 | | gd.grabExcessHorizontalSpace=true; |
|---|
| 166 | | gd.widthHint= convertWidthInCharsToPixels(50); |
|---|
| 167 | | |
|---|
| 168 | | initializeFields(); |
|---|
| 169 | | createFieldListeners(); |
|---|
| 170 | | applyDialogFont(parent); |
|---|
| 171 | | return parent; |
|---|
| 172 | | } |
|---|
| 173 | | |
|---|
| 174 | | private void updateVMType() { |
|---|
| 175 | | int selIndex= fVMTypeCombo.getSelectionIndex(); |
|---|
| 176 | | if (selIndex == fPrevIndex) { |
|---|
| 177 | | return; |
|---|
| 178 | | } |
|---|
| 179 | | fPrevIndex = selIndex; |
|---|
| 180 | | if (selIndex >= 0 && selIndex < fVMTypes.length) { |
|---|
| 181 | | fSelectedVMType= fVMTypes[selIndex]; |
|---|
| 182 | | } |
|---|
| 183 | | setJRELocationStatus(validateJRELocation()); |
|---|
| 184 | | fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType); |
|---|
| 185 | | updateStatusLine(); |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | public void create() { |
|---|
| 189 | | super.create(); |
|---|
| 190 | | fVMName.setFocus(); |
|---|
| 191 | | selectVMType(); |
|---|
| 192 | | } |
|---|
| 193 | | |
|---|
| 194 | | private String[] getVMTypeNames() { |
|---|
| 195 | | String[] names= new String[fVMTypes.length]; |
|---|
| 196 | | for (int i= 0; i < fVMTypes.length; i++) { |
|---|
| 197 | | names[i]= fVMTypes[i].getName(); |
|---|
| 198 | | } |
|---|
| 199 | | return names; |
|---|
| 200 | | } |
|---|
| 201 | | |
|---|
| 202 | | private void selectVMType() { |
|---|
| 203 | | for (int i= 0; i < fVMTypes.length; i++) { |
|---|
| 204 | | if (fSelectedVMType == fVMTypes[i]) { |
|---|
| 205 | | fVMTypeCombo.selectItem(i); |
|---|
| 206 | | return; |
|---|
| 207 | | } |
|---|
| 208 | | } |
|---|
| 209 | | } |
|---|
| 210 | | |
|---|
| 211 | | private void initializeFields() { |
|---|
| 212 | | fVMTypeCombo.setItems(getVMTypeNames()); |
|---|
| 213 | | if (fEditedVM == null) { |
|---|
| 214 | | fVMName.setText(""); //$NON-NLS-1$ |
|---|
| 215 | | fJRERoot.setText(""); //$NON-NLS-1$ |
|---|
| 216 | | fLibraryBlock.initializeFrom(null, fSelectedVMType); |
|---|
| 217 | | } else { |
|---|
| 218 | | fVMTypeCombo.setEnabled(false); |
|---|
| 219 | | fVMName.setText(fEditedVM.getName()); |
|---|
| 220 | | fJRERoot.setText(fEditedVM.getInstallLocation().getAbsolutePath()); |
|---|
| 221 | | fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType); |
|---|
| 222 | | } |
|---|
| 223 | | setVMNameStatus(validateVMName()); |
|---|
| 224 | | updateStatusLine(); |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | private IVMInstallType getVMType() { |
|---|
| 228 | | return fSelectedVMType; |
|---|
| 229 | | } |
|---|
| 230 | | |
|---|
| 231 | | private IStatus validateJRELocation() { |
|---|
| 232 | | String locationName= fJRERoot.getText().trim(); |
|---|
| 233 | | IStatus s = null; |
|---|
| 234 | | File file = null; |
|---|
| 235 | | if (locationName.length() == 0) { |
|---|
| 236 | | s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); |
|---|
| 237 | | } else { |
|---|
| 238 | | file= new File(locationName); |
|---|
| 239 | | if (!file.exists()) { |
|---|
| 240 | | s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); |
|---|
| 241 | | } else { |
|---|
| 242 | | final IStatus[] temp = new IStatus[1]; |
|---|
| 243 | | final File tempFile = file; |
|---|
| 244 | | Runnable r = new Runnable() { |
|---|
| 245 | | /** |
|---|
| 246 | | * @see java.lang.Runnable#run() |
|---|
| 247 | | */ |
|---|
| 248 | | public void run() { |
|---|
| 249 | | temp[0] = getVMType().validateInstallLocation(tempFile); |
|---|
| 250 | | } |
|---|
| 251 | | }; |
|---|
| 252 | | BusyIndicator.showWhile(getShell().getDisplay(), r); |
|---|
| 253 | | s = temp[0]; |
|---|
| 254 | | } |
|---|
| 255 | | } |
|---|
| 256 | | if (s.isOK()) { |
|---|
| 257 | | fLibraryBlock.setHomeDirectory(file); |
|---|
| 258 | | String name = fVMName.getText(); |
|---|
| 259 | | if (name == null || name.trim().length() == 0) { |
|---|
| 260 | | // auto-generate VM name |
|---|
| 261 | | fVMName.setText(VMInstallTypeUtil.getVMInstallName(fSelectedVMType, file)); |
|---|
| 262 | | } |
|---|
| 263 | | } else { |
|---|
| 264 | | fLibraryBlock.setHomeDirectory(null); |
|---|
| 265 | | } |
|---|
| 266 | | fLibraryBlock.restoreDefaultLibraries(); |
|---|
| 267 | | detectJavadocLocation(); |
|---|
| 268 | | return s; |
|---|
| 269 | | } |
|---|
| 270 | | |
|---|
| 271 | | /** |
|---|
| 272 | | * Auto-detects the default javadoc location |
|---|
| 273 | | */ |
|---|
| 274 | | private void detectJavadocLocation() { |
|---|
| 275 | | if (fAutoDetectJavadocLocation) { |
|---|
| 276 | | if (getVMType() instanceof AbstractVMInstallType) { |
|---|
| 277 | | AbstractVMInstallType type = (AbstractVMInstallType)getVMType(); |
|---|
| 278 | | fJavadocLocation = type.getDefaultJavadocLocation(getInstallLocation()); |
|---|
| 279 | | } |
|---|
| 280 | | } else { |
|---|
| 281 | | fJavadocLocation = fEditedVM.getJavadocLocation(); |
|---|
| 282 | | } |
|---|
| 283 | | } |
|---|
| 284 | | |
|---|
| 285 | | private IStatus validateVMName() { |
|---|
| 286 | | StatusInfo status= new StatusInfo(); |
|---|
| 287 | | String name= fVMName.getText(); |
|---|
| 288 | | if (name == null || name.trim().length() == 0) { |
|---|
| 289 | | status.setInfo(JREMessages.addVMDialog_enterName); |
|---|
| 290 | | } else { |
|---|
| 291 | | if (fRequestor.isDuplicateName(name) && (fEditedVM == null || !name.equals(fEditedVM.getName()))) { |
|---|
| 292 | | status.setError(JREMessages.addVMDialog_duplicateName); |
|---|
| 293 | | } else { |
|---|
| 294 | | IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE); |
|---|
| 295 | | if (!s.isOK()) { |
|---|
| 296 | | status.setError(MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); |
|---|
| 297 | | } |
|---|
| 298 | | } |
|---|
| 299 | | } |
|---|
| 300 | | return status; |
|---|
| 301 | | } |
|---|
| 302 | | |
|---|
| 303 | | protected void updateStatusLine() { |
|---|
| 304 | | IStatus max= null; |
|---|
| 305 | | for (int i= 0; i < fStati.length; i++) { |
|---|
| 306 | | IStatus curr= fStati[i]; |
|---|
| 307 | | if (curr.matches(IStatus.ERROR)) { |
|---|
| 308 | | updateStatus(curr); |
|---|
| 309 | | return; |
|---|
| 310 | | } |
|---|
| 311 | | if (max == null || curr.getSeverity() > max.getSeverity()) { |
|---|
| 312 | | max= curr; |
|---|
| 313 | | } |
|---|
| 314 | | } |
|---|
| 315 | | updateStatus(max); |
|---|
| 316 | | } |
|---|
| 317 | | |
|---|
| 318 | | private void browseForInstallDir() { |
|---|
| 319 | | DirectoryDialog dialog= new DirectoryDialog(getShell()); |
|---|
| 320 | | dialog.setFilterPath(fJRERoot.getText()); |
|---|
| 321 | | dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); |
|---|
| 322 | | String newPath= dialog.open(); |
|---|
| 323 | | if (newPath != null) { |
|---|
| 324 | | fJRERoot.setText(newPath); |
|---|
| 325 | | } |
|---|
| 326 | | } |
|---|
| 327 | | |
|---|
| 328 | | protected URL getURL() { |
|---|
| 329 | | return fJavadocLocation; |
|---|
| 330 | | } |
|---|
| 331 | | |
|---|
| 332 | | protected void okPressed() { |
|---|
| 333 | | doOkPressed(); |
|---|
| 334 | | super.okPressed(); |
|---|
| 335 | | } |
|---|
| 336 | | |
|---|
| 337 | | private void doOkPressed() { |
|---|
| 338 | | if (fEditedVM == null) { |
|---|
| 339 | | IVMInstall vm= new VMStandin(fSelectedVMType, createUniqueId(fSelectedVMType)); |
|---|
| 340 | | setFieldValuesToVM(vm); |
|---|
| 341 | | fRequestor.vmAdded(vm); |
|---|
| 342 | | } else { |
|---|
| 343 | | setFieldValuesToVM(fEditedVM); |
|---|
| 344 | | } |
|---|
| 345 | | } |
|---|
| 346 | | |
|---|
| 347 | | private String createUniqueId(IVMInstallType vmType) { |
|---|
| 348 | | String id= null; |
|---|
| 349 | | do { |
|---|
| 350 | | id= String.valueOf(System.currentTimeMillis()); |
|---|
| 351 | | } while (vmType.findVMInstall(id) != null); |
|---|
| 352 | | return id; |
|---|
| 353 | | } |
|---|
| 354 | | |
|---|
| 355 | | protected void setFieldValuesToVM(IVMInstall vm) { |
|---|
| 356 | | File dir = new File(fJRERoot.getText()); |
|---|
| 357 | | try { |
|---|
| 358 | | vm.setInstallLocation(dir.getCanonicalFile()); |
|---|
| 359 | | } catch (IOException e) { |
|---|
| 360 | | vm.setInstallLocation(dir.getAbsoluteFile()); |
|---|
| 361 | | } |
|---|
| 362 | | vm.setName(fVMName.getText()); |
|---|
| 363 | | vm.setJavadocLocation(getURL()); |
|---|
| 364 | | |
|---|
| 365 | | fLibraryBlock.performApply(vm); |
|---|
| 366 | | } |
|---|
| 367 | | |
|---|
| 368 | | protected File getAbsoluteFileOrEmpty(String path) { |
|---|
| 369 | | if (path == null || path.length() == 0) { |
|---|
| 370 | | return new File(""); //$NON-NLS-1$ |
|---|
| 371 | | } |
|---|
| 372 | | return new File(path).getAbsoluteFile(); |
|---|
| 373 | | } |
|---|
| 374 | | |
|---|
| 375 | | private void setVMNameStatus(IStatus status) { |
|---|
| 376 | | fStati[0]= status; |
|---|
| 377 | | } |
|---|
| 378 | | |
|---|
| 379 | | private void setJRELocationStatus(IStatus status) { |
|---|
| 380 | | fStati[1]= status; |
|---|
| 381 | | } |
|---|
| 382 | | |
|---|
| 383 | | protected IStatus getSystemLibraryStatus() { |
|---|
| 384 | | return fStati[3]; |
|---|
| 385 | | } |
|---|
| 386 | | |
|---|
| 387 | | protected void setSystemLibraryStatus(IStatus status) { |
|---|
| 388 | | fStati[3]= status; |
|---|
| 389 | | } |
|---|
| 390 | | |
|---|
| 391 | | /** |
|---|
| 392 | | * Updates the status of the ok button to reflect the given status. |
|---|
| 393 | | * Subclasses may override this method to update additional buttons. |
|---|
| 394 | | * @param status the status. |
|---|
| 395 | | */ |
|---|
| 396 | | protected void updateButtonsEnableState(IStatus status) { |
|---|
| 397 | | Button ok = getButton(IDialogConstants.OK_ID); |
|---|
| 398 | | if (ok != null && !ok.isDisposed()) |
|---|
| 399 | | ok.setEnabled(status.getSeverity() == IStatus.OK); |
|---|
| 400 | | } |
|---|
| 401 | | |
|---|
| 402 | | /** |
|---|
| 403 | | * @see org.eclipse.jface.dialogs.Dialog#setButtonLayoutData(org.eclipse.swt.widgets.Button) |
|---|
| 404 | | */ |
|---|
| 405 | | protected void setButtonLayoutData(Button button) { |
|---|
| 406 | | super.setButtonLayoutData(button); |
|---|
| 407 | | } |
|---|
| 408 | | |
|---|
| 409 | | /** |
|---|
| 410 | | * Returns the name of the section that this dialog stores its settings in |
|---|
| 411 | | * |
|---|
| 412 | | * @return String |
|---|
| 413 | | */ |
|---|
| 414 | | protected String getDialogSettingsSectionName() { |
|---|
| 415 | | return "ADD_VM_DIALOG_SECTION"; //$NON-NLS-1$ |
|---|
| 416 | | } |
|---|
| 417 | | |
|---|
| 418 | | /* (non-Javadoc) |
|---|
| | 409 | } |
|---|
| | 410 | } |
|---|
| | 411 | return status; |
|---|
| | 412 | } |
|---|
| | 413 | |
|---|
| | 414 | protected void updateStatusLine() |
|---|
| | 415 | { |
|---|
| | 416 | IStatus max = null; |
|---|
| | 417 | for (int i = 0; i < fStati.length; i++) |
|---|
| | 418 | { |
|---|
| | 419 | IStatus curr = fStati[i]; |
|---|
| | 420 | if (curr.matches(IStatus.ERROR)) |
|---|
| | 421 | { |
|---|
| | 422 | updateStatus(curr); |
|---|
| | 423 | return; |
|---|
| | 424 | } |
|---|
| | 425 | if (max == null || curr.getSeverity() > max.getSeverity()) |
|---|
| | 426 | { |
|---|
| | 427 | max = curr; |
|---|
| | 428 | } |
|---|
| | 429 | } |
|---|
| | 430 | updateStatus(max); |
|---|
| | 431 | } |
|---|
| | 432 | |
|---|
| | 433 | private void browseForInstallDir() |
|---|
| | 434 | { |
|---|
| | 435 | DirectoryDialog dialog = new DirectoryDialog(getShell()); |
|---|
| | 436 | dialog.setFilterPath(fCompilerExecutable.getText()); |
|---|
| | 437 | dialog |
|---|
| | 438 | .setMessage("Select the root directory of the compiler installation:"); |
|---|
| | 439 | String newPath = dialog.open(); |
|---|
| | 440 | if (newPath != null) |
|---|
| | 441 | { |
|---|
| | 442 | fCompilerExecutable.setText(newPath); |
|---|
| | 443 | } |
|---|
| | 444 | } |
|---|
| | 445 | |
|---|
| | 446 | protected URL getURL() |
|---|
| | 447 | { |
|---|
| | 448 | return fJavadocLocation; |
|---|
| | 449 | } |
|---|
| | 450 | |
|---|
| | 451 | protected void okPressed() |
|---|
| | 452 | { |
|---|
| | 453 | doOkPressed(); |
|---|
| | 454 | super.okPressed(); |
|---|
| | 455 | } |
|---|
| | 456 | |
|---|
| | 457 | private void doOkPressed() |
|---|
| | 458 | { |
|---|
| | 459 | if (fEditedCompiler == null) |
|---|
| | 460 | { |
|---|
| | 461 | ICompilerInstall vm = new VMStandin(fSelectedCompilerType, |
|---|
| | 462 | createUniqueId(fSelectedCompilerType)); |
|---|
| | 463 | setFieldValuesToVM(vm); |
|---|
| | 464 | fRequestor.compilerAdded(vm); |
|---|
| | 465 | } |
|---|
| | 466 | else |
|---|
| | 467 | { |
|---|
| | 468 | setFieldValuesToVM(fEditedCompiler); |
|---|
| | 469 | } |
|---|
| | 470 | } |
|---|
| | 471 | |
|---|
| | 472 | private String createUniqueId(ICompilerInstallType vmType) |
|---|
| | 473 | { |
|---|
| | 474 | String id = null; |
|---|
| | 475 | do |
|---|
| | 476 | { |
|---|
| | 477 | id = String.valueOf(System.currentTimeMillis()); |
|---|
| | 478 | } while (vmType.findVMInstall(id) != null); |
|---|
| | 479 | return id; |
|---|
| | 480 | } |
|---|
| | 481 | |
|---|
| | 482 | protected void setFieldValuesToVM(ICompilerInstall vm) |
|---|
| | 483 | { |
|---|
| | 484 | File dir = new File(fCompilerExecutable.getText()); |
|---|
| | 485 | try |
|---|
| | 486 | { |
|---|
| | 487 | vm.setInstallLocation(dir.getCanonicalFile()); |
|---|
| | 488 | } |
|---|
| | 489 | catch (IOException e) |
|---|
| | 490 | { |
|---|
| | 491 | vm.setInstallLocation(dir.getAbsoluteFile()); |
|---|
| | 492 | } |
|---|
| | 493 | vm.setName(fCompilerName.getText()); |
|---|
| | 494 | vm.setJavadocLocation(getURL()); |
|---|
| | 495 | |
|---|
| | 496 | fSourceDirectoryBlock.performApply(vm); |
|---|
| | 497 | } |
|---|
| | 498 | |
|---|
| | 499 | protected File getAbsoluteFileOrEmpty(String path) |
|---|
| | 500 | { |
|---|
| | 501 | if (path == null || path.length() == 0) |
|---|
| | 502 | { |
|---|
| | 503 | return new File(""); |
|---|
| | 504 | } |
|---|
| | 505 | return new File(path).getAbsoluteFile(); |
|---|
| | 506 | } |
|---|
| | 507 | |
|---|
| | 508 | private void setVMNameStatus(IStatus status) |
|---|
| | 509 | { |
|---|
| | 510 | fStati[0] = status; |
|---|
| | 511 | } |
|---|
| | 512 | |
|---|
| | 513 | private void setJRELocationStatus(IStatus status) |
|---|
| | 514 | { |
|---|
| | 515 | fStati[1] = status; |
|---|
| | 516 | } |
|---|
| | 517 | |
|---|
| | 518 | protected IStatus getSystemLibraryStatus() |
|---|
| | 519 | { |
|---|
| | 520 | return fStati[3]; |
|---|
| | 521 | } |
|---|
| | 522 | |
|---|
| | 523 | protected void setSystemLibraryStatus(IStatus status) |
|---|
| | 524 | { |
|---|
| | 525 | fStati[3] = status; |
|---|
| | 526 | } |
|---|
| | 527 | |
|---|
| | 528 | /** |
|---|
| | 529 | * Updates the status of the ok button to reflect the given status. |
|---|
| | 530 | * Subclasses may override this method to update additional buttons. |
|---|
| | 531 | * @param status the status. |
|---|
| | 532 | */ |
|---|
| | 533 | protected void updateButtonsEnableState(IStatus status) |
|---|
| | 534 | { |
|---|
| | 535 | Button ok = getButton(IDialogConstants.OK_ID); |
|---|
| | 536 | if (ok != null && !ok.isDisposed()) |
|---|
| | 537 | ok.setEnabled(status.getSeverity() == IStatus.OK); |
|---|
| | 538 | } |
|---|
| | 539 | |
|---|
| | 540 | /** |
|---|
| | 541 | * @see org.eclipse.jface.dialogs.Dialog#setButtonLayoutData(org.eclipse.swt.widgets.Button) |
|---|
| | 542 | */ |
|---|
| | 543 | protected void setButtonLayoutData(Button button) |
|---|
| | 544 | { |
|---|
| | 545 | super.setButtonLayoutData(button); |
|---|
| | 546 | } |
|---|
| | 547 | |
|---|
| | 548 | /** |
|---|
| | 549 | * Returns the name of the section that this dialog stores its settings in |
|---|
| | 550 | * |
|---|
| | 551 | * @return String |
|---|
| | 552 | */ |
|---|
| | 553 | protected String getDialogSettingsSectionName() |
|---|
| | 554 | { |
|---|
| | 555 | return "ADD_VM_DIALOG_SECTION"; |
|---|
| | 556 | } |
|---|
| | 557 | |
|---|
| | 558 | /* (non-Javadoc) |
|---|