1 11 package org.eclipse.debug.internal.ui.views.launch; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.ListIterator ; 19 import java.util.Map ; 20 import java.util.Set ; 21 import java.util.StringTokenizer ; 22 import java.util.regex.Pattern ; 23 24 import org.eclipse.core.runtime.IAdaptable; 25 import org.eclipse.core.runtime.IConfigurationElement; 26 import org.eclipse.core.runtime.IExtensionPoint; 27 import org.eclipse.core.runtime.IProgressMonitor; 28 import org.eclipse.core.runtime.IStatus; 29 import org.eclipse.core.runtime.Platform; 30 import org.eclipse.core.runtime.Status; 31 import org.eclipse.debug.core.ILaunch; 32 import org.eclipse.debug.core.model.IDebugElement; 33 import org.eclipse.debug.core.model.IDebugModelProvider; 34 import org.eclipse.debug.core.model.IProcess; 35 import org.eclipse.debug.core.model.IStackFrame; 36 import org.eclipse.debug.internal.ui.DebugUIPlugin; 37 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 38 import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager; 39 import org.eclipse.debug.ui.DebugUITools; 40 import org.eclipse.debug.ui.IDebugUIConstants; 41 import org.eclipse.jface.preference.IPreferenceStore; 42 import org.eclipse.ui.IPerspectiveDescriptor; 43 import org.eclipse.ui.IViewPart; 44 import org.eclipse.ui.IViewReference; 45 import org.eclipse.ui.IWorkbench; 46 import org.eclipse.ui.IWorkbenchPage; 47 import org.eclipse.ui.IWorkbenchPartReference; 48 import org.eclipse.ui.PartInitException; 49 import org.eclipse.ui.PlatformUI; 50 import org.eclipse.ui.activities.ActivityManagerEvent; 51 import org.eclipse.ui.activities.IActivity; 52 import org.eclipse.ui.activities.IActivityManager; 53 import org.eclipse.ui.activities.IActivityManagerListener; 54 import org.eclipse.ui.activities.IActivityPatternBinding; 55 import org.eclipse.ui.activities.IWorkbenchActivitySupport; 56 import org.eclipse.ui.contexts.ContextManagerEvent; 57 import org.eclipse.ui.contexts.EnabledSubmission; 58 import org.eclipse.ui.contexts.IContext; 59 import org.eclipse.ui.contexts.IContextManager; 60 import org.eclipse.ui.contexts.IContextManagerListener; 61 import org.eclipse.ui.contexts.IWorkbenchContextSupport; 62 import org.eclipse.ui.contexts.NotDefinedException; 63 import org.eclipse.ui.progress.UIJob; 64 65 81 public class LaunchViewContextListener implements IContextManagerListener, IActivityManagerListener { 82 83 private static final String DEBUG_MODEL_ACTIVITY_SUFFIX = "/debugModel"; public static final String ID_CONTEXT_VIEW_BINDINGS= "contextViewBindings"; public static final String ID_DEBUG_MODEL_CONTEXT_BINDINGS= "debugModelContextBindings"; public static final String ATTR_CONTEXT_ID= "contextId"; public static final String ATTR_VIEW_ID= "viewId"; public static final String ATTR_DEBUG_MODEL_ID= "debugModelId"; public static final String ATTR_AUTO_OPEN= "autoOpen"; public static final String ATTR_AUTO_CLOSE= "autoClose"; 92 95 private LaunchView launchView; 96 100 private Map modelsToContexts= new HashMap (); 101 102 105 private List modelPatternBindings = new ArrayList (); 106 107 110 private Set enabledActivities; 111 112 116 private Map modelsToActivities= new HashMap (); 117 121 private Map contextViews= new HashMap (); 122 125 private Set managedViewIds= new HashSet (); 126 131 private Set viewIdsToNotOpen= new HashSet (); 132 140 private Map openedViewIds= new HashMap (); 141 142 148 private Map fContextSubmissions= new HashMap (); 149 public static final String DEBUG_CONTEXT= "org.eclipse.debug.ui.debugging"; 157 public static final String PREF_VIEWS_TO_NOT_OPEN= IDebugUIConstants.PLUGIN_ID + ".views_to_not_open"; 166 public static final String PREF_OPENED_VIEWS= IDebugUIConstants.PLUGIN_ID + ".opened_views"; 170 private List lastEnabledIds= new ArrayList (); 171 177 private boolean fIsTrackingPartChanges; 178 182 private List fAutoManagePerspectives= new ArrayList (); 183 184 189 public LaunchViewContextListener(LaunchView view) { 190 launchView= view; 191 loadTrackViews(); 192 loadDebugModelContextExtensions(); 193 loadDebugModelActivityExtensions(); 194 loadContextToViewExtensions(true); 195 loadOpenedViews(); 196 loadViewsToNotOpen(); 197 loadAutoManagePerspectives(); 198 IWorkbench workbench = PlatformUI.getWorkbench(); 199 workbench.getContextSupport().getContextManager().addContextManagerListener(this); 200 IActivityManager activityManager = workbench.getActivitySupport().getActivityManager(); 201 activityManager.addActivityManagerListener(this); 202 enabledActivities = activityManager.getEnabledActivityIds(); 203 } 204 205 209 private void loadContextToViewExtensions(boolean reloadContextMappings) { 210 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), ID_CONTEXT_VIEW_BINDINGS); 211 IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); 212 for (int i = 0; i < configurationElements.length; i++) { 213 IConfigurationElement element = configurationElements[i]; 214 String viewId = getViewId(element); 215 if (reloadContextMappings) { 216 String contextId = element.getAttribute(ATTR_CONTEXT_ID); 217 if (contextId == null || viewId == null) { 218 continue; 219 } 220 List elements= (List ) contextViews.get(contextId); 221 if (elements == null) { 222 elements= new ArrayList (); 223 contextViews.put(contextId, elements); 224 } 225 elements.add(element); 226 } 227 managedViewIds.add(viewId); 228 } 229 } 230 231 241 private void loadDebugModelContextExtensions() { 242 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), ID_DEBUG_MODEL_CONTEXT_BINDINGS); 243 IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); 244 for (int i = 0; i < configurationElements.length; i++) { 245 IConfigurationElement element = configurationElements[i]; 246 String modelIdentifier = element.getAttribute(ATTR_DEBUG_MODEL_ID); 247 String contextId = element.getAttribute(ATTR_CONTEXT_ID); 248 if (modelIdentifier != null && contextId != null) { 249 List contextIds = (List ) modelsToContexts.get(modelIdentifier); 250 if (contextIds == null) { 251 contextIds = new ArrayList (); 252 modelsToContexts.put(modelIdentifier, contextIds); 253 } 254 contextIds.add(contextId); 255 } 256 } 257 } 258 259 264 private void loadDebugModelActivityExtensions() { 265 IActivityManager activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager(); 266 Set activityIds = activityManager.getDefinedActivityIds(); 267 Iterator activityIterator = activityIds.iterator(); 268 while (activityIterator.hasNext()) { 269 String activityId= (String ) activityIterator.next(); 270 IActivity activity = activityManager.getActivity(activityId); 271 if (activity != null) { 272 Set patternBindings = activity.getActivityPatternBindings(); 273 Iterator patternIterator= patternBindings.iterator(); 274 while (patternIterator.hasNext()) { 275 IActivityPatternBinding patternBinding= (IActivityPatternBinding) patternIterator.next(); 276 String pattern = patternBinding.getPattern().pattern(); 277 if (pattern.endsWith(DEBUG_MODEL_ACTIVITY_SUFFIX)) { 278 modelPatternBindings.add(patternBinding); 279 } 280 } 281 } 282 } 283 } 284 285 297 private List getConfigurationElements(String contextId) { 298 List configuredViewIds= new ArrayList (); 301 List allConfigurationElements= new ArrayList (); 302 IContextManager contextManager = PlatformUI.getWorkbench().getContextSupport().getContextManager(); 303 while (contextId != null) { 304 List configurationElements= (List ) contextViews.get(contextId); 305 if (configurationElements != null) { 306 ListIterator iter= configurationElements.listIterator(); 307 while (iter.hasNext()) { 308 IConfigurationElement element= (IConfigurationElement) iter.next(); 313 String viewId = element.getAttribute(ATTR_VIEW_ID); 314 if (viewId != null) { 315 if (!configuredViewIds.contains(viewId)) { 316 allConfigurationElements.add(element); 317 } 318 configuredViewIds.add(viewId); 319 } 320 } 321 } 322 IContext context = contextManager.getContext(contextId); 323 if (context != null) { 324 try { 325 contextId= context.getParentId(); 326 } catch (NotDefinedException e) { 327 contextId= null; 328 } 329 } 330 } 331 return allConfigurationElements; 332 } 333 334 337 private void saveViewsToNotOpen() { 338 saveViewCollection(LaunchViewContextListener.PREF_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen); 339 } 340 341 345 private void saveOpenedViews() { 346 saveViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds); 347 } 348 349 357 public void saveViewCollection(String attribute, Set collection) { 358 StringBuffer views= new StringBuffer (); 359 Iterator iter= collection.iterator(); 360 while (iter.hasNext()) { 361 views.append((String ) iter.next()).append(','); 362 } 363 if (views.length() > 0) { 364 IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore(); 365 preferenceStore.removePropertyChangeListener(launchView); 366 preferenceStore.setValue(attribute, views.toString()); 367 preferenceStore.addPropertyChangeListener(launchView); 368 } 369 } 370 371 372 389 private void saveViewMap(String attribute, Map map) { 390 StringBuffer views= new StringBuffer (); 391 Iterator iter= map.keySet().iterator(); 392 while (iter.hasNext()) { 393 String perspId = (String ) iter.next(); 394 Set viewIds = (Set )map.get(perspId); 395 views.append("/"); views.append(perspId); 397 if (viewIds != null && !viewIds.isEmpty()) 398 { 399 views.append(":"); Iterator viewsIter = viewIds.iterator(); 401 while (viewsIter.hasNext()) 402 { 403 String viewId = (String )viewsIter.next(); 404 views.append(viewId); 405 views.append(","); } 407 } 408 } 409 if (views.length() > 0) { 410 IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore(); 411 preferenceStore.removePropertyChangeListener(launchView); 412 preferenceStore.setValue(attribute, views.toString()); 413 preferenceStore.addPropertyChangeListener(launchView); 414 } 415 } 416 417 420 public void loadViewsToNotOpen() { 421 loadViewCollection(LaunchViewContextListener.PREF_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen); 422 } 423 424 428 public void loadOpenedViews() { 429 loadViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds); 430 } 431 432 439 public void loadViewCollection(String attribute, Set collection) { 440 collection.clear(); 441 String views = DebugUITools.getPreferenceStore().getString(attribute); 442 int startIndex= 0; 443 int endIndex= views.indexOf(','); 444 if (endIndex == -1) { 445 endIndex= views.length(); 446 } 447 while (startIndex < views.length() - 1) { 448 String viewId= views.substring(startIndex, endIndex); 449 if (viewId.length() > 0) { 450 collection.add(viewId); 451 } 452 startIndex= endIndex + 1; 453 endIndex= views.indexOf(',', startIndex); 454 } 455 } 456 457 470 private void loadViewMap(String attribute, Map map) { 471 map.clear(); 472 String views = DebugUITools.getPreferenceStore().getString(attribute); 473 474 if (views.startsWith("/")) { 476 String [] viewsStr = views.split("/"); 480 for (int i=0; i<viewsStr.length; i++) 481 { 482 if (viewsStr[i].length() == 0) 483 continue; 484 485 String [] data = viewsStr[i].split(":"); 488 491 if (data.length == 2) 492 { 493 String perspId = data[0]; 494 495 String [] viewIds = data[1].split(","); Set list = new HashSet (); 497 for (int j=0; j<viewIds.length; j++) 498 { 499 list.add(viewIds[j]); 500 } 501 502 openedViewIds.put(perspId, list); 503 } 504 } 505 } 506 } 507 508 511 public void contextManagerChanged(ContextManagerEvent contextManagerEvent) { 512 Set enabled = getNewlyEnabledContexts(contextManagerEvent); 513 Set disabled = getNewlyDisabledContexts(contextManagerEvent); 514 contextEnabled(enabled); 515 contextsDisabled(disabled); 516 } 517 518 private Set getNewlyEnabledContexts(ContextManagerEvent contextManagerEvent) { 519 Set set = new HashSet (contextManagerEvent.getContextManager().getEnabledContextIds()); 520 set.removeAll(contextManagerEvent.getPreviouslyEnabledContextIds()); 521 return set; 522 } 523 524 private Set getNewlyDisabledContexts(ContextManagerEvent contextManagerEvent) { 525 Set set = new HashSet (contextManagerEvent.getPreviouslyEnabledContextIds()); 526 set.removeAll(contextManagerEvent.getContextManager().getEnabledContextIds()); 527 return set; 528 } 529 530 537 public void contextEnabled(final Set contextIds) { 538 if (!isAutoManageViews()) { 539 return; 540 } 541 542 final UIJob openViewsJob = new UIJob("Open Context-Enabled Views") { public IStatus runInUIThread(IProgressMonitor monitor) { 544 IWorkbenchPage page = getPage(); 545 if (page == null) 546 return Status.OK_STATUS; 547 548 if (page.getPerspective() == null) 552 return Status.OK_STATUS; 553 554 contextIds.remove(DEBUG_CONTEXT); 560 if (page == null || contextIds.size() == 0) { 561 return Status.OK_STATUS; 562 } 563 Set viewsToShow = new HashSet (); 564 Set viewsToOpen = new HashSet (); 565 computeViewActivation(contextIds, viewsToOpen, viewsToShow); 566 567 boolean resetTrackingPartChanges = false; 568 if (fIsTrackingPartChanges) { 569 fIsTrackingPartChanges = false; 572 resetTrackingPartChanges = true; 573 } 574 575 Iterator iterator = viewsToOpen.iterator(); 576 577 String id = page.getPerspective().getId(); 578 Set views = (Set ) openedViewIds.get(id); 579 if (views == null) { 580 views = new HashSet (); 581 } 582 583 while (iterator.hasNext()) { 584 String viewId = (String ) iterator.next(); 585 try { 586 IViewPart view = page.showView(viewId, null, 587 IWorkbenchPage.VIEW_CREATE); 588 views.add(viewId); 589 590 viewsToShow.add(view); 591 } catch (PartInitException e) { 592 DebugUIPlugin.log(e.getStatus()); 593 } 594 } 595 596 if (!viewsToOpen.isEmpty()) { 597 openedViewIds.put(id, views); 598 saveOpenedViews(); 599 } 600 iterator = viewsToShow.iterator(); 601 while (iterator.hasNext()) { 602 boolean activate = true; 603 IViewPart view = (IViewPart) iterator.next(); 604 IViewPart[] stackedViews = page.getViewStack(view); 605 if (stackedViews == null) { 606 continue; 607 } 608 for (int i = 0; i < stackedViews.length; i++) { 612 IViewPart stackedView = stackedViews[i]; 613 if (view == stackedView) { 614 break; 615 } else if (viewsToShow.contains(stackedView)) { 616 activate = false; 619 break; 620 } 621 } 622 if (activate) { 623 page.bringToTop(view); 624 } 625 } 626 627 if (resetTrackingPartChanges) 629 loadTrackViews(); 630 631 return Status.OK_STATUS; 632 } 633 }; 634 635 openViewsJob.setSystem(true); 636 637 final PerspectiveManager manager = DebugUIPlugin.getDefault().getPerspectiveManager(); 638 if (isBoundToViews(contextIds)) { 639 manager.schedulePostSwitch(openViewsJob); 640 } 641 } 642 643 648 private boolean isBoundToViews(Set contextIds) 649 { 650 Set possibleViewsToShow = new HashSet (); 651 Iterator iter = contextIds.iterator(); 652 while (iter.hasNext()) 653 { 654 String contextId = (String )iter.next(); 655 Set viewIds = getApplicableViewIds(contextId); 656 possibleViewsToShow.addAll(viewIds); 657 } 658 659 return !possibleViewsToShow.isEmpty(); 660 } 661 662 672 private void computeViewActivation(Set contextIds, Set viewIdsToOpen, Set viewIdsShow) { 673 IWorkbenchPage page = getPage(); 674 if (page == null) { 675 return; 676 } 677 Iterator contexts = contextIds.iterator(); 678 while (contexts.hasNext()) { 679 String contextId = (String ) contexts.next(); 680 Iterator configurationElements= getConfigurationElements(contextId).iterator(); 681 while (configurationElements.hasNext()) { 682 IConfigurationElement element = (IConfigurationElement) configurationElements.next(); 683 String viewId= getViewId(element); 684 if (viewId == null) { 685 continue; 686 } 687 IViewReference reference = page.findViewReference(viewId); 688 if (reference != null && reference.isFastView()) { 689 continue; 690 } 691 IViewPart view = page.findView(viewId); 692 if (view != null) { 693 viewIdsShow.add(view); 694 } else if (isAutoOpen(element) && !viewIdsToNotOpen.contains(viewId)) { 695 viewIdsToOpen.add(viewId); 697 } 698 } 699 } 700 } 701 702 709 public void contextsDisabled(Set contexts) { 710 IWorkbenchPage page= getPage(); 711 if (page == null || contexts.size() == 0 || !isAutoManageViews()) { 712 return; 713 } 714 Set viewsToClose= getViewIdsToClose(contexts); 715 if (viewsToClose.isEmpty()) { 716 return; 717 } 718 719 boolean resetTrackingPartChanges = false; 723 if (fIsTrackingPartChanges) 724 { 725 fIsTrackingPartChanges= false; 726 resetTrackingPartChanges = true; 727 } 728 Iterator iter= viewsToClose.iterator(); 729 730 String perspId = page.getPerspective().getId(); 731 Set viewIds = (Set )openedViewIds.get(perspId); 732 733 while (iter.hasNext()) { 734 String viewId= (String ) iter.next(); 735 IViewReference view = page.findViewReference(viewId); 736 if (view != null) { 737 page.hideView(view); 738 if (viewIds != null) 739 { 740 viewIds.remove(viewId); 742 } 743 } 744 } 745 saveOpenedViews(); 746 747 if (resetTrackingPartChanges) 749 loadTrackViews(); 750 } 751 752 760 public Set getViewIdsToClose(Set contextIds) { 761 Set viewIdsToClose= new HashSet (); 762 Set viewIdsToKeepOpen= getViewIdsForEnabledContexts(); 763 Iterator contexts = contextIds.iterator(); 764 IWorkbenchPage page = getPage(); 765 if (page == null) 766 return viewIdsToClose; 767 if (page.getPerspective() == null) 768 return viewIdsToClose; 769 String currentPerspId = page.getPerspective().getId(); 770 Set viewIds = (Set )openedViewIds.get(currentPerspId); 771 while (contexts.hasNext()) { 772 String contextId = (String ) contexts.next(); 773 List list = getConfigurationElements(contextId); 774 Iterator iter = list.iterator(); 775 while (iter.hasNext()) { 776 IConfigurationElement element = (IConfigurationElement) iter.next(); 777 if (!isAutoClose(element)) { 778 continue; 779 } 780 String viewId = getViewId(element); 781 782 if (viewId == null || viewIds == null || !viewIds.contains(viewId) || viewIdsToKeepOpen.contains(viewId)) { 783 continue; 786 } 787 viewIdsToClose.add(viewId); 788 } 789 } 790 return viewIdsToClose; 791 } 792 793 799 protected Set getViewIdsForEnabledContexts() { 800 Set viewIds= new HashSet (); 801 Iterator enabledContexts = PlatformUI.getWorkbench().getContextSupport().getContextManager().getEnabledContextIds().iterator(); 802 while (enabledContexts.hasNext()) { 803 String contextId = (String ) enabledContexts.next(); 804 if (contextId.equals(DEBUG_CONTEXT)) { 805 continue; 807 } 808 viewIds.addAll(getApplicableViewIds(contextId)); 809 } 810 return viewIds; 811 } 812 813 820 public Set getApplicableViewIds(String contextId) { 821 Set viewIds= new HashSet (); 822 Iterator elements = getConfigurationElements(contextId).iterator(); 823 while (elements.hasNext()) { 824 String viewId = getViewId((IConfigurationElement) elements.next()); 825 if (viewId != null) { 826 viewIds.add(viewId); 827 } 828 } 829 return viewIds; 830 } 831 832 838 public void updateForSelection(Object selection) { 839 ILaunch launch= getLaunch(selection); 840 if (launch == null) { 841 return; 842 } 843 String [] modelIds= getDebugModelIdsForSelection(selection); 844 enableContexts(getContextsForModels(modelIds), launch); 845 enableActivitiesFor(modelIds); 846 } 847 848 855 protected static ILaunch getLaunch(Object selection) { 856 ILaunch launch= null; 857 if (selection instanceof ILaunch) { 858 launch= (ILaunch) selection; 859 } else if (selection instanceof IDebugElement) { 860 launch= ((IDebugElement) selection).getLaunch(); 861 } else if (selection instanceof IProcess) { 862 launch= ((IProcess) selection).getLaunch(); 863 } 864 return launch; 865 } 866 867 873 protected String [] getDebugModelIdsForSelection(Object selection) { 874 if (selection instanceof IAdaptable) { 875 IDebugModelProvider modelProvider= (IDebugModelProvider) Platform.getAdapterManager().getAdapter(selection, IDebugModelProvider.class); 876 if (modelProvider != null) { 877 String [] modelIds= modelProvider.getModelIdentifiers(); 878 if (modelIds != null) { 879 return modelIds; 880 } 881 } 882 } 883 if (selection instanceof IStackFrame) { 884 return new String [] { ((IStackFrame) selection).getModelIdentifier() }; 885 } 886 return new String [0]; 887 } 888 889 896 protected List getContextsForModels(String [] modelIds) { 897 List contextIds= new ArrayList (); 898 for (int i = 0; i < modelIds.length; i++) { 899 List ids= (List ) modelsToContexts.get(modelIds[i]); 900 if (ids == null) { 901 ids = new ArrayList (); 903 ids.add(DEBUG_CONTEXT); 904 modelsToContexts.put(modelIds[i], ids); 905 } 906 contextIds.addAll(ids); 907 } 908 return contextIds; 909 } 910 911 917 protected void enableActivitiesFor(String [] modelIds) { 918 Set newActivities = null; 919 for (int i = 0; i < modelIds.length; i++) { 920 String id = modelIds[i]; 921 Set ids= (Set ) modelsToActivities.get(id); 922 if (ids == null) { 923 ids = new HashSet (); 925 modelsToActivities.put(id, ids); 926 Iterator bindings = modelPatternBindings.iterator(); 927 while (bindings.hasNext()) { 928 IActivityPatternBinding binding = (IActivityPatternBinding) bindings.next(); 929 String regex = binding.getPattern().pattern(); 930 regex = regex.substring(0, regex.length() - DEBUG_MODEL_ACTIVITY_SUFFIX.length()); 931 if (Pattern.matches(regex, id)) { 932 ids.add(binding.getActivityId()); 933 } 934 } 935 } 936 if (!enabledActivities.containsAll(ids)) { 937 if (newActivities == null) { 938 newActivities = new HashSet (); 939 } 940 newActivities.addAll(ids); 941 } 942 } 943 if (newActivities != null) { 944 IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport(); 945 Set idsToEnable= new HashSet (enabledActivities.size() + newActivities.size()); 946 idsToEnable.addAll(enabledActivities); 947 idsToEnable.addAll(newActivities); 948 activitySupport.setEnabledActivityIds(idsToEnable); 949 } 950 } 951 952 962 protected void enableContexts(List contextIds, ILaunch launch) { 963 if (contextIds.isEmpty()) { 964 return; 965 } 966 Set enabledContexts = PlatformUI.getWorkbench().getContextSupport().getContextManager().getEnabledContextIds(); 967 Set contextsAlreadyEnabled= new HashSet (); 968 Iterator iter= contextIds.iterator(); 969 while (iter.hasNext()) { 970 String contextId= (String ) iter.next(); 971 if (enabledContexts.contains(contextId) && !lastEnabledIds.contains(contextId)) { 972 contextsAlreadyEnabled.add(contextId); 978 } 979 } 980 lastEnabledIds.clear(); 981 lastEnabledIds.addAll(contextIds); 982 submitContexts(contextIds, launch); 983 contextEnabled(contextsAlreadyEnabled); 984 } 985 986 994 protected void submitContexts(List contextIds, ILaunch launch) { 995 List submissions = (List ) fContextSubmissions.get(launch); 996 if (submissions == null) { 997 submissions= new ArrayList (); 998 fContextSubmissions.put(launch, submissions); 999 } 1000 List newSubmissions= new ArrayList (); 1001 Iterator iter= contextIds.iterator(); 1002 while (iter.hasNext()) { 1003 newSubmissions.add(new EnabledSubmission(null, null, null, (String ) iter.next())); 1004 } 1005 IWorkbenchContextSupport contextSupport = PlatformUI.getWorkbench().getContextSupport(); 1006 if (!newSubmissions.isEmpty()) { 1007 contextSupport.addEnabledSubmissions(newSubmissions); 1008 List submissionsToRemove= new ArrayList (); 1012 ListIterator oldSubmissions= submissions.listIterator(); 1013 while (oldSubmissions.hasNext()) { 1014 EnabledSubmission oldSubmission= (EnabledSubmission) oldSubmissions.next(); 1015 String contextId = oldSubmission.getContextId(); 1016 if (contextIds.contains(contextId)) { 1017 oldSubmissions.remove(); 1018 submissionsToRemove.add(oldSubmission); 1019 } 1020 } 1021 contextSupport.removeEnabledSubmissions(submissionsToRemove); 1022 submissions.addAll(newSubmissions); 1023 } 1024 } 1025 1026 1032 protected void launchesTerminated(ILaunch[] launches) { 1033 List allSubmissions= new ArrayList (); 1034 for (int i = 0; i < launches.length; i++) { 1035 List submissions= (List ) fContextSubmissions.remove(launches[i]); 1036 if (submissions != null) { 1037 allSubmissions.addAll(submissions); 1038 } 1039 } 1040 PlatformUI.getWorkbench().getContextSupport().removeEnabledSubmissions(allSubmissions); 1041 } 1042 1043 1050 public static String getViewId(IConfigurationElement element) { 1051 return element.getAttribute(ATTR_VIEW_ID); 1052 } 1053 1054 1064 public static boolean isAutoOpen(IConfigurationElement element) { 1065 String autoOpen = element.getAttribute(ATTR_AUTO_OPEN); 1066 return autoOpen == null || Boolean.valueOf(autoOpen).booleanValue(); 1067 } 1068 1069 1079 public static boolean isAutoClose(IConfigurationElement element) { 1080 String autoClose = element.getAttribute(ATTR_AUTO_CLOSE); 1081 return autoClose == null || Boolean.valueOf(autoClose).booleanValue(); 1082 } 1083 1084 1090 private boolean isAutoManageViews() { 1091 IWorkbenchPage page = launchView.getViewSite().getPage(); 1092 if (page != null) { 1093 IPerspectiveDescriptor descriptor = page.getPerspective(); 1094 if (descriptor != null) { 1095 return fAutoManagePerspectives.contains(descriptor.getId()); 1096 } 1097 } 1098 return false; 1099 } 1100 1101 1106 public IWorkbenchPage getPage() { 1107 return launchView.getSite().getPage(); 1108 } 1109 1110 1116 public void perspectiveChanged(String changeId) { 1117 if (changeId.equals(IWorkbenchPage.CHANGE_RESET)) { 1118 fIsTrackingPartChanges= false; 1119 } else if (changeId.equals(IWorkbenchPage.CHANGE_RESET_COMPLETE)) { 1120 loadTrackViews(); 1121 } 1122 } 1123 1124 1130 public void perspectiveChanged(IWorkbenchPartReference ref, String changeId) { 1131 if (!fIsTrackingPartChanges) { 1132 return; 1133 } 1134 if (IWorkbenchPage.CHANGE_VIEW_HIDE.equals(changeId) && (ref instanceof IViewReference)) { 1135 String id = ((IViewReference) ref).getId(); 1136 if (managedViewIds.contains(id)) { 1137 viewIdsToNotOpen.add(id); 1138 saveViewsToNotOpen(); 1139 } 1140 1141 removeFromOpenedViews(id); 1142 saveOpenedViews(); 1143 } else if (IWorkbenchPage.CHANGE_VIEW_SHOW.equals(changeId) && ref instanceof IViewReference) { 1144 String id = ((IViewReference) ref).getId(); 1145 removeFromOpenedViews(id); 1146 saveOpenedViews(); 1147 } 1148 } 1149 1150 1155 private void removeFromOpenedViews(String viewId) { 1156 Iterator keys = openedViewIds.keySet().iterator(); 1157 while (keys.hasNext()) 1158 { 1159 String perspId = (String )keys.next(); 1160 1161 Set views = (Set )openedViewIds.get(perspId); 1162 if (views != null) 1163 { 1164 views.remove(viewId); 1165 } 1166 } 1167 } 1168 1169 1175 public void loadTrackViews() { 1176 fIsTrackingPartChanges= DebugUITools.getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TRACK_VIEWS); 1177 } 1178 1179 1183 private void loadAutoManagePerspectives() { 1184 String prefString = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES); 1185 fAutoManagePerspectives= parseList(prefString); 1186 } 1187 1188 1193 public void reloadAutoManagePerspectives(Object selection) { 1194 String [] modelIds = getDebugModelIdsForSelection(selection); 1198 List contextIds = getContextsForModels(modelIds); 1199 lastEnabledIds.removeAll(contextIds); 1200 1201 loadAutoManagePerspectives(); 1202 updateForSelection(selection); 1203 } 1204 1205 public void reloadViewsToNotOpen(Object selection) { 1206 String [] modelIds = getDebugModelIdsForSelection(selection); 1210 List contextIds = getContextsForModels(modelIds); 1211 lastEnabledIds.removeAll(contextIds); 1212 1213 loadViewsToNotOpen(); 1214 updateForSelection(selection); 1215 } 1216 1217 1222 public static List parseList(String listString) { 1223 List list = new ArrayList (10); 1224 StringTokenizer tokenizer = new StringTokenizer (listString, ","); while (tokenizer.hasMoreTokens()) { 1226 String token = tokenizer.nextToken(); 1227 list.add(token); 1228 } 1229 return list; 1230 } 1231 1232 1237 public void dispose() { 1238 IWorkbench workbench = PlatformUI.getWorkbench(); 1239 workbench.getContextSupport().getContextManager().removeContextManagerListener(this); 1240 workbench.getActivitySupport().getActivityManager().removeActivityManagerListener(this); 1241 } 1242 1243 1247 protected void clearLastEnabledContexts() { 1248 lastEnabledIds.clear(); 1249 } 1250 1251 1254 public void activityManagerChanged(ActivityManagerEvent activityManagerEvent) { 1255 if (activityManagerEvent.haveEnabledActivityIdsChanged()) { 1256 enabledActivities = activityManagerEvent.getActivityManager().getEnabledActivityIds(); 1257 } 1258 1259 } 1260 1261} | Popular Tags |