1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import java.io.IOException ; 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import javax.xml.parsers.ParserConfigurationException ; 24 import javax.xml.transform.TransformerException ; 25 26 import org.eclipse.core.commands.contexts.Context; 27 import org.eclipse.core.resources.ISaveContext; 28 import org.eclipse.core.resources.ISaveParticipant; 29 import org.eclipse.core.runtime.CoreException; 30 import org.eclipse.core.runtime.jobs.Job; 31 import org.eclipse.debug.core.DebugPlugin; 32 import org.eclipse.debug.core.ILaunch; 33 import org.eclipse.debug.core.ILaunchConfiguration; 34 import org.eclipse.debug.core.ILaunchConfigurationType; 35 import org.eclipse.debug.core.ILaunchDelegate; 36 import org.eclipse.debug.core.ILaunchListener; 37 import org.eclipse.debug.core.ILaunchManager; 38 import org.eclipse.debug.internal.core.IConfigurationElementConstants; 39 import org.eclipse.debug.internal.core.LaunchManager; 40 import org.eclipse.debug.internal.ui.DebugUIPlugin; 41 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 42 import org.eclipse.debug.internal.ui.views.ViewContextManager; 43 import org.eclipse.debug.internal.ui.views.ViewContextService; 44 import org.eclipse.debug.ui.IDebugUIConstants; 45 import org.eclipse.debug.ui.contexts.ISuspendTrigger; 46 import org.eclipse.debug.ui.contexts.ISuspendTriggerListener; 47 import org.eclipse.jface.dialogs.IDialogConstants; 48 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 49 import org.eclipse.swt.widgets.Display; 50 import org.eclipse.swt.widgets.Shell; 51 import org.eclipse.ui.IPerspectiveDescriptor; 52 import org.eclipse.ui.IWorkbenchPage; 53 import org.eclipse.ui.IWorkbenchWindow; 54 import org.eclipse.ui.PlatformUI; 55 import org.eclipse.ui.WorkbenchException; 56 import org.eclipse.ui.contexts.IContextActivation; 57 import org.eclipse.ui.contexts.IContextService; 58 import org.w3c.dom.Document ; 59 import org.w3c.dom.Element ; 60 import org.w3c.dom.Node ; 61 import org.w3c.dom.NodeList ; 62 63 import com.ibm.icu.text.MessageFormat; 64 65 84 public class PerspectiveManager implements ILaunchListener, ISuspendTriggerListener, ISaveParticipant { 85 86 91 public class PerspectiveSwitchLock { 92 93 private int fSwitch = 0; 94 private List fJobs = new ArrayList (); 95 96 public synchronized void startSwitch() { 97 fSwitch++; 98 } 99 100 public synchronized void endSwitch() { 101 fSwitch--; 102 if (fSwitch == 0) { 103 Iterator jobs = fJobs.iterator(); 104 while (jobs.hasNext()) { 105 ((Job)jobs.next()).schedule(); 106 } 107 fJobs.clear(); 108 } 109 } 110 111 public synchronized void schedulePostSwitch(Job job) { 112 if (fSwitch > 0) { 113 fJobs.add(job); 114 } 115 else { 116 job.schedule(); 117 } 118 } 119 } 120 121 127 class PerspectiveContext { 128 129 private ILaunchConfigurationType fType = null; 130 private ILaunchDelegate fDelegate = null; 131 private Map fPerspectives = null; 132 133 139 public PerspectiveContext(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes) { 140 fType = type; 141 fDelegate = delegate; 142 fPerspectives = new HashMap (); 143 fPerspectives.put(modes, null); 144 } 145 146 154 public boolean equals(Object object) { 155 ILaunchDelegate delegate = null; 156 ILaunchConfigurationType type = null; 157 if(object instanceof ILaunch) { 158 try { 159 ILaunch launch = (ILaunch) object; 160 type = launch.getLaunchConfiguration().getType(); 161 delegate = resolveLaunchDelegate(launch); 162 } 163 catch (CoreException e) {return false;} 164 } 165 else if(object instanceof PerspectiveContext) { 166 PerspectiveContext context = (PerspectiveContext) object; 167 type = context.getLaunchConfigurationType(); 168 delegate = context.getLaunchDelegate(); 169 } 170 if(fType != null && type != null && fType.getIdentifier().equals(type.getIdentifier())) { 171 if(fDelegate == null) { 172 return delegate == null; 173 } 174 else { 175 return fDelegate.equals(delegate); 176 } 177 } 178 return super.equals(object); 179 } 180 181 public ILaunchConfigurationType getLaunchConfigurationType() {return fType;} 182 public ILaunchDelegate getLaunchDelegate() {return fDelegate;} 183 public Map getPersepctiveMap() {return fPerspectives;} 184 185 191 public void setPerspective(Set modes, String pid) { 192 if(fPerspectives == null) { 193 fPerspectives = new HashMap (); 194 } 195 fPerspectives.put(modes, pid); 196 } 197 198 204 public String getPerspective(Set modes) { 205 if(fPerspectives != null) { 206 return (String ) fPerspectives.get(modes); 207 } 208 return null; 209 } 210 } 211 212 217 private Set fPerspectiveContexts = null; 218 219 224 public static final String ATTR_DELEGATE_ID = "delegate"; 226 231 private boolean fPrompting; 232 233 236 private PerspectiveSwitchLock fPerspectiveSwitchLock = new PerspectiveSwitchLock(); 237 238 242 private Map fLaunchToContextActivations = new HashMap (); 243 244 249 public void startup() { 250 DebugUIPlugin.getDefault().addSaveParticipant(this); 251 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 252 initPerspectives(); 253 } 254 255 260 public void shutdown() { 261 DebugUIPlugin.getDefault().removeSaveParticipant(this); 262 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); 263 } 264 265 270 public synchronized void launchRemoved(final ILaunch launch) { 271 ISuspendTrigger trigger = (ISuspendTrigger) launch.getAdapter(ISuspendTrigger.class); 272 if (trigger != null) { 273 trigger.removeSuspendTriggerListener(this); 274 } 275 Runnable r= new Runnable () { 276 public void run() { 277 IContextActivation[] activations = (IContextActivation[]) fLaunchToContextActivations.remove(launch); 278 if (activations != null) { 279 for (int i = 0; i < activations.length; i++) { 280 IContextActivation activation = activations[i]; 281 activation.getContextService().deactivateContext(activation); 282 } 283 } 284 } 285 }; 286 async(r); 287 } 288 289 294 public void launchChanged(ILaunch launch) {} 295 296 302 public synchronized void launchAdded(ILaunch launch) { 303 ISuspendTrigger trigger = (ISuspendTrigger) launch.getAdapter(ISuspendTrigger.class); 304 if (trigger != null) { 305 trigger.addSuspendTriggerListener(this); 306 } 307 fPerspectiveSwitchLock.startSwitch(); 308 String perspectiveId = null; 309 try { 311 perspectiveId = getPerspectiveId(launch); 312 } 313 catch (CoreException e) { 314 String name = DebugUIPlugin.getModelPresentation().getText(launch); 315 switchFailed(e, name); 316 } 317 ILaunchConfiguration configuration = launch.getLaunchConfiguration(); 319 if (configuration != null) { 320 if (!LaunchConfigurationManager.isVisible(configuration)) { 321 perspectiveId = null; 322 } 323 } 324 final String id = perspectiveId; 325 async(new Runnable () { 327 public void run() { 328 try { 329 IWorkbenchWindow window = getWindowForPerspective(id); 330 if (id != null && window != null && shouldSwitchPerspective(window, id, IInternalDebugUIConstants.PREF_SWITCH_TO_PERSPECTIVE)) { 331 switchToPerspective(window, id); 332 } 333 } 334 finally { 335 fPerspectiveSwitchLock.endSwitch(); 336 } 337 } 338 }); 339 } 340 341 342 347 protected void switchToPerspective(IWorkbenchWindow window, String id) { 348 try { 349 window.getWorkbench().showPerspective(id, window); 350 } catch (WorkbenchException e) { 351 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), 352 LaunchConfigurationsMessages.PerspectiveManager_Error_1, 353 MessageFormat.format(LaunchConfigurationsMessages.PerspectiveManager_Unable_to_switch_to_perspective___0__2, new String []{id}), 354 e); 355 } 356 } 357 358 361 protected void async(Runnable r) { 362 Display d = DebugUIPlugin.getStandardDisplay(); 363 if (d != null && !d.isDisposed()) { 364 d.asyncExec(r); 365 } 366 } 367 368 371 protected void sync(Runnable r) { 372 Display d = DebugUIPlugin.getStandardDisplay(); 373 if (d != null && !d.isDisposed()) { 374 d.syncExec(r); 375 } 376 } 377 378 385 protected void switchFailed(final Throwable t, final String launchName) { 386 sync(new Runnable () { 387 public void run() { 388 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), LaunchConfigurationsMessages.PerspectiveManager_Error_1, 389 MessageFormat.format(LaunchConfigurationsMessages.PerspectiveManager_Unable_to_switch_perpsectives_as_specified_by_launch___0__4, new String [] {launchName}), 390 t); 391 }}); 392 } 393 394 400 private void handleBreakpointHit(final ILaunch launch) { 401 402 fPerspectiveSwitchLock.startSwitch(); 409 410 String perspectiveId = null; 411 try { 412 perspectiveId = getPerspectiveId(launch); 413 } 414 catch (CoreException e) {DebugUIPlugin.log(e);} 415 418 final String targetId = perspectiveId; 421 Runnable r = new Runnable () { 422 public void run() { 423 IWorkbenchWindow window = null; 424 try{ 425 if (targetId != null) { 426 window = getWindowForPerspective(targetId); 428 if (window == null) { 429 return; 430 } 431 432 if (shouldSwitchPerspective(window, targetId, IInternalDebugUIConstants.PREF_SWITCH_PERSPECTIVE_ON_SUSPEND)) { 434 switchToPerspective(window, targetId); 435 window = getWindowForPerspective(targetId); 436 if (window == null) { 437 return; 438 } 439 } 440 441 Shell shell= window.getShell(); 443 if (shell != null) { 444 if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) { 445 if (shell.getMinimized()) { 446 shell.setMinimized(false); 447 } 448 shell.forceActive(); 449 } 450 } 451 452 Object ca = fLaunchToContextActivations.get(launch); 454 if (ca == null) { 455 ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration(); 456 if (launchConfiguration != null) { 457 try { 458 String type = launchConfiguration.getType().getIdentifier(); 459 ViewContextService service = ViewContextManager.getDefault().getService(window); 460 if (service != null) { 461 IContextService contextServce = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class); 462 String [] ids = service.getEnabledPerspectives(); 463 IContextActivation[] activations = new IContextActivation[ids.length]; 464 for (int i = 0; i < ids.length; i++) { 465 Context context = contextServce.getContext(type + ".internal." + ids[i]); if (!context.isDefined()) { 468 context.define(context.getId(), null, null); 469 } 470 IContextActivation activation = contextServce.activateContext(context.getId()); 471 activations[i] = activation; 472 } 473 fLaunchToContextActivations.put(launch, activations); 474 } 475 } catch (CoreException e) { 476 DebugUIPlugin.log(e); 477 } 478 } 479 } 480 481 } 482 if (window != null && DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW)) { 483 ViewContextService service = ViewContextManager.getDefault().getService(window); 484 service.showViewQuiet(IDebugUIConstants.ID_DEBUG_VIEW); 485 } 486 } 487 finally 488 { 489 fPerspectiveSwitchLock.endSwitch(); 490 } 491 } 492 }; 493 async(r); 494 } 495 496 505 private IWorkbenchWindow getWindowForPerspective(String perspectiveId) { 506 IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); 507 if (isWindowShowingPerspective(window, perspectiveId)) { 508 return window; 509 } 510 IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); 511 for (int i = 0; i < windows.length; i++) { 512 window = windows[i]; 513 if (isWindowShowingPerspective(window, perspectiveId)) { 514 return window; 515 } 516 } 517 window = DebugUIPlugin.getActiveWorkbenchWindow(); 518 if (window != null) { 519 return window; 520 } 521 if (windows.length > 0) { 522 return windows[0]; 523 } 524 return null; 525 } 526 527 533 private boolean isWindowShowingPerspective(IWorkbenchWindow window, String perspectiveId) { 534 if (window != null) { 535 IWorkbenchPage page = window.getActivePage(); 536 if (page != null) { 537 IPerspectiveDescriptor perspectiveDescriptor = page.getPerspective(); 538 if (perspectiveDescriptor != null && perspectiveDescriptor.getId().equals(perspectiveId)) { 539 return true; 540 } 541 } 542 } 543 return false; 544 } 545 546 559 private boolean shouldSwitchPerspective(IWorkbenchWindow window, String perspectiveId, String preferenceKey) { 560 if (isCurrentPerspective(window, perspectiveId)) { 561 return false; 562 } 563 String perspectiveName = getPerspectiveLabel(perspectiveId); 564 if (perspectiveName == null) { 565 return false; 566 } 567 String perspectiveDesc = getPerspectiveDescription(perspectiveId); 568 String [] args; 569 if (perspectiveDesc != null) { 570 args = new String [] { perspectiveName , perspectiveDesc }; 571 } 572 else { 573 args = new String [] { perspectiveName }; 574 } 575 String switchPerspective = DebugUIPlugin.getDefault().getPreferenceStore().getString(preferenceKey); 576 if (MessageDialogWithToggle.ALWAYS.equals(switchPerspective)) { 577 return true; 578 } else if (MessageDialogWithToggle.NEVER.equals(switchPerspective)) { 579 return false; 580 } 581 582 Shell shell= window.getShell(); 583 if (shell == null || fPrompting) { 584 return false; 585 } 586 fPrompting= true; 587 if (shell.getMinimized()) { 589 shell.setMinimized(false); 590 } 591 if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) { 592 shell.forceActive(); 593 } 594 String message = ""; if(IInternalDebugUIConstants.PREF_SWITCH_PERSPECTIVE_ON_SUSPEND.equals(preferenceKey)) { 596 if (getPerspectiveDescription(perspectiveId) != null) { 597 message = LaunchConfigurationsMessages.PerspectiveManager_suspend_description; 598 } 599 else { 600 message = LaunchConfigurationsMessages.PerspectiveManager_13; 601 } 602 } 603 else if(IInternalDebugUIConstants.PREF_SWITCH_TO_PERSPECTIVE.equals(preferenceKey)) { 604 if (getPerspectiveDescription(perspectiveId) != null) { 605 message = LaunchConfigurationsMessages.PerspectiveManager_launch_description; 606 } 607 else { 608 message = LaunchConfigurationsMessages.PerspectiveManager_15; 609 } 610 } 611 MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, LaunchConfigurationsMessages.PerspectiveManager_12, MessageFormat.format(message, args), null, false, DebugUIPlugin.getDefault().getPreferenceStore(), preferenceKey); 612 boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID); 613 synchronized (this) { 614 fPrompting= false; 615 notifyAll(); 616 } 617 if (isCurrentPerspective(window, perspectiveId)) { 618 answer = false; 619 } 620 return answer; 621 } 622 623 631 protected boolean isCurrentPerspective(IWorkbenchWindow window, String perspectiveId) { 632 boolean isCurrent= false; 633 if (window != null) { 634 IWorkbenchPage page = window.getActivePage(); 635 if (page != null) { 636 IPerspectiveDescriptor perspectiveDescriptor = page.getPerspective(); 637 if (perspectiveDescriptor != null) { 638 isCurrent= perspectiveId.equals(perspectiveDescriptor.getId()); 639 } 640 } 641 } 642 return isCurrent; 643 } 644 645 653 protected String getPerspectiveLabel(String perspectiveId) { 654 IPerspectiveDescriptor newPerspective = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(perspectiveId); 655 if (newPerspective == null) { 656 return null; 657 } 658 return newPerspective.getLabel(); 659 } 660 661 662 670 protected String getPerspectiveDescription(String perspectiveId) { 671 IPerspectiveDescriptor newPerspective = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(perspectiveId); 672 if (newPerspective == null) { 673 return null; 674 } 675 return newPerspective.getDescription(); 676 } 677 678 688 protected String getPerspectiveId(ILaunch launch) throws CoreException { 689 if (launch == null) { 690 return null; 691 } 692 ILaunchConfiguration config = launch.getLaunchConfiguration(); 693 if (config == null) { 694 return null; 695 } 696 Set modes = launch.getLaunchConfiguration().getModes(); 697 modes.add(launch.getLaunchMode()); 698 String perspectiveId = getLaunchPerspective(config.getType(), modes, resolveLaunchDelegate(launch)); 699 if (perspectiveId != null && perspectiveId.equals(IDebugUIConstants.PERSPECTIVE_NONE)) { 700 perspectiveId = null; 701 } 702 return perspectiveId; 703 } 704 705 715 public String getLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate) { 716 String id = null; 717 PerspectiveContext context = findContext(new PerspectiveContext(type, delegate, modes)); 718 if(context == null || (context != null && !context.getPersepctiveMap().containsKey(modes))) { 719 context = findContext(new PerspectiveContext(type, null, modes)); 721 if(context == null || (context != null && !context.getPersepctiveMap().containsKey(modes))) { 722 return getDefaultLaunchPerspective(type, delegate, modes); 724 } 725 } 726 if(context != null) { 727 id = context.getPerspective(modes); 728 } 729 return id; 730 } 731 732 745 public String getLaunchPerspective(ILaunchConfigurationType type, String mode) { 746 HashSet modes = new HashSet (); 747 modes.add(mode); 748 return getLaunchPerspective(type, modes, null); 749 } 750 751 767 public void setLaunchPerspective(ILaunchConfigurationType type, String mode, String perspective) { 768 HashSet modes = new HashSet (); 769 modes.add(mode); 770 setLaunchPerspective(type, modes, null, perspective); 771 } 772 773 786 public void setLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate, String perspectiveid) { 787 PerspectiveContext context = new PerspectiveContext(type, delegate, modes); 788 String id = null; 789 if(!IDebugUIConstants.PERSPECTIVE_NONE.equals(perspectiveid)) { 790 if(IDebugUIConstants.PERSPECTIVE_DEFAULT.equals(perspectiveid)) { 791 id = getDefaultLaunchPerspective(type, delegate, modes); 792 } 793 else { 794 id = perspectiveid; 795 } 796 } 797 PerspectiveContext item = findContext(context); 798 if(item != null) { 799 item.setPerspective(modes, id); 800 } 801 else { 802 context.setPerspective(modes, id); 803 item = context; 804 } 805 fPerspectiveContexts.add(item); 806 } 807 808 815 private PerspectiveContext findContext(PerspectiveContext context) { 816 PerspectiveContext item = null; 817 Object o = null; 818 for(Iterator iter = fPerspectiveContexts.iterator(); iter.hasNext();) { 819 o = iter.next(); 820 if(context.equals(o)) { 821 item = (PerspectiveContext) o; 822 return item; 823 } 824 } 825 return item; 826 } 827 828 836 private String generatePerspectiveXML() throws ParserConfigurationException , TransformerException , IOException { 837 Document doc = DebugUIPlugin.getDocument(); 838 Element root = doc.createElement(IConfigurationElementConstants.LAUNCH_PERSPECTIVES); 839 doc.appendChild(root); 840 PerspectiveContext context = null; 841 Map modesets = null; 842 Element element = null; 843 Set modes = null; 844 String id = null; 845 ILaunchDelegate delegate = null; 846 for(Iterator iter = fPerspectiveContexts.iterator(); iter.hasNext();) { 847 context = (PerspectiveContext) iter.next(); 848 modesets = context.getPersepctiveMap(); 849 for(Iterator iter2 = modesets.keySet().iterator(); iter2.hasNext();) { 850 modes = (Set ) iter2.next(); 851 id = context.getPerspective(modes); 852 if(id != null) { 853 element = doc.createElement(IConfigurationElementConstants.LAUNCH_PERSPECTIVE); 854 element.setAttribute(IConfigurationElementConstants.MODE, createModesetString(modes)); 855 delegate = context.getLaunchDelegate(); 856 if(delegate != null) { 857 element.setAttribute(ATTR_DELEGATE_ID, delegate.getId()); 858 } 859 element.setAttribute(IConfigurationElementConstants.CONFIGURATION_TYPES, context.getLaunchConfigurationType().getIdentifier()); 860 element.setAttribute(IConfigurationElementConstants.PERSPECTIVE, id); 861 root.appendChild(element); 862 } 863 } 864 865 } 866 return DebugUIPlugin.serializeDocument(doc); 867 } 868 869 882 public String getDefaultLaunchPerspective(ILaunchConfigurationType type, String mode) { 883 HashSet modes = new HashSet (); 884 modes.add(mode); 885 return getDefaultLaunchPerspective(type, null, modes); 886 } 887 888 898 public String getDefaultLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes) { 899 String id = null; 900 if(delegate != null) { 901 id = delegate.getPerspectiveId(modes); 902 } 903 if(id == null) { 904 LaunchConfigurationTabGroupExtension extension = LaunchConfigurationPresentationManager.getDefault().getExtension(type.getIdentifier(), modes); 905 if (extension != null) { 906 id = extension.getPerspective(modes); 907 if (id == null) { 908 if (modes.contains(ILaunchManager.DEBUG_MODE)) { 909 id = IDebugUIConstants.ID_DEBUG_PERSPECTIVE; 910 } 911 } 912 } 913 } 914 return id; 915 } 916 917 923 private ILaunchDelegate resolveLaunchDelegate(ILaunch launch) throws CoreException { 924 Set modes = launch.getLaunchConfiguration().getModes(); 925 modes.add(launch.getLaunchMode()); 926 ILaunchConfigurationType type = launch.getLaunchConfiguration().getType(); 927 ILaunchDelegate[] delegates = LaunchConfigurationManager.filterLaunchDelegates(type, modes); 928 ILaunchDelegate delegate = null; 929 if(delegates.length == 1) { 930 delegate = delegates[0]; 931 } 932 else if(delegates.length > 1) { 933 delegate = launch.getLaunchConfiguration().getPreferredDelegate(modes); 934 if(delegate == null) { 935 delegate = type.getPreferredDelegate(modes); 936 } 937 } 938 return delegate; 939 } 940 941 944 private void initPerspectives() { 945 if(fPerspectiveContexts == null) { 946 fPerspectiveContexts = new HashSet (); 947 String xml = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_LAUNCH_PERSPECTIVES); 948 if (xml != null && xml.length() > 0) { 949 try { 950 Element root = DebugPlugin.parseDocument(xml); 951 NodeList list = root.getChildNodes(); 952 LaunchManager lm = (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); 953 ILaunchConfigurationType lctype = null; 954 ILaunchDelegate ldelegate = null; 955 Set modes = null; 956 Node node = null; 957 Element element = null; 958 for (int i = 0; i < list.getLength(); ++i) { 959 node = list.item(i); 960 if (node.getNodeType() == Node.ELEMENT_NODE) { 961 element = (Element ) node; 962 String nodeName = element.getNodeName(); 963 if (nodeName.equalsIgnoreCase(IConfigurationElementConstants.LAUNCH_PERSPECTIVE)) { 964 String type = element.getAttribute(IConfigurationElementConstants.CONFIGURATION_TYPES); 965 String mode = element.getAttribute(IConfigurationElementConstants.MODE); 966 String perspective = element.getAttribute(IConfigurationElementConstants.PERSPECTIVE); 967 String delegate = element.getAttribute(ATTR_DELEGATE_ID); 968 lctype = lm.getLaunchConfigurationType(type); 969 ldelegate = lm.getLaunchDelegate(delegate); 970 modes = parseModes(mode); 971 if(lctype != null && !modes.isEmpty() && !"".equals(perspective)) { setLaunchPerspective(lctype, modes, ldelegate, perspective); 973 } 974 } 975 } 976 } 977 } 978 catch (CoreException e) {DebugUIPlugin.log(e);} 979 } 980 } 981 } 982 983 990 private Set parseModes(String modes) { 991 HashSet modeset = new HashSet (); 992 String [] ms = modes.split(","); for(int i = 0; i < ms.length; i++) { 994 modeset.add(ms[i].trim()); 995 } 996 return modeset; 997 } 998 999 1004 private String createModesetString(Set modes) { 1005 String str = ""; if(modes != null) { 1007 for(Iterator iter = modes.iterator(); iter.hasNext();) { 1008 str += iter.next(); 1009 if(iter.hasNext()) { 1010 str += ","; } 1012 } 1013 } 1014 return str; 1015 } 1016 1017 1023 public void schedulePostSwitch(Job job) { 1024 fPerspectiveSwitchLock.schedulePostSwitch(job); 1025 } 1026 1027 1030 public void suspended(ILaunch launch, Object context) { 1031 handleBreakpointHit(launch); 1032 } 1033 1034 1037 public void doneSaving(ISaveContext context) {} 1038 1039 1042 public void prepareToSave(ISaveContext context) throws CoreException {} 1043 1044 1047 public void rollback(ISaveContext context) {} 1048 1049 1052 public void saving(ISaveContext context) throws CoreException { 1053 try { 1054 DebugUIPlugin.getDefault().getPreferenceStore().putValue(IInternalDebugUIConstants.PREF_LAUNCH_PERSPECTIVES, generatePerspectiveXML()); 1055 } 1056 catch (IOException e) {DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception occurred while generating launch perspectives preference XML", e));} catch (ParserConfigurationException e) {DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception occurred while generating launch perspectives preference XML", e));} catch (TransformerException e) {DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception occurred while generating launch perspectives preference XML", e));} } 1060} 1061 | Popular Tags |