1 12 package org.eclipse.debug.internal.ui.launchConfigurations; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.ListenerList; 23 import org.eclipse.core.runtime.NullProgressMonitor; 24 import org.eclipse.core.runtime.SafeRunner; 25 import org.eclipse.core.runtime.Status; 26 import org.eclipse.debug.core.DebugPlugin; 27 import org.eclipse.debug.core.ILaunchConfiguration; 28 import org.eclipse.debug.core.ILaunchConfigurationType; 29 import org.eclipse.debug.core.ILaunchManager; 30 import org.eclipse.debug.core.IStatusHandler; 31 import org.eclipse.debug.internal.core.LaunchManager; 32 import org.eclipse.debug.internal.ui.DebugUIPlugin; 33 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 34 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 35 import org.eclipse.debug.ui.DebugUITools; 36 import org.eclipse.debug.ui.IDebugUIConstants; 37 import org.eclipse.debug.ui.IDebugView; 38 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 39 import org.eclipse.debug.ui.ILaunchConfigurationTab; 40 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; 41 import org.eclipse.jface.action.Action; 42 import org.eclipse.jface.action.IAction; 43 import org.eclipse.jface.action.Separator; 44 import org.eclipse.jface.action.ToolBarManager; 45 import org.eclipse.jface.dialogs.ErrorDialog; 46 import org.eclipse.jface.dialogs.IDialogConstants; 47 import org.eclipse.jface.dialogs.IDialogSettings; 48 import org.eclipse.jface.dialogs.IPageChangeProvider; 49 import org.eclipse.jface.dialogs.IPageChangedListener; 50 import org.eclipse.jface.dialogs.MessageDialog; 51 import org.eclipse.jface.dialogs.PageChangedEvent; 52 import org.eclipse.jface.dialogs.TitleAreaDialog; 53 import org.eclipse.jface.operation.IRunnableWithProgress; 54 import org.eclipse.jface.operation.ModalContext; 55 import org.eclipse.jface.resource.ImageDescriptor; 56 import org.eclipse.jface.util.IPropertyChangeListener; 57 import org.eclipse.jface.util.PropertyChangeEvent; 58 import org.eclipse.jface.util.SafeRunnable; 59 import org.eclipse.jface.viewers.ISelectionChangedListener; 60 import org.eclipse.jface.viewers.IStructuredSelection; 61 import org.eclipse.jface.viewers.SelectionChangedEvent; 62 import org.eclipse.jface.viewers.StructuredSelection; 63 import org.eclipse.jface.viewers.StructuredViewer; 64 import org.eclipse.jface.viewers.TreeViewer; 65 import org.eclipse.jface.viewers.Viewer; 66 import org.eclipse.jface.viewers.ViewerFilter; 67 import org.eclipse.jface.wizard.ProgressMonitorPart; 68 import org.eclipse.swt.SWT; 69 import org.eclipse.swt.custom.SashForm; 70 import org.eclipse.swt.custom.ViewForm; 71 import org.eclipse.swt.graphics.Font; 72 import org.eclipse.swt.graphics.Image; 73 import org.eclipse.swt.graphics.Point; 74 import org.eclipse.swt.graphics.Rectangle; 75 import org.eclipse.swt.layout.GridData; 76 import org.eclipse.swt.layout.GridLayout; 77 import org.eclipse.swt.widgets.Button; 78 import org.eclipse.swt.widgets.Composite; 79 import org.eclipse.swt.widgets.Control; 80 import org.eclipse.swt.widgets.Display; 81 import org.eclipse.swt.widgets.Shell; 82 import org.eclipse.swt.widgets.ToolBar; 83 import org.eclipse.swt.widgets.TreeItem; 84 import org.eclipse.ui.PlatformUI; 85 import org.eclipse.ui.progress.WorkbenchJob; 86 87 import com.ibm.icu.text.MessageFormat; 88 89 92 public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaunchConfigurationDialog, IPageChangeProvider, IPropertyChangeListener { 93 94 97 private static ILaunchConfigurationDialog fgCurrentlyVisibleLaunchConfigurationDialog; 98 101 protected static final int ID_LAUNCH_BUTTON = IDialogConstants.CLIENT_ID + 1; 102 103 106 protected static final int ID_CLOSE_BUTTON = IDialogConstants.CLIENT_ID + 2; 107 110 protected static final int ID_CANCEL_BUTTON = IDialogConstants.CLIENT_ID + 3; 111 112 116 protected static final int ID_DISCARD_BUTTON = IDialogConstants.CLIENT_ID + 4; 117 118 122 protected static final float MAX_DIALOG_WIDTH_PERCENT = 0.75f; 123 127 protected static final float MAX_DIALOG_HEIGHT_PERCENT = 0.60f; 128 131 protected static final Point DEFAULT_INITIAL_DIALOG_SIZE = new Point(800, 640); 132 136 private static final int[] DEFAULT_SASH_WEIGHTS = new int[] {190, 610}; 137 141 public static final int LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED = 2; 142 146 public static final int LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION = 3; 147 151 public static final int LAUNCH_CONFIGURATION_DIALOG_REUSE_OPEN = 4; 152 156 private static final String EMPTY_STRING = ""; 161 private static final String DELIMITER = ", "; 166 private int fOpenMode = LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED; 167 168 171 private static final String DIALOG_SASH_WEIGHTS_1 = IDebugUIConstants.PLUGIN_ID + ".DIALOG_SASH_WEIGHTS_1"; private static final String DIALOG_SASH_WEIGHTS_2 = IDebugUIConstants.PLUGIN_ID + ".DIALOG_SASH_WEIGHTS_2"; private static final String DIALOG_EXPANDED_NODES = IDebugUIConstants.PLUGIN_ID + ".EXPANDED_NODES"; 175 179 public static ILaunchConfigurationDialog getCurrentlyVisibleLaunchConfigurationDialog() { 180 return fgCurrentlyVisibleLaunchConfigurationDialog; 181 } 182 186 public static void setCurrentlyVisibleLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { 187 fgCurrentlyVisibleLaunchConfigurationDialog = dialog; 188 } 189 190 193 private Control fLastControl; 194 private Composite fButtonComp; 195 private SashForm fSashForm; 196 private LaunchConfigurationView fLaunchConfigurationView; 197 private LaunchConfigurationTabGroupViewer fTabViewer; 198 private Button fProgressMonitorCancelButton; 199 private ProgressMonitorPart fProgressMonitorPart; 200 private LaunchGroupExtension fGroup; 201 private Image fBannerImage; 202 203 207 private IStructuredSelection fInitialSelection; 208 209 212 private IStatus fInitialStatus; 213 214 217 private ListenerList changeListeners = new ListenerList(); 218 219 222 private long fActiveRunningOperations = 0; 223 224 227 private IAction fDoubleClickAction; 228 229 233 private ClosedProjectFilter fClosedProjectFilter; 234 private DeletedProjectFilter fDeletedProjectFilter; 235 private LaunchConfigurationTypeFilter fLCTFilter; 236 private WorkingSetsFilter fWorkingSetsFilter; 237 238 241 protected Set fReservedNames = null; 242 243 250 public LaunchConfigurationsDialog(Shell shell, LaunchGroupExtension group) { 251 super(shell); 252 setShellStyle(getShellStyle() | SWT.RESIZE); 253 setLaunchGroup(group); 254 } 255 256 261 protected void addContent(Composite dialogComp) { 262 GridData gd; 263 Composite topComp = new Composite(dialogComp, SWT.NONE); 264 gd = new GridData(GridData.FILL_BOTH); 265 topComp.setLayoutData(gd); 266 GridLayout topLayout = new GridLayout(2, false); 267 topLayout.marginHeight = 5; 268 topLayout.marginWidth = 5; 269 topComp.setLayout(topLayout); 270 271 setTitle(LaunchConfigurationsMessages.LaunchConfigurationDialog_Create__manage__and_run_launch_configurations_8); 273 setMessage(LaunchConfigurationsMessages.LaunchConfigurationDialog_Ready_to_launch_2); 274 setModeLabelState(); 275 276 gd = new GridData(GridData.FILL_BOTH); 279 gd.horizontalSpan = 2; 280 SashForm sash = new SashForm(topComp, SWT.SMOOTH); 281 sash.setOrientation(SWT.HORIZONTAL); 282 sash.setLayoutData(gd); 283 sash.setFont(dialogComp.getFont()); 284 sash.setVisible(true); 285 fSashForm = sash; 286 287 Control launchConfigSelectionArea = createLaunchConfigurationSelectionArea(fSashForm); 289 gd = new GridData(GridData.FILL_VERTICAL); 290 launchConfigSelectionArea.setLayoutData(gd); 291 292 Composite editAreaComp = createLaunchConfigurationEditArea(fSashForm); 294 gd = new GridData(GridData.FILL_BOTH); 295 editAreaComp.setLayoutData(gd); 296 297 dialogComp.layout(true); 298 applyDialogFont(dialogComp); 299 } 300 301 304 public void addPageChangedListener(IPageChangedListener listener) { 305 changeListeners.add(listener); 306 } 307 308 314 protected void buttonPressed(int buttonId) { 315 if (buttonId == ID_LAUNCH_BUTTON) { 316 handleLaunchPressed(); 317 } 318 else if (buttonId == ID_CLOSE_BUTTON) { 319 handleClosePressed(); 320 } 321 else { 322 super.buttonPressed(buttonId); 323 } 324 } 325 326 332 protected int shouldSaveCurrentConfig() { 333 if (getTabViewer().isDirty()) { 334 if (getTabViewer().canSave()) { 335 return showSaveChangesDialog(); 336 } 337 return showUnsavedChangesDialog(); 338 } 339 return IDialogConstants.NO_ID; 340 } 341 342 345 public boolean close() { 346 if (!isSafeToClose()) { 347 return false; 348 } 349 persistSashWeights(); 350 persistExpansion(); 351 setCurrentlyVisibleLaunchConfigurationDialog(null); 352 getBannerImage().dispose(); 353 getTabViewer().dispose(); 354 if (fLaunchConfigurationView != null) { 355 fLaunchConfigurationView.dispose(); 356 } 357 DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); 358 return super.close(); 359 } 360 361 366 protected void configureShell(Shell shell) { 367 super.configureShell(shell); 368 shell.setText(getShellTitle()); 369 } 370 371 374 public void create() { 375 super.create(); 376 if (getTabViewer().getInput() == null) { 377 getTabViewer().inputChanged(null); 378 } 379 } 380 381 384 protected Control createButtonBar(Composite parent) { 385 Font font = parent.getFont(); 386 Composite composite = new Composite(parent, SWT.NULL); 387 GridLayout layout = new GridLayout(); 388 layout.numColumns = 2; 389 layout.marginHeight= 0; 390 layout.marginWidth= 0; 391 layout.marginLeft = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 392 composite.setLayout(layout); 393 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 394 composite.setFont(font); 395 if (isHelpAvailable()) { 397 createHelpControl(composite); 398 } 399 Composite monitorComposite = new Composite(composite, SWT.NULL); 400 layout = new GridLayout(); 401 layout.marginHeight = 0; 402 layout.marginWidth = 0; 403 layout.numColumns = 2; 404 monitorComposite.setLayout(layout); 405 monitorComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 406 GridLayout pmLayout = new GridLayout(); 407 fProgressMonitorPart = new ProgressMonitorPart(monitorComposite, pmLayout); 408 fProgressMonitorPart.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 409 fProgressMonitorPart.setFont(font); 410 fProgressMonitorCancelButton = createButton(monitorComposite, ID_CANCEL_BUTTON, LaunchConfigurationsMessages.LaunchConfigurationDialog_Cancel_3, true); 411 fProgressMonitorCancelButton.setFont(font); 412 monitorComposite.setVisible(false); 413 414 418 boolean helpAvailable = isHelpAvailable(); 419 setHelpAvailable(false); 420 fButtonComp = (Composite) super.createButtonBar(composite); 421 setHelpAvailable(helpAvailable); 422 return composite; 423 } 424 425 426 427 435 protected void createButtonsForButtonBar(Composite parent) { 436 Button button = createButton(parent, ID_LAUNCH_BUTTON, getLaunchButtonText(), true); 437 button.setEnabled(false); 438 createButton(parent, ID_CLOSE_BUTTON, LaunchConfigurationsMessages.LaunchConfigurationDialog_Close_1, false); 439 } 440 441 444 protected Control createContents(Composite parent) { 445 Control contents = super.createContents(parent); 446 initializeContent(); 447 PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), getHelpContextId()); 448 return contents; 449 } 450 451 454 protected Control createDialogArea(Composite parent) { 455 Composite dialogComp = (Composite)super.createDialogArea(parent); 456 addContent(dialogComp); 457 if(fLaunchConfigurationView != null) { 458 fLaunchConfigurationView.updateFilterLabel(); 459 } 460 return dialogComp; 461 } 462 463 471 protected Composite createLaunchConfigurationEditArea(Composite parent) { 472 setTabViewer(new LaunchConfigurationTabGroupViewer(parent, this)); 473 getTabViewer().addSelectionChangedListener(new ISelectionChangedListener() { 474 public void selectionChanged(SelectionChangedEvent event) { 475 handleTabSelectionChanged(); 476 } 477 }); 478 return (Composite)getTabViewer().getControl(); 479 } 480 481 486 protected void createToolbarActions(ToolBarManager tmanager) { 487 tmanager.add(getNewAction()); 488 tmanager.add(getDuplicateAction()); 489 tmanager.add(getDeleteAction()); 490 tmanager.add(new Separator()); 491 tmanager.add(getCollapseAllAction()); 492 tmanager.add(getFilterAction()); 493 tmanager.update(true); 494 DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); 495 } 496 497 505 protected Control createLaunchConfigurationSelectionArea(Composite parent) { 506 Composite comp = new Composite(parent, SWT.FLAT); 507 GridLayout gridLayout = new GridLayout(1, false); 508 gridLayout.marginHeight = 0; 509 gridLayout.marginWidth = 0; 510 comp.setLayout(gridLayout); 511 comp.setLayoutData(new GridData(GridData.FILL_BOTH)); 512 513 ViewForm viewForm = new ViewForm(comp, SWT.FLAT | SWT.BORDER); 514 ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT); 515 toolBar.setBackground(parent.getBackground()); 516 ToolBarManager toolBarManager= new ToolBarManager(toolBar); 517 viewForm.setTopLeft(toolBar); 518 viewForm.setLayoutData(new GridData(GridData.FILL_BOTH)); 519 520 Composite viewFormContents = new Composite(viewForm, SWT.FLAT); 521 gridLayout = new GridLayout(); 522 gridLayout.marginHeight = 5; 523 gridLayout.marginWidth = 5; 524 viewFormContents.setLayout(gridLayout); 525 viewFormContents.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); 526 fLaunchConfigurationView = new LaunchConfigurationView(getLaunchGroup(), createViewerFilters()); 527 fLaunchConfigurationView.createLaunchDialogControl(viewFormContents); 528 529 createToolbarActions(toolBarManager); 532 fDoubleClickAction = new Action() { 533 public void run() { 534 IStructuredSelection selection = (IStructuredSelection)fLaunchConfigurationView.getViewer().getSelection(); 535 Object target = selection.getFirstElement(); 536 if (target instanceof ILaunchConfiguration) { 537 if (getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates()) { 538 handleLaunchPressed(); 539 } 540 } else { 541 getNewAction().run(); 542 } 543 } 544 }; 545 fLaunchConfigurationView.setAction(IDebugView.DOUBLE_CLICK_ACTION, fDoubleClickAction); 546 Viewer viewer = fLaunchConfigurationView.getViewer(); 547 548 Control control = viewer.getControl(); 549 GridData gd = new GridData(GridData.FILL_BOTH); 550 control.setLayoutData(gd); 551 viewForm.setContent(viewFormContents); 552 AbstractLaunchConfigurationAction.IConfirmationRequestor requestor = new AbstractLaunchConfigurationAction.IConfirmationRequestor() { 553 public boolean getConfirmation() { 554 int status = shouldSaveCurrentConfig(); 555 if(status == IDialogConstants.YES_ID) { 556 fTabViewer.handleApplyPressed(); 557 return true; 558 } 559 else if(status == IDialogConstants.NO_ID) { 560 fTabViewer.handleRevertPressed(); 561 return true; 562 } 563 return false; 564 } 565 }; 566 getDuplicateAction().setConfirmationRequestor(requestor); 567 getNewAction().setConfirmationRequestor(requestor); 568 ((StructuredViewer) viewer).addPostSelectionChangedListener(new ISelectionChangedListener() { 569 public void selectionChanged(SelectionChangedEvent event) { 570 handleLaunchConfigurationSelectionChanged(event); 571 getNewAction().setEnabled(getNewAction().isEnabled()); 572 getDeleteAction().setEnabled(getDeleteAction().isEnabled()); 573 getDuplicateAction().setEnabled(getDuplicateAction().isEnabled()); 574 } 575 }); 576 return comp; 577 } 578 579 585 private ViewerFilter[] createViewerFilters() { 586 ArrayList filters = new ArrayList (); 587 fClosedProjectFilter = new ClosedProjectFilter(); 588 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED)) { 589 filters.add(fClosedProjectFilter); 590 } 591 fDeletedProjectFilter = new DeletedProjectFilter(); 592 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED)) { 593 filters.add(fDeletedProjectFilter); 594 } 595 fLCTFilter = new LaunchConfigurationTypeFilter(); 596 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) { 597 filters.add(fLCTFilter); 598 } 599 fWorkingSetsFilter = new WorkingSetsFilter(); 600 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS)) { 601 filters.add(fWorkingSetsFilter); 602 } 603 return (ViewerFilter[]) filters.toArray(new ViewerFilter[filters.size()]); 604 } 605 606 609 public void doInitialTreeSelection() { 610 fLaunchConfigurationView.getViewer().setSelection(fInitialSelection); 611 } 612 613 622 protected void firePageChanged(final PageChangedEvent event) { 623 Object [] listeners = changeListeners.getListeners(); 624 for (int i = 0; i < listeners.length; ++i) { 625 final IPageChangedListener l = (IPageChangedListener) listeners[i]; 626 SafeRunner.run(new SafeRunnable() { 627 public void run() { 628 l.pageChanged(event); 629 } 630 }); 631 } 632 } 633 634 637 public String generateName(String name) { 638 if (name == null) { 639 name = EMPTY_STRING; 640 } 641 return getLaunchManager().generateUniqueLaunchConfigurationNameFrom(name); 642 } 643 644 654 public String generateName(String name, Set reservednames) { 655 if(name == null) { 656 name = EMPTY_STRING; 657 } 658 return ((LaunchManager)getLaunchManager()).generateUniqueLaunchConfigurationNameFrom(name, reservednames); 659 } 660 661 664 public ILaunchConfigurationTab getActiveTab() { 665 return getTabViewer().getActiveTab(); 666 } 667 668 671 protected Image getBannerImage() { 672 if (fBannerImage == null) { 673 ImageDescriptor descriptor = getLaunchGroup().getBannerImageDescriptor(); 674 if (descriptor != null) { 675 fBannerImage = descriptor.createImage(); 676 } 677 } 678 return fBannerImage; 679 } 680 681 686 protected AbstractLaunchConfigurationAction getDeleteAction() { 687 return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(DeleteLaunchConfigurationAction.ID_DELETE_ACTION); 688 } 689 690 695 protected IAction getFilterAction() { 696 return fLaunchConfigurationView.getAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION); 697 } 698 699 704 protected IAction getCollapseAllAction() { 705 return fLaunchConfigurationView.getAction(CollapseAllLaunchConfigurationAction.ID_COLLAPSEALL_ACTION); 706 } 707 708 712 protected IDialogSettings getDialogBoundsSettings() { 713 return getDialogSettings(); 714 } 715 716 722 protected IDialogSettings getDialogSettings() { 723 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 724 IDialogSettings section = settings.getSection(getDialogSettingsSectionName()); 725 if (section == null) { 726 section = settings.addNewSection(getDialogSettingsSectionName()); 727 } 728 return section; 729 } 730 731 736 protected String getDialogSettingsSectionName() { 737 return IDebugUIConstants.PLUGIN_ID + ".LAUNCH_CONFIGURATIONS_DIALOG_SECTION"; } 739 740 745 protected Display getDisplay() { 746 Shell shell = getShell(); 747 if (shell != null) { 748 return shell.getDisplay(); 749 } 750 return Display.getDefault(); 751 } 752 753 758 protected AbstractLaunchConfigurationAction getDuplicateAction() { 759 return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(DuplicateLaunchConfigurationAction.ID_DUPLICATE_ACTION); 760 } 761 762 767 protected String getHelpContextId() { 768 return IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG; 769 } 770 771 776 protected IStatus getInitialStatus() { 777 return fInitialStatus; 778 } 779 780 785 protected ILaunchConfiguration getLastLaunchedWorkbenchConfiguration() { 786 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLastLaunch(getLaunchGroup().getIdentifier()); 787 } 788 789 794 protected String getLaunchButtonText() { 795 return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(getMode()).getLabel(); 796 } 797 798 803 public LaunchGroupExtension getLaunchGroup() { 804 return fGroup; 805 } 806 807 810 public String getMode() { 811 return getLaunchGroup().getMode(); 812 } 813 814 819 protected AbstractLaunchConfigurationAction getNewAction() { 820 return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(CreateLaunchConfigurationAction.ID_CREATE_ACTION); 821 } 822 823 829 public Set getReservedNameSet() { 830 return fReservedNames; 831 } 832 833 838 protected int getOpenMode() { 839 return fOpenMode; 840 } 841 842 845 public Object getSelectedPage() { 846 return getActiveTab(); 847 } 848 849 853 protected String getShellTitle() { 854 String title = null; 855 if(getLaunchGroup() != null) { 856 title = DebugUIPlugin.removeAccelerators(getLaunchGroup().getLabel()); 857 } 858 if (title == null) { 859 title = LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_Configurations_18; 860 } 861 return title; 862 } 863 864 869 public ILaunchConfigurationTabGroup getTabGroup() { 870 if (getTabViewer() != null) { 871 return getTabViewer().getTabGroup(); 872 } 873 return null; 874 } 875 876 879 public ILaunchConfigurationTab[] getTabs() { 880 if (getTabGroup() == null) { 881 return null; 882 } 883 return getTabGroup().getTabs(); 884 } 885 886 891 protected LaunchConfigurationTabGroupViewer getTabViewer() { 892 return fTabViewer; 893 } 894 895 898 protected void handleClosePressed() { 899 int status = shouldSaveCurrentConfig(); 900 if(status != IDialogConstants.CANCEL_ID) { 901 if(status != ID_DISCARD_BUTTON) { 902 if(status == IDialogConstants.YES_ID) { 903 getTabViewer().handleApplyPressed(); 904 } 905 cancelPressed(); 906 } 907 } 908 } 909 910 919 protected void handleLaunchConfigurationSelectionChanged(SelectionChangedEvent event) { 920 Object input = getTabViewer().getInput(); 921 Object newInput = null; 922 IStructuredSelection selection = (IStructuredSelection) event.getSelection(); 923 if (!selection.isEmpty()) { 924 if (selection.size() == 1) { 925 newInput = selection.getFirstElement(); 926 } 927 } 928 if (!isEqual(input, newInput)) { 929 LaunchConfigurationTabGroupViewer viewer = getTabViewer(); 930 ILaunchConfiguration original = viewer.getOriginal(); 931 if (original != null && newInput == null && getLaunchManager().getMovedTo(original) != null) { 932 return; 933 } 934 boolean deleted = false; 935 if (original != null) { 936 deleted = !original.exists(); 937 } 938 boolean renamed = false; 939 if (newInput instanceof ILaunchConfiguration) { 940 renamed = getLaunchManager().getMovedFrom((ILaunchConfiguration)newInput) != null; 941 } 942 Object in = input; 943 if (viewer.isDirty() && !deleted && !renamed) { 944 if(fLaunchConfigurationView != null) { 945 fLaunchConfigurationView.setAutoSelect(false); 946 } 947 int ret = showUnsavedChangesDialog(); 948 boolean cansave = viewer.canSave(); 949 if(ret == IDialogConstants.YES_ID) { 950 if(cansave) { 951 viewer.handleApplyPressed(); 952 } 953 else { 954 viewer.handleRevertPressed(); 955 } 956 in = newInput; 957 } 958 else if(ret == IDialogConstants.NO_ID) { 959 if(cansave) { 960 viewer.handleRevertPressed(); 961 if(viewer.isDirty()) { 962 viewer.handleApplyPressed(); 963 } 964 in = newInput; 965 } 966 } 967 if(fLaunchConfigurationView != null) { 968 if(in != null) { 969 fLaunchConfigurationView.getViewer().setSelection(new StructuredSelection(in)); 970 } 971 fLaunchConfigurationView.setAutoSelect(true); 972 } 973 } 974 else { 975 viewer.setInput(newInput); 976 if(newInput != null) { 977 if(viewer.isDirty()) { 978 viewer.handleApplyPressed(); 979 } 980 if (getShell() != null && getShell().isVisible()) { 981 resize(); 982 } 983 } 984 } 985 986 } 987 } 988 989 993 protected void handleLaunchPressed() { 994 ILaunchConfiguration config = getTabViewer().getOriginal(); 995 if (getTabViewer().isDirty() & getTabViewer().canSave()) { 996 getTabViewer().handleApplyPressed(); 997 config = getTabViewer().getOriginal(); 998 } 999 String mode = getMode(); 1000 close(); 1001 if(config != null) { 1002 DebugUITools.launch(config, mode); 1003 } 1004 } 1005 1006 1012 public void handleStatus(IStatus status) { 1013 IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); 1014 if (handler != null) { 1015 try { 1016 handler.handleStatus(status, this); 1017 return; 1018 } 1019 catch (CoreException e) {status = e.getStatus();} 1020 } 1021 String title = null; 1023 switch (status.getSeverity()) { 1024 case IStatus.ERROR: 1025 title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Error_1; 1026 break; 1027 case IStatus.WARNING: 1028 title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Warning_2; 1029 break; 1030 default: 1031 title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Information_3; 1032 break; 1033 } 1034 ErrorDialog.openError(getShell(), title, null, status); 1035 } 1036 1037 1041 protected void handleTabSelectionChanged() { 1042 updateMessage(); 1043 firePageChanged(new PageChangedEvent(this, getSelectedPage())); 1044 } 1045 1046 1049 protected void initializeBounds() { 1050 IDialogSettings settings = getDialogSettings(); 1051 if (fSashForm != null) { 1052 int w1, w2; 1053 try { 1054 w1 = settings.getInt(DIALOG_SASH_WEIGHTS_1); 1055 w2 = settings.getInt(DIALOG_SASH_WEIGHTS_2); 1056 } 1057 catch(NumberFormatException nfe) { 1058 w1 = DEFAULT_SASH_WEIGHTS[0]; 1059 w2 = DEFAULT_SASH_WEIGHTS[1]; 1060 } 1061 fSashForm.setWeights(new int[] {w1, w2}); 1062 } 1063 super.initializeBounds(); 1064 } 1065 1066 1069 protected Point getInitialSize() { 1070 IDialogSettings settings = getDialogSettings(); 1071 if(settings.get(DIALOG_SASH_WEIGHTS_1) != null) { 1072 return super.getInitialSize(); 1073 } 1074 return DEFAULT_INITIAL_DIALOG_SIZE; 1075 } 1076 1077 1080 protected void initializeContent() { 1081 doInitialTreeSelection(); 1082 IStatus status = getInitialStatus(); 1083 if (status != null) { 1084 handleStatus(status); 1085 } 1086 fLaunchConfigurationView.getFilteringTextControl().setFocus(); 1087 restoreExpansion(); 1088 } 1089 1090 1097 protected boolean isEqual(Object o1, Object o2) { 1098 if (o1 == o2) { 1099 return true; 1100 } else if (o1 == null) { 1101 return false; 1102 } else { 1103 return o1.equals(o2); 1104 } 1105 } 1106 1107 1112 protected boolean isSafeToClose() { 1113 return fActiveRunningOperations == 0; 1114 } 1115 1116 1124 public int open() { 1125 int mode = getOpenMode(); 1126 setCurrentlyVisibleLaunchConfigurationDialog(this); 1127 if (mode == LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED) { 1128 ILaunchConfiguration lastLaunchedConfig = getLastLaunchedWorkbenchConfiguration(); 1129 if (lastLaunchedConfig != null) { 1130 setInitialSelection(new StructuredSelection(lastLaunchedConfig)); 1131 } 1132 } 1133 return super.open(); 1134 } 1135 1136 1140 protected void persistExpansion() { 1141 if(fLaunchConfigurationView != null) { 1142 IDialogSettings settings = getDialogSettings(); 1143 TreeItem[] items = fLaunchConfigurationView.getTreeViewer().getTree().getItems(); 1144 String value = settings.get(DIALOG_EXPANDED_NODES); 1145 if(value == null) { 1146 value = EMPTY_STRING; 1147 } 1148 ArrayList list = new ArrayList (); 1149 String [] persisted = value.split(DELIMITER); 1150 for(int i = 0; i < persisted.length; i++) { 1151 list.add(persisted[i]); 1152 } 1153 String type = EMPTY_STRING; 1154 for(int i = 0; i < items.length; i++) { 1157 type = ((ILaunchConfigurationType)items[i].getData()).getIdentifier(); 1158 if(!list.contains(type) & items[i].getExpanded()) { 1159 list.add(type); 1160 } 1161 else if(!items[i].getExpanded()) { 1162 list.remove(type); 1163 } 1164 } 1165 value = EMPTY_STRING; 1166 for(Iterator iter = list.iterator(); iter.hasNext();) { 1168 value += iter.next() + DELIMITER; 1169 } 1170 settings.put(DIALOG_EXPANDED_NODES, value); 1171 } 1172 } 1173 1174 1178 protected void restoreExpansion() { 1179 if(fLaunchConfigurationView != null) { 1180 IDialogSettings settings = getDialogSettings(); 1181 String value = settings.get(DIALOG_EXPANDED_NODES); 1182 if(value != null) { 1183 String [] nodes = value.split(DELIMITER); 1184 TreeItem[] items = fLaunchConfigurationView.getTreeViewer().getTree().getItems(); 1185 ArrayList toexpand = new ArrayList (); 1186 if(fInitialSelection != null && !fInitialSelection.isEmpty()) { 1188 Object obj = fInitialSelection.getFirstElement(); 1189 if(obj instanceof ILaunchConfigurationType) { 1190 toexpand.add(obj); 1191 } 1192 else if(obj instanceof ILaunchConfiguration) { 1193 try { 1194 toexpand.add(((ILaunchConfiguration) obj).getType()); 1195 } 1196 catch (CoreException e) {DebugUIPlugin.log(e);} 1197 } 1198 } 1199 for(int i = 0; i < nodes.length; i++) { 1200 for(int k = 0; k < items.length; k++) { 1201 ILaunchConfigurationType type = (ILaunchConfigurationType)items[k].getData(); 1202 if(type.getIdentifier().equals(nodes[i])) { 1203 toexpand.add(type); 1204 } 1205 } 1206 } 1207 fLaunchConfigurationView.getTreeViewer().setExpandedElements(toexpand.toArray()); 1208 } 1209 } 1210 } 1211 1212 1215 protected void persistSashWeights() { 1216 IDialogSettings settings = getDialogSettings(); 1217 if (fSashForm != null) { 1218 int[] sashWeights = fSashForm.getWeights(); 1219 settings.put(DIALOG_SASH_WEIGHTS_1, sashWeights[0]); 1220 settings.put(DIALOG_SASH_WEIGHTS_2, sashWeights[1]); 1221 } 1222 } 1223 1224 1227 protected void refreshStatus() { 1228 updateMessage(); 1229 updateButtons(); 1230 } 1231 1232 1235 public void removePageChangedListener(IPageChangedListener listener) { 1236 changeListeners.remove(listener); 1237 } 1238 1239 1242 protected void resize() { 1243 if(getTabGroup() != null) { 1244 Point shell = getShell().getSize(); 1245 int maxx = (int)(getDisplay().getBounds().width * MAX_DIALOG_WIDTH_PERCENT), 1246 maxy = (int) (getDisplay().getBounds().height * MAX_DIALOG_HEIGHT_PERCENT); 1247 maxx = (maxx < DEFAULT_INITIAL_DIALOG_SIZE.x ? DEFAULT_INITIAL_DIALOG_SIZE.x : maxx); 1248 maxy = (maxy < DEFAULT_INITIAL_DIALOG_SIZE.y ? DEFAULT_INITIAL_DIALOG_SIZE.y : maxy); 1249 Point psize = getShell().computeSize(SWT.DEFAULT, maxy); 1250 if((psize.x > maxx ? maxx : psize.x) > shell.x || (psize.y > maxy ? maxy : psize.y) > shell.y) { 1251 setShellSize(Math.min(psize.x, maxx), Math.min(psize.y, maxy)); 1252 } 1253 } 1254 } 1255 1256 1259 public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException , InterruptedException { 1260 if (getShell() != null && getShell().isVisible()) { 1261 fLastControl = getShell().getDisplay().getFocusControl(); 1263 if (fLastControl != null && fLastControl.getShell() != getShell()) { 1264 fLastControl = null; 1265 } 1266 fProgressMonitorCancelButton.setEnabled(cancelable); 1267 fProgressMonitorPart.attachToCancelComponent(fProgressMonitorCancelButton); 1269 fProgressMonitorPart.getParent().setVisible(true); 1270 fProgressMonitorCancelButton.setFocus(); 1271 fActiveRunningOperations++; 1272 1273 Control[] children = ((Composite)fButtonComp.getChildren()[0]).getChildren(); 1276 boolean[] prev = new boolean[children.length+2]; 1277 prev[0] = getTabViewer().getApplyButton().isEnabled(); 1278 prev[1] = getTabViewer().getRevertButton().isEnabled(); 1279 for(int i = 0; i < children.length; i++) { 1280 prev[i+2] = children[i].isEnabled(); 1281 } 1282 try { 1283 updateRunnnableControls(false, prev); 1284 ModalContext.run(runnable, fork, fProgressMonitorPart, getShell().getDisplay()); 1285 } 1286 finally { 1287 fActiveRunningOperations--; 1288 updateRunnnableControls(true, prev); 1289 if (getShell() != null) { 1290 fProgressMonitorPart.getParent().setVisible(false); 1291 fProgressMonitorPart.removeFromCancelComponent(fProgressMonitorCancelButton); 1292 if (fLastControl != null) { 1293 fLastControl.setFocus(); 1294 } 1295 } 1296 } 1297 } 1298 else { 1299 PlatformUI.getWorkbench().getProgressService().run(fork, cancelable, runnable); 1300 } 1301 } 1302 1303 1310 private void updateRunnnableControls(boolean enabled, boolean[] prev) { 1311 getTabViewer().getApplyButton().setEnabled(enabled ? prev[0] : enabled); 1312 getTabViewer().getRevertButton().setEnabled(enabled ? prev[1] : enabled); 1313 Control[] children = ((Composite)fButtonComp.getChildren()[0]).getChildren(); 1315 for(int i = 0; i < children.length; i++) { 1316 children[i].setEnabled(enabled ? prev[i+2] : enabled); 1317 } 1318 getDialogArea().setEnabled(enabled); 1319 } 1320 1321 1324 public void setActiveTab(ILaunchConfigurationTab tab) { 1325 getTabViewer().setActiveTab(tab); 1326 } 1327 1328 1331 public void setActiveTab(int index) { 1332 getTabViewer().setActiveTab(index); 1333 } 1334 1335 1339 public void setInitialSelection(IStructuredSelection selection) { 1340 fInitialSelection = selection; 1341 } 1342 1343 1348 public void setInitialStatus(IStatus status) { 1349 fInitialStatus = status; 1350 } 1351 1352 1357 protected void setLaunchGroup(LaunchGroupExtension group) { 1358 fGroup = group; 1359 } 1360 1361 1364 protected void setModeLabelState() { 1365 setTitleImage(getBannerImage()); 1366 } 1367 1368 1371 public void setName(String name) { 1372 getTabViewer().setName(name); 1373 } 1374 1375 1379 protected ILaunchManager getLaunchManager() { 1380 return DebugPlugin.getDefault().getLaunchManager(); 1381 } 1382 1383 1387 public void setOpenMode(int mode) { 1388 fOpenMode = mode; 1389 } 1390 1391 1395 protected void setShellSize(int width, int height) { 1396 Rectangle bounds = getShell().getMonitor().getBounds(); 1397 getShell().setSize(Math.min(width, bounds.width), Math.min(height, bounds.height)); 1398 } 1399 1400 1405 protected void setTabViewer(LaunchConfigurationTabGroupViewer viewer) { 1406 fTabViewer = viewer; 1407 } 1408 1409 1417 private int showDiscardChangesDialog() { 1418 StringBuffer buffer = new StringBuffer (MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationDialog_The_configuration___35, new String []{getTabViewer().getWorkingCopy().getName()})); 1419 buffer.append(getTabViewer().getErrorMesssage()); 1420 buffer.append(LaunchConfigurationsMessages.LaunchConfigurationDialog_Do_you_wish_to_discard_changes_37); 1421 MessageDialog dialog = new MessageDialog(getShell(), 1422 LaunchConfigurationsMessages.LaunchConfigurationDialog_Discard_changes__38, 1423 null, 1424 buffer.toString(), 1425 MessageDialog.QUESTION, 1426 new String [] {LaunchConfigurationsMessages.LaunchConfigurationDialog_Yes_32, 1427 LaunchConfigurationsMessages.LaunchConfigurationDialog_No_33}, 1428 1); 1429 int val = IDialogConstants.NO_ID; 1430 if (dialog.open() == 0) { 1431 if (fLaunchConfigurationView != null) { 1432 fLaunchConfigurationView.setAutoSelect(false); 1433 } 1434 getTabViewer().handleRevertPressed(); 1435 val = IDialogConstants.YES_ID; 1436 if (fLaunchConfigurationView != null) { 1437 fLaunchConfigurationView.setAutoSelect(true); 1438 } 1439 } 1440 if(val == IDialogConstants.NO_ID) { 1441 val = ID_DISCARD_BUTTON; 1442 } 1443 return val; 1444 } 1445 1446 1454 private int showSaveChangesDialog() { 1455 String message = MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationDialog_The_configuration___29, new String []{getTabViewer().getWorkingCopy().getName()}); 1456 MessageDialog dialog = new MessageDialog(getShell(), 1457 LaunchConfigurationsMessages.LaunchConfigurationDialog_Save_changes__31, 1458 null, 1459 message, 1460 MessageDialog.QUESTION, 1461 new String [] {LaunchConfigurationsMessages.LaunchConfigurationDialog_Yes_32, 1462 LaunchConfigurationsMessages.LaunchConfigurationDialog_No_33, 1463 LaunchConfigurationsMessages.LaunchConfigurationsDialog_c_ancel}, 1464 0); 1465 int ret = dialog.open(); 1466 int val = IDialogConstants.CANCEL_ID; 1467 if (ret == 0 || ret == 1) { 1468 if (ret == 0) { 1469 val = IDialogConstants.YES_ID; 1470 } 1471 else { 1472 val = IDialogConstants.NO_ID; 1473 } 1474 } 1475 return val; 1476 } 1477 1478 1486 private int showUnsavedChangesDialog() { 1487 if (getTabViewer().canSave()) { 1488 return showSaveChangesDialog(); 1489 } 1490 return showDiscardChangesDialog(); 1491 } 1492 1493 1496 public void updateButtons() { 1497 getNewAction().setEnabled(getNewAction().isEnabled()); 1499 getDeleteAction().setEnabled(getDeleteAction().isEnabled()); 1500 getDuplicateAction().setEnabled(getDuplicateAction().isEnabled()); 1501 getTabViewer().refresh(); 1502 getButton(ID_LAUNCH_BUTTON).setEnabled(getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates()); 1503 } 1504 1505 1508 public void updateMessage() { 1509 setErrorMessage(getTabViewer().getErrorMesssage()); 1510 setMessage(getTabViewer().getMessage()); 1511 } 1512 1513 1518 public boolean isTreeSelectionEmpty() { 1519 return fLaunchConfigurationView.getTreeViewer().getSelection().isEmpty(); 1520 } 1521 1522 1525 public void propertyChange(final PropertyChangeEvent event) { 1526 WorkbenchJob job = new WorkbenchJob(EMPTY_STRING) { 1527 public IStatus runInUIThread(IProgressMonitor monitor) { 1528 TreeViewer viewer = fLaunchConfigurationView.getTreeViewer(); 1529 boolean newvalue = Boolean.valueOf(event.getNewValue().toString()).booleanValue(); 1530 if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED)) { 1531 updateFilter(newvalue, fClosedProjectFilter); 1532 } 1533 else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED)) { 1534 updateFilter(newvalue, fDeletedProjectFilter); 1535 } 1536 else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) { 1537 updateFilter(newvalue, fLCTFilter); 1538 } 1539 else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS)) { 1540 updateFilter(newvalue, fWorkingSetsFilter); 1541 } 1542 else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST)) { 1543 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) { 1544 viewer.refresh(); 1545 fLaunchConfigurationView.updateFilterLabel(); 1546 } 1547 } 1548 1549 return Status.OK_STATUS; 1550 } 1551 }; 1552 job.runInUIThread(new NullProgressMonitor()); 1553 } 1554 1555 1560 private void updateFilter(boolean state, ViewerFilter filter) { 1561 TreeViewer viewer = (TreeViewer)fLaunchConfigurationView.getViewer(); 1562 if(state) { 1563 viewer.addFilter(filter); 1564 } 1565 else { 1566 viewer.removeFilter(filter); 1567 } 1568 fLaunchConfigurationView.updateFilterLabel(); 1569 } 1570} 1571 | Popular Tags |