1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.ResourcesPlugin; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.core.runtime.IStatus; 24 import org.eclipse.core.runtime.Status; 25 import org.eclipse.debug.core.DebugPlugin; 26 import org.eclipse.debug.core.ILaunchConfiguration; 27 import org.eclipse.debug.core.ILaunchConfigurationType; 28 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 29 import org.eclipse.debug.core.ILaunchDelegate; 30 import org.eclipse.debug.internal.core.LaunchConfigurationWorkingCopy; 31 import org.eclipse.debug.internal.ui.DebugUIPlugin; 32 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 33 import org.eclipse.debug.internal.ui.SWTFactory; 34 import org.eclipse.debug.ui.DebugUITools; 35 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 36 import org.eclipse.debug.ui.ILaunchConfigurationTab; 37 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; 38 import org.eclipse.jface.dialogs.Dialog; 39 import org.eclipse.jface.dialogs.ErrorDialog; 40 import org.eclipse.jface.dialogs.IDialogConstants; 41 import org.eclipse.jface.operation.IRunnableWithProgress; 42 import org.eclipse.jface.resource.ColorRegistry; 43 import org.eclipse.jface.resource.JFaceResources; 44 import org.eclipse.jface.viewers.ISelection; 45 import org.eclipse.jface.viewers.IStructuredSelection; 46 import org.eclipse.jface.viewers.StructuredSelection; 47 import org.eclipse.jface.viewers.Viewer; 48 import org.eclipse.swt.SWT; 49 import org.eclipse.swt.custom.BusyIndicator; 50 import org.eclipse.swt.custom.CTabFolder; 51 import org.eclipse.swt.custom.CTabItem; 52 import org.eclipse.swt.custom.StackLayout; 53 import org.eclipse.swt.custom.ViewForm; 54 import org.eclipse.swt.events.ModifyEvent; 55 import org.eclipse.swt.events.ModifyListener; 56 import org.eclipse.swt.events.SelectionAdapter; 57 import org.eclipse.swt.events.SelectionEvent; 58 import org.eclipse.swt.events.SelectionListener; 59 import org.eclipse.swt.graphics.Color; 60 import org.eclipse.swt.graphics.Font; 61 import org.eclipse.swt.graphics.Image; 62 import org.eclipse.swt.layout.GridData; 63 import org.eclipse.swt.layout.GridLayout; 64 import org.eclipse.swt.widgets.Button; 65 import org.eclipse.swt.widgets.Composite; 66 import org.eclipse.swt.widgets.Control; 67 import org.eclipse.swt.widgets.Label; 68 import org.eclipse.swt.widgets.Link; 69 import org.eclipse.swt.widgets.Shell; 70 import org.eclipse.swt.widgets.Text; 71 import org.eclipse.ui.IWorkbenchPreferenceConstants; 72 import org.eclipse.ui.PlatformUI; 73 74 import com.ibm.icu.text.MessageFormat; 75 76 80 public class LaunchConfigurationTabGroupViewer extends Viewer { 81 82 private final String EMPTY_STRING = ""; 86 private ILaunchConfigurationDialog fDialog; 87 88 91 private Object fInput; 92 93 96 private ILaunchConfiguration fOriginal; 97 98 101 private ILaunchConfigurationWorkingCopy fWorkingCopy; 102 103 106 private Composite fViewerControl; 107 108 111 private Composite fVisibleArea; 112 113 116 private Label fNameLabel; 117 118 121 private Text fNameWidget; 122 123 126 private Composite fTabComposite; 127 128 131 private CTabFolder fTabFolder; 132 133 136 private ILaunchConfigurationTabGroup fTabGroup; 137 138 142 private ILaunchConfigurationType fTabType; 143 144 147 private int fCurrentTabIndex = -1; 148 149 152 private Button fApplyButton; 153 private Button fRevertButton; 154 155 158 private boolean fDisposingTabs = false; 159 private boolean fInitializingTabs = false; 160 161 165 private String fDescription = null; 166 167 171 private Composite fTabPlaceHolder = null; 172 173 177 private Link fOptionsLink = null; 178 179 183 private Composite fGettingStarted = null; 184 185 private ViewForm fViewform; 186 187 194 public LaunchConfigurationTabGroupViewer(Composite parent, ILaunchConfigurationDialog dialog) { 195 super(); 196 fDialog = dialog; 197 createControl(parent); 198 } 199 200 203 public void dispose() { 204 disposeTabGroup(); 205 } 206 207 210 protected void disposeTabGroup() { 211 if (fTabGroup != null) { 212 fTabGroup.dispose(); 213 fTabGroup = null; 214 fTabType = null; 215 } 216 } 217 218 225 private void createControl(Composite parent) { 226 fViewerControl = new Composite(parent, SWT.NONE); 227 GridLayout layout = new GridLayout(); 228 layout.numColumns = 1; 229 layout.marginHeight = 0; 230 layout.marginWidth = 0; 231 layout.horizontalSpacing = 0; 232 layout.verticalSpacing = 0; 233 fViewerControl.setLayout(layout); 234 GridData gd = new GridData(GridData.FILL_BOTH); 235 fViewerControl.setLayoutData(gd); 236 237 fViewform = new ViewForm(fViewerControl, SWT.FLAT | SWT.BORDER); 238 layout = new GridLayout(1, false); 239 layout.horizontalSpacing = 0; 240 layout.verticalSpacing = 0; 241 fViewform.setLayout(layout); 242 gd = new GridData(GridData.FILL_BOTH); 243 fViewform.setLayoutData(gd); 244 fVisibleArea = fViewform; 245 fViewform.setTopLeft(null); 246 247 Composite mainComp = new Composite(fViewform, SWT.FLAT); 248 layout = new GridLayout(1, false); 249 layout.verticalSpacing = 0; 250 layout.horizontalSpacing = 0; 251 mainComp.setLayout(layout); 252 fViewform.setContent(mainComp); 253 254 fTabPlaceHolder = new Composite(mainComp, SWT.NONE); 255 fTabPlaceHolder.setLayout(new StackLayout()); 256 gd = new GridData(GridData.FILL_BOTH); 257 fTabPlaceHolder.setLayoutData(gd); 258 259 fGettingStarted = new Composite(fTabPlaceHolder, SWT.NONE); 260 fGettingStarted.setLayout(new GridLayout()); 261 gd = new GridData(GridData.FILL_BOTH); 262 fGettingStarted.setLayoutData(gd); 263 264 createGettingStarted(fGettingStarted); 265 266 fTabComposite = new Composite(fTabPlaceHolder, SWT.NONE); 267 layout = new GridLayout(2, false); 268 layout.verticalSpacing = 10; 269 layout.horizontalSpacing = 5; 270 fTabComposite.setLayout(layout); 271 gd = new GridData(GridData.FILL_BOTH); 272 fTabComposite.setLayoutData(gd); 273 274 fNameLabel = new Label(fTabComposite, SWT.HORIZONTAL | SWT.LEFT); 275 fNameLabel.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog__Name__16); 276 fNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); 277 278 fNameWidget = new Text(fTabComposite, SWT.SINGLE | SWT.BORDER); 279 fNameWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 280 fNameWidget.addModifyListener(new ModifyListener() { 281 public void modifyText(ModifyEvent e) { 282 if(!fInitializingTabs) { 283 handleNameModified(); 284 } 285 } 286 } 287 ); 288 289 createTabFolder(fTabComposite); 290 291 Composite blComp = SWTFactory.createComposite(mainComp, mainComp.getFont(), 2, 1, GridData.FILL_HORIZONTAL); 292 Composite linkComp = SWTFactory.createComposite(blComp, blComp.getFont(), 1, 1, GridData.FILL_HORIZONTAL); 293 294 fOptionsLink = new Link(linkComp, SWT.WRAP); 296 fOptionsLink.setFont(linkComp.getFont()); 297 gd = new GridData(SWT.LEFT); 298 gd.grabExcessHorizontalSpace = true; 299 fOptionsLink.setLayoutData(gd); 300 fOptionsLink.addSelectionListener(new SelectionListener() { 301 public void widgetSelected(SelectionEvent e) { 302 try { 304 if(!canLaunchWithModes()) { 305 SelectLaunchModesDialog sld = new SelectLaunchModesDialog(getShell(), 306 getLaunchConfigurationDialog().getMode(), getWorkingCopy()); 307 if(sld.open() == IDialogConstants.OK_ID) { 308 Object [] res = sld.getResult(); 310 if(res != null) { 311 Set modes = (Set ) res[0]; 312 modes.remove(getLaunchConfigurationDialog().getMode()); 313 ILaunchConfigurationWorkingCopy wc = getWorkingCopy(); 314 wc.setModes(modes); 315 refreshStatus(); 316 } 317 } 318 } 319 else if(hasMultipleDelegates()) { 320 SelectLaunchersDialog sldd = new SelectLaunchersDialog(getShell(), 321 getWorkingCopy().getType().getDelegates(getCurrentModeSet()), 322 getWorkingCopy(), 323 getLaunchConfigurationDialog().getMode()); 324 if(sldd.open() == IDialogConstants.OK_ID) { 325 displayInstanceTabs(true); 326 } 327 } 328 } catch (CoreException ex) {} 329 } 330 public void widgetDefaultSelected(SelectionEvent e) {} 331 }); 332 fOptionsLink.setVisible(false); 333 334 Composite buttonComp = new Composite(blComp, SWT.NONE); 335 GridLayout buttonCompLayout = new GridLayout(); 336 buttonCompLayout.numColumns = 2; 337 buttonComp.setLayout(buttonCompLayout); 338 gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 339 buttonComp.setLayoutData(gd); 340 341 fApplyButton = new Button(buttonComp, SWT.PUSH); 342 fApplyButton.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog__Apply_17); 343 gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 344 fApplyButton.setLayoutData(gd); 345 SWTFactory.setButtonDimensionHint(fApplyButton); 346 fApplyButton.addSelectionListener(new SelectionAdapter() { 347 public void widgetSelected(SelectionEvent evt) { 348 handleApplyPressed(); 349 } 350 }); 351 352 fRevertButton = new Button(buttonComp, SWT.PUSH); 353 fRevertButton.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog_Revert_2); 354 gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 355 fRevertButton.setLayoutData(gd); 356 SWTFactory.setButtonDimensionHint(fRevertButton); 357 fRevertButton.addSelectionListener(new SelectionAdapter() { 358 public void widgetSelected(SelectionEvent evt) { 359 handleRevertPressed(); 360 } 361 }); 362 Dialog.applyDialogFont(parent); 363 } 364 365 370 private void createGettingStarted(Composite parent) { 371 Font font = parent.getFont(); 372 GridData gd = null; 373 int width = parent.getBounds().width - 30; 374 SWTFactory.createWrapLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_1, 1, width); 375 SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_2, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_NEW_CONFIG), 1, width); 376 SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_6, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG), 1, width); 377 SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_4, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG), 1, width); 378 SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_8, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_FILTER_CONFIGS), 1, width); 379 SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_3, DebugUITools.getImage(IInternalDebugUIConstants.IMG_OVR_TRANSPARENT), 1, width); 380 381 SWTFactory.createHorizontalSpacer(parent, 2); 382 Link link = new Link(parent, SWT.LEFT | SWT.WRAP); 383 link.setText(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_5); 384 link.setFont(font); 385 gd = new GridData(GridData.FILL_HORIZONTAL); 386 gd.widthHint = width; 387 link.setLayoutData(gd); 388 link.addSelectionListener(new SelectionListener() { 389 public void widgetSelected(SelectionEvent e) { 390 SWTFactory.showPreferencePage("org.eclipse.debug.ui.PerspectivePreferencePage"); } 392 public void widgetDefaultSelected(SelectionEvent e) {} 393 }); 394 } 395 396 400 private void createTabFolder(Composite parent) { 401 if (fTabFolder == null) { 402 ColorRegistry reg = JFaceResources.getColorRegistry(); 403 Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); fTabFolder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT); 406 GridData gd = new GridData(GridData.FILL_BOTH); 407 gd.horizontalSpan = 2; 408 fTabFolder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true); 409 fTabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); fTabFolder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); 411 fTabFolder.setLayoutData(gd); 412 fTabFolder.setBorderVisible(true); 413 fTabFolder.setFont(parent.getFont()); 414 fTabFolder.addSelectionListener(new SelectionAdapter() { 415 public void widgetSelected(SelectionEvent event) { 416 if (!fInitializingTabs) { 417 handleTabSelected(); 418 refresh(); 419 } 420 } 421 }); 422 } 423 } 424 425 428 protected Button getApplyButton() { 429 return fApplyButton; 430 } 431 432 435 protected Button getRevertButton() { 436 return fRevertButton; 437 } 438 439 442 protected CTabFolder getTabFolder() { 443 return fTabFolder; 444 } 445 446 449 public void setName(String name) { 450 if (getWorkingCopy() != null) { 451 if (name == null) { 452 fNameWidget.setText(EMPTY_STRING); 453 } 454 else { 455 fNameWidget.setText(name.trim()); 456 } 457 refreshStatus(); 458 } 459 } 460 461 464 public Control getControl() { 465 return fViewerControl; 466 } 467 468 471 protected Shell getShell() { 472 return getControl().getShell(); 473 } 474 475 478 public Object getInput() { 479 return fInput; 480 } 481 482 485 public ISelection getSelection() { 486 return new StructuredSelection(fWorkingCopy); 487 } 488 489 492 public void refresh() { 493 if (fInitializingTabs) { 494 return; 495 } 496 ILaunchConfigurationTab[] tabs = getTabs(); 497 if (tabs != null) { 498 boolean newwc = !getWorkingCopy().isDirty(); 500 getActiveTab().performApply(getWorkingCopy()); 501 if(getOriginal() instanceof ILaunchConfigurationWorkingCopy && newwc) { 502 try { 503 getWorkingCopy().doSave(); 504 } 505 catch (CoreException e) {DebugUIPlugin.log(e);} 506 } 507 updateButtons(); 508 CTabItem item = null; 510 boolean error = false; 511 Image image = null; 512 for (int i = 0; i < tabs.length; i++) { 513 item = fTabFolder.getItem(i); 514 image = tabs[i].getImage(); 515 item.setImage(image); 516 if(!tabs[i].isValid(getWorkingCopy())) { 517 error = tabs[i].getErrorMessage() != null; 518 if(error) { 519 item.setImage(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getErrorTabImage(tabs[i])); 520 } 521 } 522 } 523 showLink(); 524 } 525 } 526 527 532 private void showLink() { 533 String text = null; 534 if(!canLaunchWithModes()) { 535 text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_13; 536 } 537 else if(hasMultipleDelegates()) { 538 ILaunchDelegate delegate = getPreferredDelegate(); 539 if(delegate != null) { 540 String name = delegate.getName(); 541 if(name == null) { 542 text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_15; 543 } 544 else { 545 text = MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_16, new String [] {name}); 546 } 547 } 548 else { 549 text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_17; 550 } 551 } 552 if(text != null) { 553 fOptionsLink.setText(text); 554 } 555 fOptionsLink.setVisible(!canLaunchWithModes() || hasMultipleDelegates()); 556 fOptionsLink.getParent().getParent().layout(true); 557 } 558 559 565 protected ILaunchDelegate getPreferredDelegate() { 566 ILaunchDelegate preferred = null; 567 ILaunchConfigurationWorkingCopy config = getWorkingCopy(); 568 if(config != null) { 569 try { 570 Set modes = getCurrentModeSet(); 571 preferred = config.getPreferredDelegate(modes); 572 if(preferred == null) { 573 preferred = config.getType().getPreferredDelegate(modes); 574 } 575 } 576 catch(CoreException ce) {DebugUIPlugin.log(ce);} 577 } 578 return preferred; 579 } 580 581 586 private Set getCurrentModeSet() { 587 Set set = new HashSet (); 588 ILaunchConfigurationWorkingCopy config = getWorkingCopy(); 589 if(config != null) { 590 try { 591 set.addAll(config.getModes()); 592 set.add(getLaunchConfigurationDialog().getMode()); 593 } 594 catch(CoreException ce) {DebugUIPlugin.log(ce);} 595 } 596 return set; 597 } 598 599 602 private void updateButtons() { 603 boolean dirty = isDirty(); 604 fApplyButton.setEnabled(dirty && canSave()); 605 fRevertButton.setEnabled(dirty); 606 } 607 608 611 public void setInput(final Object input) { 612 if(DebugUIPlugin.getStandardDisplay().getThread().equals(Thread.currentThread())) { 613 setInput0(input); 614 } 615 else { 616 DebugUIPlugin.getStandardDisplay().syncExec(new Runnable () { 617 public void run() { 618 setInput0(input); 619 } 620 }); 621 } 622 623 } 624 629 private void setInput0(Object input) { 630 if (input == null) { 631 if (fInput == null) { 632 return; 633 } 634 inputChanged(input); 635 } else { 636 if (!input.equals(fInput)) { 637 inputChanged(input); 638 } 639 } 640 } 641 642 647 protected void inputChanged(Object input) { 648 fInput = input; 649 Runnable r = new Runnable () { 650 public void run() { 651 try { 652 fVisibleArea.setRedraw(false); 653 if (fInput instanceof ILaunchConfiguration) { 654 ILaunchConfiguration configuration = (ILaunchConfiguration)fInput; 655 boolean refreshtabs = !delegatesEqual(fWorkingCopy, configuration); 656 fOriginal = configuration; 657 fWorkingCopy = configuration.getWorkingCopy(); 658 displayInstanceTabs(refreshtabs); 659 } else if (fInput instanceof ILaunchConfigurationType) { 660 fDescription = getDescription((ILaunchConfigurationType)fInput); 661 setNoInput(); 662 refreshStatus(); 663 } else { 664 setNoInput(); 665 refreshStatus(); 666 } 667 } catch (CoreException ce) { 668 errorDialog(ce); 669 setNoInput(); 670 } 671 finally { 672 fVisibleArea.setRedraw(true); 673 } 674 } 675 }; 676 BusyIndicator.showWhile(getShell().getDisplay(), r); 677 } 678 679 684 private void setNoInput() { 685 fOriginal = null; 686 fWorkingCopy = null; 687 disposeExistingTabs(); 688 updateButtons(); 689 updateVisibleControls(false); 690 ILaunchConfigurationDialog lcd = getLaunchConfigurationDialog(); 691 if(lcd instanceof LaunchConfigurationsDialog) { 692 if(((LaunchConfigurationsDialog)lcd).isTreeSelectionEmpty()) { 693 fDescription = EMPTY_STRING; 694 } 695 } 696 } 697 698 705 protected boolean delegatesEqual(ILaunchConfiguration config1, ILaunchConfiguration config2) { 706 try { 707 if(config1 == null || config2 == null) { 708 return false; 709 } 710 Set modes = getCurrentModeSet(); 711 ILaunchDelegate d1 = config1.getPreferredDelegate(modes); 712 if(d1 == null) { 713 d1 = config1.getType().getPreferredDelegate(modes); 714 } 715 ILaunchDelegate d2 = config2.getPreferredDelegate(modes); 716 if(d2 == null) { 717 d2 = config2.getType().getPreferredDelegate(modes); 718 } 719 if(d1 != null) { 720 return d1.equals(d2); 721 } 722 } 723 catch(CoreException ce) {DebugUIPlugin.log(ce);} 724 return false; 725 } 726 727 731 private void updateVisibleControls(boolean visible) { 732 fApplyButton.setVisible(visible); 733 fRevertButton.setVisible(visible); 734 fOptionsLink.setVisible(visible); 735 if(visible) { 736 ((StackLayout)fTabPlaceHolder.getLayout()).topControl = fTabComposite; 737 fTabComposite.layout(); 738 } 739 else { 740 ((StackLayout)fTabPlaceHolder.getLayout()).topControl = fGettingStarted; 741 } 742 fTabPlaceHolder.layout(true); 743 } 744 745 748 protected void setFocusOnName() { 749 fNameWidget.setFocus(); 750 } 751 752 755 protected void displayInstanceTabs(boolean redrawTabs) { 756 fInitializingTabs = true; 758 ILaunchConfigurationType type = null; 759 try { 760 type = getWorkingCopy().getType(); 761 } 762 catch (CoreException e) { 763 errorDialog(e); 764 fInitializingTabs = false; 765 return; 766 } 767 if(redrawTabs) { 768 showInstanceTabsFor(type); 769 } 770 updateVisibleControls(true); 772 773 ILaunchConfigurationTabGroup tabGroup = getTabGroup(); 775 if (tabGroup == null) { 776 IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_No_tabs_defined_for_launch_configuration_type__0__1, new String []{type.getName()}), null); 777 CoreException e = new CoreException(status); 778 errorDialog(e); 779 fInitializingTabs = false; 780 return; 781 } 782 783 tabGroup.initializeFrom(getWorkingCopy()); 785 786 fNameWidget.setText(getWorkingCopy().getName()); 788 789 fCurrentTabIndex = fTabFolder.getSelectionIndex(); 790 791 fInitializingTabs = false; 793 794 if (!fVisibleArea.isVisible()) { 795 fVisibleArea.setVisible(true); 796 } 797 refreshStatus(); 798 } 799 800 804 private void showInstanceTabsFor(ILaunchConfigurationType configType) { 805 Class tabKind = null; 807 if (getActiveTab() != null) { 808 tabKind = getActiveTab().getClass(); 809 } 810 ILaunchConfigurationTabGroup group = null; 812 try { 813 group = createGroup(); 814 } catch (CoreException ce) { 815 DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_Exception_occurred_creating_launch_configuration_tabs_27,ce); return; 817 } 818 disposeExistingTabs(); 819 fTabGroup = group; 820 fTabType = configType; 821 ILaunchConfigurationTab[] tabs = getTabs(); 822 CTabItem tab = null; 823 String name = EMPTY_STRING; 824 Control control = null; 825 for (int i = 0; i < tabs.length; i++) { 826 tab = new CTabItem(fTabFolder, SWT.BORDER); 827 name = tabs[i].getName(); 828 if (name == null) { 829 name = LaunchConfigurationsMessages.LaunchConfigurationDialog_unspecified_28; 830 } 831 tab.setText(name); 832 tab.setImage(tabs[i].getImage()); 833 tabs[i].createControl(tab.getParent()); 834 control = tabs[i].getControl(); 835 if (control != null) { 836 tab.setControl(control); 837 } 838 } 839 setActiveTab(tabs[0]); 841 for (int i = 0; i < tabs.length; i++) { 843 if (tabs[i].getClass().equals(tabKind)) { 844 setActiveTab(tabs[i]); 845 break; 846 } 847 } 848 fDescription = getDescription(configType); 849 } 850 851 858 private String getDescription(ILaunchConfigurationType configType) { 859 String description = null; 860 if(configType != null) { 861 String mode = fDialog.getMode(); 862 description = LaunchConfigurationPresentationManager.getDefault().getDescription(configType, mode); 863 } 864 if (description == null) { 865 description = EMPTY_STRING; 866 } 867 return description; 868 } 869 870 876 protected ILaunchConfigurationTabGroup createGroup() throws CoreException { 877 final Object [] finalArray = new Object [2]; 880 Runnable runnable = new Runnable () { 881 public void run() { 882 ILaunchConfigurationTabGroup tabGroup = null; 883 try { 884 tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(getWorkingCopy(), getLaunchConfigurationDialog().getMode()); 885 finalArray[0] = tabGroup; 886 } catch (CoreException ce) { 887 finalArray[1] = ce; 888 return; 889 } 890 tabGroup.createTabs(getLaunchConfigurationDialog(), getLaunchConfigurationDialog().getMode()); 891 ILaunchConfigurationTab[] tabs = tabGroup.getTabs(); 892 for (int i = 0; i < tabs.length; i++) { 893 tabs[i].setLaunchConfigurationDialog(getLaunchConfigurationDialog()); 894 } 895 } 896 }; 897 898 BusyIndicator.showWhile(getControl().getDisplay(), runnable); 900 901 if (finalArray[1] != null) { 903 throw (CoreException)finalArray[1]; 904 } 905 906 return (ILaunchConfigurationTabGroup)finalArray[0]; 908 } 909 910 913 public void setSelection(ISelection selection, boolean reveal) { 914 if (getWorkingCopy() != null) { 915 if (selection instanceof IStructuredSelection) { 916 IStructuredSelection structuredSelection = (IStructuredSelection)selection; 917 Object object = structuredSelection.getFirstElement(); 918 if (object instanceof ILaunchConfigurationTab) { 919 ILaunchConfigurationTab[] tabs = getTabs(); 920 for (int i = 0; i < tabs.length; i++) { 921 if (tabs[i].equals(object)) { 922 fCurrentTabIndex = i; 923 fTabFolder.setSelection(i); 924 } 925 return; 926 } 927 } 928 } 929 } 930 931 } 932 933 939 public ILaunchConfigurationTab[] getTabs() { 940 if (getTabGroup() != null) { 941 return getTabGroup().getTabs(); 942 } 943 return null; 944 } 945 946 952 public ILaunchConfigurationTab getActiveTab() { 953 ILaunchConfigurationTab[] tabs = getTabs(); 954 if (fTabFolder != null && tabs != null) { 955 int pageIndex = fTabFolder.getSelectionIndex(); 956 if (pageIndex >= 0) { 957 return tabs[pageIndex]; 958 } 959 } 960 return null; 961 } 962 963 969 public boolean isDirty() { 970 ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy(); 971 if (workingCopy == null) { 972 return false; 973 } 974 if(workingCopy.getParent() != null) { 975 return !workingCopy.getParent().contentsEqual(workingCopy); 976 } 977 if (workingCopy.getOriginal() == null) { 979 return true; 980 } 981 ILaunchConfiguration original = getOriginal(); 982 return !original.contentsEqual(workingCopy); 983 } 984 985 989 protected void refreshStatus() { 990 if (!fInitializingTabs) { 991 getLaunchConfigurationDialog().updateButtons(); 992 getLaunchConfigurationDialog().updateMessage(); 993 } 994 } 995 996 999 protected ILaunchConfigurationDialog getLaunchConfigurationDialog() { 1000 return fDialog; 1001 } 1002 1003 1009 protected ILaunchConfiguration getOriginal() { 1010 return fOriginal; 1011 } 1012 1013 1017 protected ILaunchConfigurationWorkingCopy getWorkingCopy() { 1018 return fWorkingCopy; 1019 } 1020 1021 1031 public boolean canSave() { 1032 if (fInitializingTabs) { 1033 return false; 1034 } 1035 try { 1037 verifyName(); 1038 } catch (CoreException ce) { 1039 return false; 1040 } 1041 1042 ILaunchConfigurationTab[] tabs = getTabs(); 1044 if (tabs == null) { 1045 return false; 1046 } 1047 for (int i = 0; i < tabs.length; i++) { 1048 if (!tabs[i].canSave()) { 1049 return false; 1050 } 1051 } 1052 if(getWorkingCopy() != null) { 1053 return !getWorkingCopy().isReadOnly(); 1054 } 1055 return true; 1056 } 1057 1058 1061 public boolean canLaunch() { 1062 if(fInitializingTabs) { 1063 return false; 1064 } 1065 if (getWorkingCopy() == null) { 1066 return false; 1067 } 1068 try { 1069 verifyName(); 1070 } catch (CoreException e) { 1071 return false; 1072 } 1073 1074 ILaunchConfigurationTab[] tabs = getTabs(); 1075 if (tabs == null) { 1076 return false; 1077 } 1078 for (int i = 0; i < tabs.length; i++) { 1079 if (!tabs[i].isValid(getWorkingCopy())) { 1080 return false; 1081 } 1082 } 1083 return true; 1084 } 1085 1086 1094 public boolean canLaunchWithModes() { 1095 if(fInitializingTabs) { 1096 return false; 1097 } 1098 try { 1100 ILaunchConfigurationWorkingCopy wc = getWorkingCopy(); 1101 if(wc != null) { 1102 return wc.getType().supportsModeCombination(getCurrentModeSet()); 1103 } 1104 } catch (CoreException e) { 1105 } 1106 return true; 1107 } 1108 1109 1118 public boolean hasDuplicateDelegates() { 1119 if(fInitializingTabs) { 1120 return false; 1121 } 1122 ILaunchConfiguration config = getWorkingCopy(); 1123 if(config != null) { 1124 if(hasMultipleDelegates()) { 1125 return getPreferredDelegate() == null; 1126 } 1127 } 1128 return false; 1129 } 1130 1131 1136 private boolean hasMultipleDelegates() { 1137 ILaunchConfiguration config = getWorkingCopy(); 1138 if(config != null) { 1139 try { 1140 Set modes = getCurrentModeSet(); 1141 ILaunchDelegate[] delegates = LaunchConfigurationManager.filterLaunchDelegates(fTabType, modes); 1142 return delegates.length > 1; 1143 } 1144 catch (CoreException ce) {DebugUIPlugin.log(ce);} 1145 } 1146 return false; 1147 } 1148 1149 1152 public String getErrorMesssage() { 1153 if (fInitializingTabs) { 1154 return null; 1155 } 1156 1157 if (getWorkingCopy() == null) { 1158 return null; 1159 } 1160 try { 1161 verifyName(); 1162 } catch (CoreException ce) { 1163 return ce.getStatus().getMessage(); 1164 } 1165 1166 String message = null; 1167 ILaunchConfigurationTab activeTab = getActiveTab(); 1168 if (activeTab == null) { 1169 return null; 1170 } 1171 message = activeTab.getErrorMessage(); 1172 if (message != null) { 1173 return message; 1174 } 1175 1176 ILaunchConfigurationTab[] allTabs = getTabs(); 1177 for (int i = 0; i < allTabs.length; i++) { 1178 ILaunchConfigurationTab tab = allTabs[i]; 1179 if (tab == activeTab) { 1180 continue; 1181 } 1182 message = tab.getErrorMessage(); 1183 if (message != null) { 1184 StringBuffer temp= new StringBuffer (); 1185 temp.append('['); 1186 temp.append(DebugUIPlugin.removeAccelerators(tab.getName())); 1187 temp.append("]: "); temp.append(message); 1189 return temp.toString(); 1190 } 1191 } 1192 if(getWorkingCopy().isReadOnly()) { 1193 return LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_9; 1194 } 1195 if(!canLaunchWithModes()) { 1196 Set modes = getCurrentModeSet(); 1197 List names = LaunchConfigurationPresentationManager.getDefault().getLaunchModeNames(modes); 1198 return MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_14, new String []{names.toString()}); 1199 } 1200 if(hasDuplicateDelegates()) { 1201 return LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_18; 1202 } 1203 return null; 1204 } 1205 1206 1214 public String getMessage() { 1215 if (fInitializingTabs) { 1216 return null; 1217 } 1218 1219 String message = fDescription; 1220 1221 ILaunchConfigurationTab tab = getActiveTab(); 1222 if (tab != null) { 1223 String tabMessage = tab.getMessage(); 1224 if (tabMessage != null) { 1225 message = tabMessage; 1226 } 1227 } 1228 1229 return message; 1230 } 1231 1232 1235 protected void verifyName() throws CoreException { 1236 if (fNameWidget.isVisible()) { 1237 String currentName = fNameWidget.getText().trim(); 1238 1239 if (currentName.length() < 1) { 1241 throw new CoreException(new Status(IStatus.ERROR, 1242 DebugUIPlugin.getUniqueIdentifier(), 1243 0, 1244 LaunchConfigurationsMessages.LaunchConfigurationDialog_Name_required_for_launch_configuration_11, 1245 null)); 1246 } 1247 1248 IStatus status = ResourcesPlugin.getWorkspace().validateName(currentName, IResource.FILE); 1250 if (status.getCode() != IStatus.OK) { 1251 throw new CoreException(new Status(IStatus.ERROR, 1252 DebugUIPlugin.getUniqueIdentifier(), 1253 0, 1254 status.getMessage(), 1255 null)); 1256 } 1257 1258 char[] disallowedChars = new char[] { '@', '&' }; 1261 for (int i = 0; i < disallowedChars.length; i++) { 1262 char c = disallowedChars[i]; 1263 if (currentName.indexOf(c) > -1) { 1264 throw new CoreException(new Status(IStatus.ERROR, 1265 DebugUIPlugin.getUniqueIdentifier(), 1266 0, 1267 MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_0, new String [] { new String (new char[] {c}), currentName }), 1268 null)); 1269 } 1270 } 1271 1272 if (!getOriginal().getName().equals(currentName)) { 1274 Set reservednames = ((LaunchConfigurationsDialog)getLaunchConfigurationDialog()).getReservedNameSet(); 1275 if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(currentName) || (reservednames != null ? reservednames.contains(currentName) : false)) { 1276 throw new CoreException(new Status(IStatus.ERROR, 1277 DebugUIPlugin.getUniqueIdentifier(), 1278 0, 1279 LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_configuration_already_exists_with_this_name_12, 1280 null)); 1281 } 1282 } 1283 } 1284 } 1285 1286 1289 private void disposeExistingTabs() { 1290 fDisposingTabs = true; 1291 fTabFolder.dispose(); 1292 fTabFolder = null; 1293 createTabFolder(fTabComposite); 1294 disposeTabGroup(); 1295 fDisposingTabs = false; 1296 } 1297 1298 1303 public ILaunchConfigurationTabGroup getTabGroup() { 1304 return fTabGroup; 1305 } 1306 1307 1314 protected void handleTabSelected() { 1315 if (fDisposingTabs || fInitializingTabs) { 1316 return; 1317 } 1318 ILaunchConfigurationTab[] tabs = getTabs(); 1319 if (fCurrentTabIndex == fTabFolder.getSelectionIndex() || tabs == null || tabs.length == 0 || fCurrentTabIndex > (tabs.length - 1)) { 1320 return; 1321 } 1322 if (fCurrentTabIndex != -1) { 1323 ILaunchConfigurationTab tab = tabs[fCurrentTabIndex]; 1324 ILaunchConfigurationWorkingCopy wc = getWorkingCopy(); 1325 if (wc != null) { 1326 tab.deactivated(wc); 1327 getActiveTab().activated(wc); 1328 } 1329 } 1330 fCurrentTabIndex = fTabFolder.getSelectionIndex(); 1331 } 1332 1333 1336 protected void handleNameModified() { 1337 getWorkingCopy().rename(fNameWidget.getText().trim()); 1338 refreshStatus(); 1339 } 1340 1341 1344 protected void handleApplyPressed() { 1345 Exception exception = null; 1346 try { 1347 fInitializingTabs = true; 1349 String trimmed = fNameWidget.getText().trim(); 1351 fNameWidget.setText(trimmed); 1352 if(fWorkingCopy == null) { 1353 fWorkingCopy = fOriginal.getWorkingCopy(); 1354 } 1355 fWorkingCopy.rename(trimmed); 1356 getTabGroup().performApply(fWorkingCopy); 1357 if (isDirty()) { 1358 if(!fWorkingCopy.isLocal()) { 1359 IRunnableWithProgress runnable = new IRunnableWithProgress() { 1360 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 1361 try { 1362 ((LaunchConfigurationWorkingCopy)fWorkingCopy).doSave(monitor); 1363 } 1364 catch (CoreException e) {DebugUIPlugin.log(e);} 1365 } 1366 }; 1367 getLaunchConfigurationDialog().run(true, false, runnable); 1368 } 1369 else { 1370 fWorkingCopy.doSave(); 1371 } 1372 } 1373 updateButtons(); 1374 fInitializingTabs = false; 1375 } 1376 catch (CoreException e) {exception = e;} 1377 catch (InvocationTargetException e) {exception = e;} 1378 catch (InterruptedException e) {exception = e;} 1379 if(exception != null) { 1380 DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_Configuration_Error_46, LaunchConfigurationsMessages.LaunchConfigurationDialog_Exception_occurred_while_saving_launch_configuration_47, exception); return; 1382 } 1383 } 1384 1385 1388 protected void handleRevertPressed() { 1389 try { 1390 if(fTabGroup != null) { 1391 fTabGroup.initializeFrom(fOriginal); 1392 fNameWidget.setText(fOriginal.getName()); 1393 fWorkingCopy = fOriginal.getWorkingCopy(); 1394 refreshStatus(); 1395 } 1396 } 1397 catch (CoreException e) {DebugUIPlugin.log(e);} 1398 } 1399 1400 1405 protected void errorDialog(CoreException exception) { 1406 ErrorDialog.openError(getShell(), null, null, exception.getStatus()); 1407 } 1408 1409 1415 public void setActiveTab(ILaunchConfigurationTab tab) { 1416 ILaunchConfigurationTab[] tabs = getTabs(); 1417 if(tabs != null) { 1418 for (int i = 0; i < tabs.length; i++) { 1419 if (tabs[i].getClass().equals(tab.getClass())) { 1420 setActiveTab(i); 1421 return; 1422 } 1423 } 1424 } 1425 } 1426 1427 1434 public void setActiveTab(int index) { 1435 ILaunchConfigurationTab[] tabs = getTabs(); 1436 if (index >= 0 && index < tabs.length) { 1437 fTabFolder.setSelection(index); 1438 handleTabSelected(); 1439 } 1440 } 1441 1442} 1443 | Popular Tags |