1 11 package org.eclipse.debug.ui; 12 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.core.resources.IContainer; 21 import org.eclipse.core.resources.IFile; 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.resources.IResource; 24 import org.eclipse.core.resources.IWorkspaceRoot; 25 import org.eclipse.core.resources.ResourcesPlugin; 26 import org.eclipse.core.runtime.CoreException; 27 import org.eclipse.core.runtime.IPath; 28 import org.eclipse.core.runtime.Path; 29 import org.eclipse.core.variables.VariablesPlugin; 30 import org.eclipse.debug.core.DebugPlugin; 31 import org.eclipse.debug.core.ILaunchConfiguration; 32 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 33 import org.eclipse.debug.internal.ui.DebugUIPlugin; 34 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 35 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 36 import org.eclipse.debug.internal.ui.SWTFactory; 37 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; 38 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages; 39 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; 40 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; 41 import org.eclipse.jface.dialogs.IDialogConstants; 42 import org.eclipse.jface.dialogs.IDialogSettings; 43 import org.eclipse.jface.resource.ImageDescriptor; 44 import org.eclipse.jface.viewers.CheckStateChangedEvent; 45 import org.eclipse.jface.viewers.CheckboxTableViewer; 46 import org.eclipse.jface.viewers.ICheckStateListener; 47 import org.eclipse.jface.viewers.ILabelProviderListener; 48 import org.eclipse.jface.viewers.IStructuredContentProvider; 49 import org.eclipse.jface.viewers.ITableLabelProvider; 50 import org.eclipse.jface.viewers.Viewer; 51 import org.eclipse.swt.SWT; 52 import org.eclipse.swt.events.ModifyEvent; 53 import org.eclipse.swt.events.ModifyListener; 54 import org.eclipse.swt.events.SelectionAdapter; 55 import org.eclipse.swt.events.SelectionEvent; 56 import org.eclipse.swt.events.SelectionListener; 57 import org.eclipse.swt.graphics.Image; 58 import org.eclipse.swt.layout.GridData; 59 import org.eclipse.swt.layout.GridLayout; 60 import org.eclipse.swt.widgets.Button; 61 import org.eclipse.swt.widgets.Combo; 62 import org.eclipse.swt.widgets.Composite; 63 import org.eclipse.swt.widgets.Control; 64 import org.eclipse.swt.widgets.FileDialog; 65 import org.eclipse.swt.widgets.Group; 66 import org.eclipse.swt.widgets.Shell; 67 import org.eclipse.swt.widgets.Text; 68 import org.eclipse.ui.PlatformUI; 69 import org.eclipse.ui.WorkbenchEncoding; 70 import org.eclipse.ui.dialogs.ContainerSelectionDialog; 71 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 72 import org.eclipse.ui.ide.IDEEncoding; 73 import org.eclipse.ui.model.WorkbenchContentProvider; 74 import org.eclipse.ui.model.WorkbenchLabelProvider; 75 import org.eclipse.ui.views.navigator.ResourceComparator; 76 77 import com.ibm.icu.text.MessageFormat; 78 79 88 public class CommonTab extends AbstractLaunchConfigurationTab { 89 90 94 class SharedLocationSelectionDialog extends ContainerSelectionDialog { 95 private final String SETTINGS_ID = IDebugUIConstants.PLUGIN_ID + ".SHARED_LAUNCH_CONFIGURATON_DIALOG"; 97 public SharedLocationSelectionDialog(Shell parentShell, IContainer initialRoot, boolean allowNewContainerName, String message) { 98 super(parentShell, initialRoot, allowNewContainerName, message); 99 } 100 101 protected IDialogSettings getDialogBoundsSettings() { 102 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 103 IDialogSettings section = settings.getSection(SETTINGS_ID); 104 if (section == null) { 105 section = settings.addNewSection(SETTINGS_ID); 106 } 107 return section; 108 } 109 } 110 111 private static final String EMPTY_STRING = ""; 113 119 private static final String BAD_CONTAINER = "bad_container_name"; 121 private Button fLocalRadioButton; 123 private Button fSharedRadioButton; 124 private Text fSharedLocationText; 125 private Button fSharedLocationButton; 126 private Button fLaunchInBackgroundButton; 127 private Button fDefaultEncodingButton; 128 private Button fAltEncodingButton; 129 private Combo fEncodingCombo; 130 private Button fConsoleOutput; 131 private Button fFileOutput; 132 private Button fFileBrowse; 133 private Text fFileText; 134 private Button fVariables; 135 private Button fAppend; 136 private Button fWorkspaceBrowse; 137 138 141 private CheckboxTableViewer fFavoritesTable; 142 143 146 private ModifyListener fBasicModifyListener = new ModifyListener() { 147 public void modifyText(ModifyEvent evt) { 148 updateLaunchConfigurationDialog(); 149 } 150 }; 151 152 155 public void createControl(Composite parent) { 156 Composite comp = new Composite(parent, SWT.NONE); 157 setControl(comp); 158 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_COMMON_TAB); 159 comp.setLayout(new GridLayout(2, true)); 160 comp.setFont(parent.getFont()); 161 162 createSharedConfigComponent(comp); 163 createFavoritesComponent(comp); 164 createEncodingComponent(comp); 165 createOutputCaptureComponent(comp); 166 createLaunchInBackgroundComponent(comp); 167 } 168 169 174 private void createFavoritesComponent(Composite parent) { 175 Group favComp = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.CommonTab_Display_in_favorites_menu__10, 1, 1, GridData.FILL_BOTH); 176 fFavoritesTable = CheckboxTableViewer.newCheckList(favComp, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 177 Control table = fFavoritesTable.getControl(); 178 GridData gd = new GridData(GridData.FILL_BOTH); 179 table.setLayoutData(gd); 180 table.setFont(parent.getFont()); 181 fFavoritesTable.setContentProvider(new FavoritesContentProvider()); 182 fFavoritesTable.setLabelProvider(new FavoritesLabelProvider()); 183 fFavoritesTable.addCheckStateListener(new ICheckStateListener() { 184 public void checkStateChanged(CheckStateChangedEvent event) { 185 updateLaunchConfigurationDialog(); 186 } 187 }); 188 } 189 190 195 private void createSharedConfigComponent(Composite parent) { 196 Group group = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.CommonTab_0, 3, 2, GridData.FILL_HORIZONTAL); 197 Composite comp = SWTFactory.createComposite(group, parent.getFont(), 3, 3, GridData.FILL_BOTH, 0, 0); 198 fLocalRadioButton = createRadioButton(comp, LaunchConfigurationsMessages.CommonTab_L_ocal_3); 199 GridData gd = new GridData(); 200 gd.horizontalSpan = 3; 201 fLocalRadioButton.setLayoutData(gd); 202 fSharedRadioButton = createRadioButton(comp, LaunchConfigurationsMessages.CommonTab_S_hared_4); 203 fSharedRadioButton.addSelectionListener(new SelectionAdapter() { 204 public void widgetSelected(SelectionEvent evt) { 205 handleSharedRadioButtonSelected(); 206 } 207 }); 208 fSharedLocationText = SWTFactory.createSingleText(comp, 1); 209 fSharedLocationText.addModifyListener(fBasicModifyListener); 210 fSharedLocationButton = createPushButton(comp, LaunchConfigurationsMessages.CommonTab__Browse_6, null); 211 fSharedLocationButton.addSelectionListener(new SelectionAdapter() { 212 public void widgetSelected(SelectionEvent evt) { 213 handleSharedLocationButtonSelected(); 214 } 215 }); 216 217 fLocalRadioButton.setSelection(true); 218 setSharedEnabled(false); 219 } 220 221 225 private void createOutputCaptureComponent(Composite parent) { 226 Group group = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.CommonTab_4, 5, 2, GridData.FILL_HORIZONTAL); 227 Composite comp = SWTFactory.createComposite(group, 5, 5, GridData.FILL_BOTH); 228 GridLayout ld = (GridLayout)comp.getLayout(); 229 ld.marginWidth = 1; 230 ld.marginHeight = 1; 231 fConsoleOutput = createCheckButton(comp, LaunchConfigurationsMessages.CommonTab_5); 232 GridData gd = new GridData(SWT.BEGINNING, SWT.NORMAL, true, false); 233 gd.horizontalSpan = 5; 234 fConsoleOutput.setLayoutData(gd); 235 fConsoleOutput.addSelectionListener(new SelectionAdapter() { 236 public void widgetSelected(SelectionEvent e) { 237 updateLaunchConfigurationDialog(); 238 } 239 }); 240 241 fFileOutput = createCheckButton(comp, LaunchConfigurationsMessages.CommonTab_6); 242 fFileOutput.setLayoutData(new GridData(SWT.BEGINNING, SWT.NORMAL, false, false)); 243 fFileOutput.addSelectionListener(new SelectionAdapter() { 244 public void widgetSelected(SelectionEvent e) { 245 enableOuputCaptureWidgets(fFileOutput.getSelection()); 246 updateLaunchConfigurationDialog(); 247 } 248 }); 249 fFileText = SWTFactory.createSingleText(comp, 4); 250 fFileText.addModifyListener(fBasicModifyListener); 251 252 Composite bcomp = SWTFactory.createComposite(comp, 3, 5, GridData.HORIZONTAL_ALIGN_END); 253 ld = (GridLayout)bcomp.getLayout(); 254 ld.marginHeight = 1; 255 ld.marginWidth = 0; 256 fWorkspaceBrowse = createPushButton(bcomp, LaunchConfigurationsMessages.CommonTab_12, null); 257 fWorkspaceBrowse.addSelectionListener(new SelectionAdapter() { 258 public void widgetSelected(SelectionEvent e) { 259 ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider()); 260 dialog.setTitle(LaunchConfigurationsMessages.CommonTab_13); 261 dialog.setMessage(LaunchConfigurationsMessages.CommonTab_14); 262 dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); 263 dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); 264 if (dialog.open() == IDialogConstants.OK_ID) { 265 IResource resource = (IResource) dialog.getFirstResult(); 266 String arg = resource.getFullPath().toString(); 267 String fileLoc = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", arg); fFileText.setText(fileLoc); 269 } 270 } 271 }); 272 fFileBrowse = createPushButton(bcomp, LaunchConfigurationsMessages.CommonTab_7, null); 273 fFileBrowse.addSelectionListener(new SelectionAdapter() { 274 public void widgetSelected(SelectionEvent e) { 275 String filePath = fFileText.getText(); 276 FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); 277 filePath = dialog.open(); 278 if (filePath != null) { 279 fFileText.setText(filePath); 280 } 281 } 282 }); 283 fVariables = createPushButton(bcomp, LaunchConfigurationsMessages.CommonTab_9, null); 284 fVariables.addSelectionListener(new SelectionListener() { 285 public void widgetSelected(SelectionEvent e) { 286 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); 287 dialog.open(); 288 String variable = dialog.getVariableExpression(); 289 if (variable != null) { 290 fFileText.insert(variable); 291 } 292 } 293 public void widgetDefaultSelected(SelectionEvent e) {} 294 }); 295 fAppend = createCheckButton(comp, LaunchConfigurationsMessages.CommonTab_11); 296 gd = new GridData(SWT.LEFT, SWT.TOP, true, false); 297 gd.horizontalSpan = 4; 298 fAppend.setLayoutData(gd); 299 fAppend.addSelectionListener(new SelectionAdapter() { 300 public void widgetSelected(SelectionEvent e) { 301 updateLaunchConfigurationDialog(); 302 } 303 }); 304 } 305 306 311 private void enableOuputCaptureWidgets(boolean enable) { 312 fFileText.setEnabled(enable); 313 fFileBrowse.setEnabled(enable); 314 fWorkspaceBrowse.setEnabled(enable); 315 fVariables.setEnabled(enable); 316 fAppend.setEnabled(enable); 317 } 318 319 323 private void createEncodingComponent(Composite parent) { 324 List allEncodings = IDEEncoding.getIDEEncodings(); 325 String defaultEncoding = WorkbenchEncoding.getWorkbenchDefaultEncoding(); 326 Group group = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.CommonTab_1, 2, 1, GridData.FILL_BOTH); 327 328 fDefaultEncodingButton = createRadioButton(group, MessageFormat.format(LaunchConfigurationsMessages.CommonTab_2, new String []{defaultEncoding})); 329 GridData gd = new GridData(SWT.BEGINNING, SWT.NORMAL, true, false); 330 gd.horizontalSpan = 2; 331 fDefaultEncodingButton.setLayoutData(gd); 332 333 fAltEncodingButton = createRadioButton(group, LaunchConfigurationsMessages.CommonTab_3); 334 fAltEncodingButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); 335 336 fEncodingCombo = new Combo(group, SWT.READ_ONLY); 337 fEncodingCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 338 fEncodingCombo.setFont(parent.getFont()); 339 String [] encodingArray = (String []) allEncodings.toArray(new String [0]); 340 fEncodingCombo.setItems(encodingArray); 341 if (encodingArray.length > 0) { 342 fEncodingCombo.select(0); 343 } 344 SelectionListener listener = new SelectionAdapter() { 345 public void widgetSelected(SelectionEvent e) { 346 updateLaunchConfigurationDialog(); 347 fEncodingCombo.setEnabled(fAltEncodingButton.getSelection() == true); 348 } 349 }; 350 fAltEncodingButton.addSelectionListener(listener); 351 fDefaultEncodingButton.addSelectionListener(listener); 352 fEncodingCombo.addSelectionListener(listener); 353 } 354 355 361 protected void createLaunchInBackgroundComponent(Composite parent) { 362 fLaunchInBackgroundButton = createCheckButton(parent, LaunchConfigurationsMessages.CommonTab_10); 363 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 364 data.horizontalSpan = 2; 365 fLaunchInBackgroundButton.setLayoutData(data); 366 fLaunchInBackgroundButton.setFont(parent.getFont()); 367 fLaunchInBackgroundButton.addSelectionListener(new SelectionAdapter() { 368 public void widgetSelected(SelectionEvent e) { 369 updateLaunchConfigurationDialog(); 370 } 371 }); 372 } 373 374 377 private void handleSharedRadioButtonSelected() { 378 setSharedEnabled(isShared()); 379 updateLaunchConfigurationDialog(); 380 } 381 382 386 private void setSharedEnabled(boolean enable) { 387 fSharedLocationText.setEnabled(enable); 388 fSharedLocationButton.setEnabled(enable); 389 } 390 391 private String getDefaultSharedConfigLocation(ILaunchConfiguration config) { 392 String path = EMPTY_STRING; 393 try { 394 IResource[] res = config.getMappedResources(); 395 if(res != null) { 396 IProject proj; 397 for (int i = 0; i < res.length; i++) { 398 proj = res[i].getProject(); 399 if(proj.isAccessible()) { 400 return proj.getFullPath().toOSString(); 401 } 402 } 403 } 404 } 405 catch (CoreException e) {DebugUIPlugin.log(e);} 406 return path; 407 } 408 409 413 private boolean isShared() { 414 return fSharedRadioButton.getSelection(); 415 } 416 417 420 private void handleSharedLocationButtonSelected() { 421 String currentContainerString = fSharedLocationText.getText(); 422 IContainer currentContainer = getContainer(currentContainerString); 423 SharedLocationSelectionDialog dialog = new SharedLocationSelectionDialog(getShell(), 424 currentContainer, 425 false, 426 LaunchConfigurationsMessages.CommonTab_Select_a_location_for_the_launch_configuration_13); 427 dialog.showClosedProjects(false); 428 dialog.open(); 429 Object [] results = dialog.getResult(); 430 if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) { 431 IPath path = (IPath)results[0]; 432 String containerName = path.toOSString(); 433 fSharedLocationText.setText(containerName); 434 } 435 } 436 437 442 private IContainer getContainer(String path) { 443 Path containerPath = new Path(path); 444 return (IContainer) getWorkspaceRoot().findMember(containerPath); 445 } 446 447 450 public void initializeFrom(ILaunchConfiguration configuration) { 451 boolean isShared = !configuration.isLocal(); 452 fSharedRadioButton.setSelection(isShared); 453 fLocalRadioButton.setSelection(!isShared); 454 setSharedEnabled(isShared); 455 fSharedLocationText.setText(getDefaultSharedConfigLocation(configuration)); 456 if(isShared) { 457 String containerName = EMPTY_STRING; 458 IFile file = configuration.getFile(); 459 if (file != null) { 460 IContainer parent = file.getParent(); 461 if (parent != null) { 462 containerName = parent.getFullPath().toOSString(); 463 } 464 } 465 fSharedLocationText.setText(containerName); 466 } 467 updateFavoritesFromConfig(configuration); 468 updateLaunchInBackground(configuration); 469 updateEncoding(configuration); 470 updateConsoleOutput(configuration); 471 } 472 473 477 private void updateConsoleOutput(ILaunchConfiguration configuration) { 478 boolean outputToConsole = true; 479 String outputFile = null; 480 boolean append = false; 481 482 try { 483 outputToConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true); 484 outputFile = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String )null); 485 append = configuration.getAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, false); 486 } catch (CoreException e) { 487 } 488 489 fConsoleOutput.setSelection(outputToConsole); 490 fAppend.setSelection(append); 491 boolean haveOutputFile= outputFile != null; 492 if (haveOutputFile) { 493 fFileText.setText(outputFile); 494 } 495 fFileOutput.setSelection(haveOutputFile); 496 enableOuputCaptureWidgets(haveOutputFile); 497 } 498 499 503 protected void updateLaunchInBackground(ILaunchConfiguration configuration) { 504 fLaunchInBackgroundButton.setSelection(isLaunchInBackground(configuration)); 505 } 506 507 511 private void updateEncoding(ILaunchConfiguration configuration) { 512 String encoding = null; 513 try { 514 encoding = configuration.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String )null); 515 } catch (CoreException e) { 516 } 517 518 if (encoding != null) { 519 fAltEncodingButton.setSelection(true); 520 fDefaultEncodingButton.setSelection(false); 521 fEncodingCombo.setText(encoding); 522 fEncodingCombo.setEnabled(true); 523 } else { 524 fDefaultEncodingButton.setSelection(true); 525 fAltEncodingButton.setSelection(false); 526 fEncodingCombo.setEnabled(false); 527 } 528 } 529 530 536 public static boolean isLaunchInBackground(ILaunchConfiguration configuration) { 537 boolean launchInBackground= true; 538 try { 539 launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); 540 } catch (CoreException ce) { 541 DebugUIPlugin.log(ce); 542 } 543 return launchInBackground; 544 } 545 546 550 private void updateFavoritesFromConfig(ILaunchConfiguration config) { 551 fFavoritesTable.setInput(config); 552 fFavoritesTable.setCheckedElements(new Object []{}); 553 try { 554 List groups = config.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, new ArrayList ()); 555 if (groups.isEmpty()) { 556 if (config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false)) { 558 groups.add(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP); 559 } 560 if (config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false)) { 561 groups.add(IDebugUIConstants.ID_RUN_LAUNCH_GROUP); 562 } 563 } 564 if (!groups.isEmpty()) { 565 List list = new ArrayList (); 566 Iterator iterator = groups.iterator(); 567 while (iterator.hasNext()) { 568 String id = (String )iterator.next(); 569 LaunchGroupExtension extension = getLaunchConfigurationManager().getLaunchGroup(id); 570 list.add(extension); 571 } 572 fFavoritesTable.setCheckedElements(list.toArray()); 573 } 574 } catch (CoreException e) { 575 DebugUIPlugin.log(e); 576 } 577 } 578 579 583 private void updateConfigFromLocalShared(ILaunchConfigurationWorkingCopy config) { 584 if (isShared()) { 585 String containerPathString = fSharedLocationText.getText(); 586 IContainer container = getContainer(containerPathString); 587 if(container == null) { 588 config.setAttribute(BAD_CONTAINER, containerPathString); 590 } 591 else { 592 config.setContainer(container); 593 } 594 } else { 595 config.setContainer(null); 596 } 597 } 598 599 602 protected LaunchConfigurationManager getLaunchConfigurationManager() { 603 return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); 604 } 605 606 613 private void updateConfigFromFavorites(ILaunchConfigurationWorkingCopy config) { 614 try { 615 Object [] checked = fFavoritesTable.getCheckedElements(); 616 boolean debug = config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false); 617 boolean run = config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false); 618 if (debug || run) { 619 List groups = new ArrayList (); 621 int num = 0; 622 if (debug) { 623 groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP)); 624 num++; 625 } 626 if (run) { 627 num++; 628 groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP)); 629 } 630 if (num == checked.length) { 632 boolean different = false; 633 for (int i = 0; i < checked.length; i++) { 634 if (!groups.contains(checked[i])) { 635 different = true; 636 break; 637 } 638 } 639 if (!different) { 640 return; 641 } 642 } 643 } 644 config.setAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, (String )null); 645 config.setAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, (String )null); 646 List groups = null; 647 for (int i = 0; i < checked.length; i++) { 648 LaunchGroupExtension group = (LaunchGroupExtension)checked[i]; 649 if (groups == null) { 650 groups = new ArrayList (); 651 } 652 groups.add(group.getIdentifier()); 653 } 654 config.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, groups); 655 } catch (CoreException e) { 656 DebugUIPlugin.log(e); 657 } 658 } 659 660 663 private IWorkspaceRoot getWorkspaceRoot() { 664 return ResourcesPlugin.getWorkspace().getRoot(); 665 } 666 667 670 public boolean isValid(ILaunchConfiguration config) { 671 setMessage(null); 672 setErrorMessage(null); 673 674 return validateLocalShared() && validateRedirectFile() && validateEncoding(); 675 } 676 677 681 private boolean validateEncoding() { 682 if (fAltEncodingButton.getSelection()) { 683 if (fEncodingCombo.getSelectionIndex() == -1) { 684 setErrorMessage(LaunchConfigurationsMessages.CommonTab_No_Encoding_Selected); 685 return false; 686 } 687 } 688 return true; 689 } 690 691 695 private boolean validateRedirectFile() { 696 if(fFileOutput.getSelection()) { 697 int len = fFileText.getText().trim().length(); 698 if (len == 0) { 699 setErrorMessage(LaunchConfigurationsMessages.CommonTab_8); 700 return false; 701 } 702 } 703 return true; 704 } 705 706 710 private boolean validateLocalShared() { 711 if (isShared()) { 712 String path = fSharedLocationText.getText().trim(); 713 IContainer container = getContainer(path); 714 if (container == null || container.equals(ResourcesPlugin.getWorkspace().getRoot())) { 715 setErrorMessage(LaunchConfigurationsMessages.CommonTab_Invalid_shared_configuration_location_14); 716 return false; 717 } else if (!container.getProject().isOpen()) { 718 setErrorMessage(LaunchConfigurationsMessages.CommonTab_Cannot_save_launch_configuration_in_a_closed_project__1); 719 return false; 720 } 721 } 722 return true; 723 } 724 725 728 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 729 config.setContainer(null); 730 setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, config, true, true); 731 } 732 733 736 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 737 updateConfigFromLocalShared(configuration); 738 updateConfigFromFavorites(configuration); 739 setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, configuration, fLaunchInBackgroundButton.getSelection(), true); 740 String encoding = null; 741 if(fAltEncodingButton.getSelection()) { 742 encoding = fEncodingCombo.getText(); 743 } 744 configuration.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, encoding); 745 boolean captureOutput = false; 746 if (fConsoleOutput.getSelection()) { 747 captureOutput = true; 748 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, (String )null); 749 } else { 750 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, false); 751 } 752 if (fFileOutput.getSelection()) { 753 captureOutput = true; 754 String file = fFileText.getText(); 755 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, file); 756 if(fAppend.getSelection()) { 757 configuration.setAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, true); 758 } else { 759 configuration.setAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, (String )null); 760 } 761 } else { 762 configuration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String )null); 763 } 764 765 if (!captureOutput) { 766 configuration.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, false); 767 } else { 768 configuration.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, (String )null); 769 } 770 } 771 772 775 public String getName() { 776 return LaunchConfigurationsMessages.CommonTab__Common_15; 777 } 778 779 784 public String getId() { 785 return "org.eclipse.debug.ui.commonTab"; } 787 788 791 public boolean canSave() { 792 return validateLocalShared(); 793 } 794 795 798 public Image getImage() { 799 return DebugUITools.getImage(IInternalDebugUIConstants.IMG_OBJS_COMMON_TAB); 800 } 801 802 805 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {} 806 807 810 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {} 811 812 815 class FavoritesContentProvider implements IStructuredContentProvider { 816 817 public Object [] getElements(Object inputElement) { 818 ILaunchGroup[] groups = DebugUITools.getLaunchGroups(); 819 List possibleGroups = new ArrayList (); 820 ILaunchConfiguration configuration = (ILaunchConfiguration)inputElement; 821 for (int i = 0; i < groups.length; i++) { 822 ILaunchGroup extension = groups[i]; 823 LaunchHistory history = getLaunchConfigurationManager().getLaunchHistory(extension.getIdentifier()); 824 if (history != null && history.accepts(configuration)) { 825 possibleGroups.add(extension); 826 } 827 } 828 return possibleGroups.toArray(); 829 } 830 831 public void dispose() {} 832 833 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 834 835 } 836 837 841 class FavoritesLabelProvider implements ITableLabelProvider { 842 843 private Map fImages = new HashMap (); 844 845 public Image getColumnImage(Object element, int columnIndex) { 846 Image image = (Image)fImages.get(element); 847 if (image == null) { 848 ImageDescriptor descriptor = ((LaunchGroupExtension)element).getImageDescriptor(); 849 if (descriptor != null) { 850 image = descriptor.createImage(); 851 fImages.put(element, image); 852 } 853 } 854 return image; 855 } 856 857 public String getColumnText(Object element, int columnIndex) { 858 String label = ((LaunchGroupExtension)element).getLabel(); 859 return DebugUIPlugin.removeAccelerators(label); 860 } 861 862 public void addListener(ILabelProviderListener listener) {} 863 864 public void dispose() { 865 Iterator images = fImages.values().iterator(); 866 while (images.hasNext()) { 867 Image image = (Image)images.next(); 868 image.dispose(); 869 } 870 } 871 872 public boolean isLabelProperty(Object element, String property) {return false;} 873 874 public void removeListener(ILabelProviderListener listener) {} 875 } 876 877 } 878 | Popular Tags |