1 11 package org.eclipse.debug.internal.ui.views; 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.Map ; 19 import java.util.Set ; 20 import java.util.StringTokenizer ; 21 import java.util.Map.Entry; 22 23 import org.eclipse.core.commands.common.NotDefinedException; 24 import org.eclipse.core.commands.contexts.Context; 25 import org.eclipse.core.commands.contexts.ContextManagerEvent; 26 import org.eclipse.core.commands.contexts.IContextManagerListener; 27 import org.eclipse.core.runtime.CoreException; 28 import org.eclipse.core.runtime.IConfigurationElement; 29 import org.eclipse.core.runtime.IExtensionPoint; 30 import org.eclipse.core.runtime.Platform; 31 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; 32 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; 33 import org.eclipse.debug.core.DebugPlugin; 34 import org.eclipse.debug.core.ILaunch; 35 import org.eclipse.debug.core.ILaunchConfiguration; 36 import org.eclipse.debug.core.ILaunchConfigurationType; 37 import org.eclipse.debug.internal.ui.DebugUIPlugin; 38 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 39 import org.eclipse.debug.internal.ui.contexts.DebugModelContextBindingManager; 40 import org.eclipse.debug.ui.DebugUITools; 41 import org.eclipse.debug.ui.IDebugUIConstants; 42 import org.eclipse.debug.ui.contexts.DebugContextEvent; 43 import org.eclipse.debug.ui.contexts.IDebugContextListener; 44 import org.eclipse.debug.ui.contexts.IDebugContextService; 45 import org.eclipse.jface.viewers.ISelection; 46 import org.eclipse.jface.viewers.IStructuredSelection; 47 import org.eclipse.ui.IPerspectiveDescriptor; 48 import org.eclipse.ui.IPerspectiveListener4; 49 import org.eclipse.ui.IViewPart; 50 import org.eclipse.ui.IViewReference; 51 import org.eclipse.ui.IWorkbenchPage; 52 import org.eclipse.ui.IWorkbenchPartReference; 53 import org.eclipse.ui.IWorkbenchWindow; 54 import org.eclipse.ui.PartInitException; 55 import org.eclipse.ui.PlatformUI; 56 import org.eclipse.ui.console.IConsoleConstants; 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 68 public class ViewContextService implements IDebugContextListener, IPerspectiveListener4, IPropertyChangeListener, IContextManagerListener { 69 70 73 private Map fPerspectiveToActiveContext = new HashMap (); 74 75 78 private Map fPerspectiveToActivatedContexts = new HashMap (); 79 80 83 private Map fContextIdsToBindings; 84 85 88 private List fEnabledPerspectives = new ArrayList (); 89 90 94 private boolean fIgnoreChanges = false; 95 96 99 private IWorkbenchWindow fWindow; 100 101 private IContextService fContextService; 102 103 public static final String DEBUG_CONTEXT= "org.eclipse.debug.ui.debugging"; 106 private static final String ID_CONTEXT_VIEW_BINDINGS= "contextViewBindings"; 109 private static final String ATTR_CONTEXT_ID= "contextId"; private static final String ATTR_VIEW_ID= "viewId"; private static final String ATTR_AUTO_OPEN= "autoOpen"; private static final String ATTR_AUTO_CLOSE= "autoClose"; 115 private static final String XML_ELEMENT_VIEW_BINDINGS ="viewBindings"; private static final String XML_ELEMENT_PERSPECTIVE ="perspective"; private static final String XML_ELEMENT_VIEW = "view"; private static final String XML_ATTR_ID = "id"; private static final String XML_ATTR_USER_ACTION = "userAction"; private static final String XML_VALUE_OPENED = "opened"; private static final String XML_VALUE_CLOSED = "closed"; 124 private static Set fgBaseDebugViewIds = null; 126 127 static { 128 fgBaseDebugViewIds = new HashSet (); 129 fgBaseDebugViewIds.add(IDebugUIConstants.ID_DEBUG_VIEW); 130 fgBaseDebugViewIds.add(IDebugUIConstants.ID_VARIABLE_VIEW); 131 fgBaseDebugViewIds.add(IDebugUIConstants.ID_BREAKPOINT_VIEW); 132 fgBaseDebugViewIds.add(IConsoleConstants.ID_CONSOLE_VIEW); 133 } 134 135 private static String [] EMPTY_IDS = new String [0]; 136 137 140 private class DebugContextViewBindings { 141 142 private String fId; 144 145 private String [] fViewBindingIds = EMPTY_IDS; 147 148 private String [] fAllViewBindingIds = null; 150 private Map fAllViewIdToBindings = new HashMap (); 152 private String [] fAllConetxtIds = null; 154 155 private String fParentId; 157 158 163 public DebugContextViewBindings(String id) { 164 fId = id; 165 } 166 167 172 public String getId() { 173 return fId; 174 } 175 176 181 public void addBinding(ViewBinding binding) { 182 String [] newBindings = new String [fViewBindingIds.length + 1]; 183 System.arraycopy(fViewBindingIds, 0, newBindings, 0, fViewBindingIds.length); 184 newBindings[fViewBindingIds.length] = binding.getViewId(); 185 fAllViewIdToBindings.put(binding.getViewId(), binding); 186 fViewBindingIds = newBindings; 187 } 188 189 194 protected void setParentId(String id) { 195 fParentId = id; 196 } 197 198 203 public DebugContextViewBindings getParentContext() { 204 if (fParentId == null) { 205 return null; 206 } 207 return (DebugContextViewBindings) fContextIdsToBindings.get(fParentId); 208 } 209 210 214 public void activateChain(IWorkbenchPage page) { 215 initializeChain(); 216 doActivation(page, fAllViewBindingIds, fAllConetxtIds); 217 } 218 219 227 private void doActivation(IWorkbenchPage page, String [] viewIds, String [] contextIds) { 228 for (int i = 0; i < contextIds.length; i++) { 230 addActivated(contextIds[i]); 231 } 232 setActive(page.getPerspective(), getId()); 234 for (int i = 0; i < viewIds.length; i++) { 236 String viewId = viewIds[i]; 237 ViewBinding binding = (ViewBinding) fAllViewIdToBindings.get(viewId); 238 binding.activated(page); 239 } 240 for (int i = 0; i < viewIds.length; i++) { 242 String viewId = viewIds[i]; 243 ViewBinding binding = (ViewBinding) fAllViewIdToBindings.get(viewId); 244 binding.checkZOrder(page, fAllViewBindingIds); 245 } 246 } 247 248 252 private synchronized void initializeChain() { 253 if (fAllViewBindingIds == null) { 254 List orderedIds = new ArrayList (); 255 List contexts = new ArrayList (); 256 DebugContextViewBindings context = this; 257 while (context != null) { 258 contexts.add(0, context); 259 context = context.getParentContext(); 260 } 261 Iterator iterator = contexts.iterator(); 262 fAllConetxtIds = new String [contexts.size()]; 263 int pos = 0; 264 while (iterator.hasNext()) { 265 DebugContextViewBindings bindings = (DebugContextViewBindings) iterator.next(); 266 fAllConetxtIds[pos] = bindings.getId(); 267 pos++; 268 for (int i = 0; i < bindings.fViewBindingIds.length; i++) { 269 String viewId = bindings.fViewBindingIds[i]; 270 if (bindings == this) { 271 orderedIds.add(viewId); 272 } 273 if (!fAllViewIdToBindings.containsKey(viewId)) { 274 orderedIds.add(viewId); 275 fAllViewIdToBindings.put(viewId, bindings.fAllViewIdToBindings.get(viewId)); 276 } 277 } 278 } 279 fAllViewBindingIds = (String []) orderedIds.toArray(new String [orderedIds.size()]); 280 } 281 } 282 283 288 public void deactivate(IWorkbenchPage page) { 289 removeActivated(getId()); 290 if (isActiveContext(getId())) { 291 setActive(page.getPerspective(), null); 292 } 293 for (int i = 0; i < fViewBindingIds.length; i++) { 294 String viewId = fViewBindingIds[i]; 295 ViewBinding binding = (ViewBinding) fAllViewIdToBindings.get(viewId); 296 binding.deactivated(page); 297 } 298 } 299 300 306 public void setViewOpened(boolean opened, String viewId) { 307 initializeChain(); 308 ViewBinding binding = (ViewBinding)fAllViewIdToBindings.get(viewId); 309 if (binding != null) { 310 if (opened) { 311 binding.userOpened(); 312 } else { 313 binding.userClosed(); 314 } 315 } 316 } 317 318 public void applyUserSettings(String viewId, Element viewElement) { 319 initializeChain(); 320 ViewBinding binding = (ViewBinding) fAllViewIdToBindings.get(viewId); 321 if (binding != null) { 322 binding.applyUserSettings(viewElement); 323 } 324 } 325 326 333 public void saveBindings(Document document, Element root, Set alreadyDone) { 334 for (int i = 0; i < fViewBindingIds.length; i++) { 335 String viewId = fViewBindingIds[i]; 336 if (!alreadyDone.contains(viewId)) { 337 alreadyDone.add(viewId); 338 ViewBinding binding = (ViewBinding) fAllViewIdToBindings.get(viewId); 339 binding.saveBindings(document, root); 340 } 341 } 342 } 343 } 344 345 348 private class ViewBinding { 349 private IConfigurationElement fElement; 350 353 private Set fUserOpened = new HashSet (); 354 357 private Set fUserClosed = new HashSet (); 358 359 public ViewBinding(IConfigurationElement element) { 360 fElement = element; 361 } 362 363 368 public String getViewId() { 369 return fElement.getAttribute(ATTR_VIEW_ID); 370 } 371 372 377 public boolean isAutoOpen() { 378 String autoopen = fElement.getAttribute(ATTR_AUTO_OPEN); 379 return autoopen == null || "true".equals(autoopen); } 381 382 387 public boolean isAutoClose() { 388 String autoclose = fElement.getAttribute(ATTR_AUTO_CLOSE); 389 return autoclose == null || "true".equals(autoclose); } 391 392 396 public boolean isUserOpened() { 397 return fUserOpened.contains(getActivePerspective().getId()); 398 } 399 400 404 public boolean isUserClosed() { 405 return fUserClosed.contains(getActivePerspective().getId()); 406 } 407 408 416 public boolean isDefault() { 417 String id = getActivePerspective().getId(); 418 if (IDebugUIConstants.ID_DEBUG_PERSPECTIVE.equals(id)) { 419 return fgBaseDebugViewIds.contains(getViewId()); 420 } 421 return false; 422 } 423 424 protected void userOpened() { 425 if (isTrackingViews()) { 426 String id = getActivePerspective().getId(); 427 fUserOpened.add(id); 428 fUserClosed.remove(id); 429 saveViewBindings(); 430 } 431 } 432 433 protected void userClosed() { 434 if (isTrackingViews()) { 435 String id = getActivePerspective().getId(); 436 fUserClosed.add(id); 437 fUserOpened.remove(id); 438 saveViewBindings(); 439 } 440 } 441 442 447 protected boolean isTrackingViews() { 448 return DebugUITools.getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TRACK_VIEWS); 449 } 450 451 456 public void activated(IWorkbenchPage page) { 457 if (!isUserClosed()) { 458 if (isAutoOpen()) { 459 try { 460 fIgnoreChanges = true; 461 page.showView(getViewId(), null, IWorkbenchPage.VIEW_CREATE); 462 } catch (PartInitException e) { 463 DebugUIPlugin.log(e); 464 } finally { 465 fIgnoreChanges = false; 466 } 467 } 468 } 469 } 470 471 477 public void checkZOrder(IWorkbenchPage page, String [] relevantViews) { 478 IViewPart part = page.findView(getViewId()); 480 if (part != null) { 481 IViewPart[] viewStack = page.getViewStack(part); 482 if (viewStack != null && viewStack.length > 0) { 483 String top = viewStack[0].getSite().getId(); 484 for (int i = 0; i < relevantViews.length; i++) { 485 if (relevantViews[i].equals(top)) { 486 return; 488 } 489 } 490 try { 492 fIgnoreChanges = true; 493 page.bringToTop(part); 494 } finally { 495 fIgnoreChanges = false; 496 } 497 } 498 } 499 } 500 501 506 public void deactivated(IWorkbenchPage page) { 507 if (!isUserOpened()) { 508 if (isAutoClose() && !isDefault()) { 509 IViewReference reference = page.findViewReference(getViewId()); 510 if (reference != null) { 511 try { 512 fIgnoreChanges = true; 513 page.hideView(reference); 514 } finally { 515 fIgnoreChanges = false; 516 } 517 } 518 } 519 } 520 } 521 522 528 public void saveBindings(Document document, Element root) { 529 Element viewElement = document.createElement(XML_ELEMENT_VIEW); 530 viewElement.setAttribute(XML_ATTR_ID, getViewId()); 531 appendPerspectives(document, viewElement, fUserOpened, XML_VALUE_OPENED); 532 appendPerspectives(document, viewElement, fUserClosed, XML_VALUE_CLOSED); 533 if (viewElement.hasChildNodes()) { 534 root.appendChild(viewElement); 535 } 536 } 537 538 private void appendPerspectives(Document document, Element parent, Set perpectives, String xmlValue) { 539 String [] ids = (String []) perpectives.toArray(new String [perpectives.size()]); 540 for (int i = 0; i < ids.length; i++) { 541 String id = ids[i]; 542 Element element = document.createElement(XML_ELEMENT_PERSPECTIVE); 543 element.setAttribute(XML_ATTR_ID, id); 544 element.setAttribute(XML_ATTR_USER_ACTION, xmlValue); 545 parent.appendChild(element); 546 } 547 } 548 549 public void applyUserSettings(Element viewElement) { 550 NodeList list = viewElement.getChildNodes(); 551 int length = list.getLength(); 552 for (int i = 0; i < length; ++i) { 553 Node node = list.item(i); 554 short type = node.getNodeType(); 555 if (type == Node.ELEMENT_NODE) { 556 Element entry = (Element) node; 557 if(entry.getNodeName().equalsIgnoreCase(XML_ELEMENT_PERSPECTIVE)){ 558 String id = entry.getAttribute(XML_ATTR_ID); 559 String setting = entry.getAttribute(XML_ATTR_USER_ACTION); 560 if (id != null) { 561 if (XML_VALUE_CLOSED.equals(setting)) { 562 fUserClosed.add(id); 563 } else if (XML_VALUE_OPENED.equals(setting)) { 564 fUserOpened.add(id); 565 } 566 } 567 } 568 } 569 } 570 } 571 } 572 573 private IDebugContextService getDebugContextService() { 574 return DebugUITools.getDebugContextManager().getContextService(fWindow); 575 } 576 577 582 ViewContextService(IWorkbenchWindow window) { 583 fWindow = window; 584 fContextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class); 585 loadContextToViewExtensions(); 586 applyUserViewBindings(); 587 loadPerspectives(); 588 window.addPerspectiveListener(this); 589 getDebugContextService().addDebugContextListener(this); 590 DebugUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this); 591 fContextService.addContextManagerListener(this); 592 } 593 594 public void dispose() { 595 fWindow.removePerspectiveListener(this); 596 getDebugContextService().removeDebugContextListener(this); 597 DebugUIPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(this); 598 fContextService.removeContextManagerListener(this); 599 } 600 601 604 private void loadContextToViewExtensions() { 605 fContextIdsToBindings = new HashMap (); 606 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), ID_CONTEXT_VIEW_BINDINGS); 607 IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); 608 for (int i = 0; i < configurationElements.length; i++) { 609 IConfigurationElement element = configurationElements[i]; 610 String viewId = element.getAttribute(ATTR_VIEW_ID); 611 String contextId = element.getAttribute(ATTR_CONTEXT_ID); 612 if (contextId == null || viewId == null) { 613 continue; 614 } 615 ViewBinding info = new ViewBinding(element); 616 DebugContextViewBindings bindings = (DebugContextViewBindings) fContextIdsToBindings.get(contextId); 617 if (bindings == null) { 618 bindings = new DebugContextViewBindings(contextId); 619 fContextIdsToBindings.put(contextId, bindings); 620 } 621 bindings.addBinding(info); 622 } 623 linkParentContexts(); 624 } 625 626 629 private void applyUserViewBindings() { 630 String xml = DebugUITools.getPreferenceStore().getString(IInternalDebugUIConstants.PREF_USER_VIEW_BINDINGS); 631 if (xml.length() > 0) { 632 try { 633 Element root = DebugPlugin.parseDocument(xml); 634 NodeList list = root.getChildNodes(); 635 int length = list.getLength(); 636 for (int i = 0; i < length; ++i) { 637 Node node = list.item(i); 638 short type = node.getNodeType(); 639 if (type == Node.ELEMENT_NODE) { 640 Element entry = (Element) node; 641 if(entry.getNodeName().equalsIgnoreCase(XML_ELEMENT_VIEW)){ 642 String id = entry.getAttribute(XML_ATTR_ID); 643 Iterator bindings = fContextIdsToBindings.values().iterator(); 644 while (bindings.hasNext()) { 645 DebugContextViewBindings binding = (DebugContextViewBindings) bindings.next(); 646 binding.applyUserSettings(id, entry); 647 } 648 } 649 } 650 } 651 } catch (CoreException e) { 652 DebugUIPlugin.log(e); 653 } 654 } 655 } 656 657 660 private void loadPerspectives() { 661 String prefString = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES); 662 fEnabledPerspectives = parseList(prefString); 663 } 664 665 668 public void propertyChange(PropertyChangeEvent event) { 669 if (!fIgnoreChanges) { 670 if (IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES.equals(event.getProperty())) { 671 loadPerspectives(); 672 } else if (IInternalDebugUIConstants.PREF_USER_VIEW_BINDINGS.equals(event.getProperty())) { 673 loadContextToViewExtensions(); 674 applyUserViewBindings(); 675 fPerspectiveToActivatedContexts.clear(); 677 ISelection selection = getDebugContextService().getActiveContext(); 678 contextActivated(selection); 679 } 680 } 681 } 682 683 688 private boolean isEnabledPerspective() { 689 IPerspectiveDescriptor perspective = getActivePerspective(); 690 if (perspective != null) { 691 return fEnabledPerspectives.contains(perspective.getId()); 692 } 693 return false; 694 } 695 696 701 private IPerspectiveDescriptor getActivePerspective() { 702 IWorkbenchPage activePage = fWindow.getActivePage(); 703 if (activePage != null) { 704 return activePage.getPerspective(); 705 } 706 return null; 707 } 708 709 714 public static List parseList(String listString) { 715 List list = new ArrayList (10); 716 StringTokenizer tokenizer = new StringTokenizer (listString, ","); while (tokenizer.hasMoreTokens()) { 718 String token = tokenizer.nextToken(); 719 list.add(token); 720 } 721 return list; 722 } 723 724 public void contextActivated(ISelection selection) { 725 if (isEnabledPerspective()) { 726 if (selection instanceof IStructuredSelection && !selection.isEmpty()) { 727 IStructuredSelection ss = (IStructuredSelection) selection; 728 Iterator iterator = ss.iterator(); 729 while (iterator.hasNext()) { 730 Object target = iterator.next(); 731 ILaunch launch = DebugModelContextBindingManager.getLaunch(target); 732 if (launch != null) { 733 ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration(); 734 if (launchConfiguration != null) { 735 try { 736 ILaunchConfigurationType type = launchConfiguration.getType(); 737 if (fContextService.getActiveContextIds().contains(type.getIdentifier() + ".internal." + getActivePerspective().getId())) { List workbenchContexts = DebugModelContextBindingManager.getDefault().getWorkbenchContextsForDebugContext(target); 742 if (!workbenchContexts.isEmpty()) { 744 Iterator contexts = workbenchContexts.iterator(); 746 while (contexts.hasNext()) { 747 String contextId = (String )contexts.next(); 748 if (!isActivated(contextId)) { 749 activateChain(contextId); 750 } 751 if (!contexts.hasNext()) { 753 if (!isActiveContext(contextId)) { 754 activateChain(contextId); 755 } 756 } 757 } 758 } 759 760 } 761 } catch (CoreException e) { 762 DebugUIPlugin.log(e); 763 } 764 } 765 } 766 } 767 } 768 } 769 } 770 771 777 private boolean isActiveContext(String contextId) { 778 IPerspectiveDescriptor activePerspective = getActivePerspective(); 779 if (activePerspective != null) { 780 String activeId = (String ) fPerspectiveToActiveContext.get(activePerspective); 781 return contextId.equals(activeId); 782 } 783 return false; 784 } 785 786 792 private boolean isActivated(String contextId) { 793 IPerspectiveDescriptor activePerspective = getActivePerspective(); 794 if (activePerspective != null) { 795 Set contexts = (Set ) fPerspectiveToActivatedContexts.get(activePerspective); 796 if (contexts != null) { 797 return contexts.contains(contextId); 798 } 799 } 800 return false; 801 } 802 803 private void addActivated(String contextId) { 804 IPerspectiveDescriptor activePerspective = getActivePerspective(); 805 if (activePerspective != null) { 806 Set contexts = (Set ) fPerspectiveToActivatedContexts.get(activePerspective); 807 if (contexts == null) { 808 contexts = new HashSet (); 809 fPerspectiveToActivatedContexts.put(activePerspective, contexts); 810 } 811 contexts.add(contextId); 812 } 813 } 814 815 private void removeActivated(String contextId) { 816 IPerspectiveDescriptor activePerspective = getActivePerspective(); 817 if (activePerspective != null) { 818 Set contexts = (Set ) fPerspectiveToActivatedContexts.get(activePerspective); 819 if (contexts != null) { 820 contexts.remove(contextId); 821 } 822 } 823 } 824 825 public void debugContextChanged(DebugContextEvent event) { 826 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 827 contextActivated(event.getContext()); 828 } 829 } 830 831 834 public void perspectiveOpened(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 835 } 836 837 840 public void perspectiveClosed(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 841 } 842 843 846 public void perspectiveDeactivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 847 } 848 849 855 private void clean(IPerspectiveDescriptor perspective) { 856 Set contexts = (Set ) fPerspectiveToActivatedContexts.remove(perspective); 857 fPerspectiveToActiveContext.remove(perspective); 858 if (contexts != null) { 859 Iterator iterator = contexts.iterator(); 860 while (iterator.hasNext()) { 861 String id = (String ) iterator.next(); 862 deactivate(id); 863 } 864 } 865 } 866 867 870 public void perspectiveSavedAs(IWorkbenchPage page, IPerspectiveDescriptor oldPerspective, IPerspectiveDescriptor newPerspective) { 871 } 872 873 876 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) { 877 if (!fIgnoreChanges && page.getWorkbenchWindow().equals(fWindow)) { 878 if(partRef != null) { 879 if (IWorkbenchPage.CHANGE_VIEW_SHOW == changeId || IWorkbenchPage.CHANGE_VIEW_HIDE == changeId) { 880 Iterator iterator = fContextIdsToBindings.values().iterator(); 881 while (iterator.hasNext()) { 882 DebugContextViewBindings bindings = (DebugContextViewBindings) iterator.next(); 883 bindings.setViewOpened(IWorkbenchPage.CHANGE_VIEW_SHOW == changeId, partRef.getId()); 884 } 885 } 886 } 887 } 888 } 889 890 893 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 894 if (page.getWorkbenchWindow().equals(fWindow)) { 895 ISelection activeContext = getDebugContextService().getActiveContext(); 896 if (activeContext != null) { 897 contextActivated(activeContext); 898 } 899 } 900 } 901 902 905 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) { 906 } 907 908 913 private void activateChain(String contextId) { 914 IWorkbenchPage page = fWindow.getActivePage(); 915 if (page != null) { 916 DebugContextViewBindings bindings= (DebugContextViewBindings) fContextIdsToBindings.get(contextId); 917 if (bindings != null) { 918 bindings.activateChain(page); 919 } 920 } 921 } 922 923 926 private void linkParentContexts() { 927 Iterator iterator = fContextIdsToBindings.entrySet().iterator(); 928 while (iterator.hasNext()) { 929 Entry entry = (Entry)iterator.next(); 930 String contextId = (String ) entry.getKey(); 931 DebugContextViewBindings bindings = (DebugContextViewBindings) entry.getValue(); 932 if (!bindings.getId().equals(DEBUG_CONTEXT)) { 933 Context context = fContextService.getContext(contextId); 934 try { 935 bindings.setParentId(context.getParentId()); 936 } catch (NotDefinedException e) { 937 DebugUIPlugin.log(e); 938 } 939 } 940 } 941 } 942 943 950 private void setActive(IPerspectiveDescriptor perspective, String contextId) { 951 if (contextId == null) { 952 fPerspectiveToActiveContext.remove(perspective); 953 } else { 954 fPerspectiveToActiveContext.put(perspective, contextId); 955 } 956 } 957 958 961 public void contextManagerChanged(ContextManagerEvent event) { 962 if (event.isActiveContextsChanged()) { 963 Set disabledContexts = getDisabledContexts(event); 964 if (!disabledContexts.isEmpty()) { 965 Iterator contexts = disabledContexts.iterator(); 966 while (contexts.hasNext()) { 967 String contextId = (String )contexts.next(); 968 if (isViewConetxt(contextId)) { 969 if (isActivated(contextId)) { 970 deactivate(contextId); 971 } 972 } 973 } 974 } 975 } 976 } 977 978 private void deactivate(String contextId) { 979 IWorkbenchPage page = fWindow.getActivePage(); 980 if (page != null) { 981 DebugContextViewBindings bindings = (DebugContextViewBindings) fContextIdsToBindings.get(contextId); 982 if (bindings != null) { 983 bindings.deactivate(page); 984 } 985 } 986 } 987 988 994 private Set getDisabledContexts(ContextManagerEvent event) { 995 Set prev = new HashSet (event.getPreviouslyActiveContextIds()); 996 Set activeContextIds = event.getContextManager().getActiveContextIds(); 997 if (activeContextIds != null) { 998 prev.removeAll(activeContextIds); 999 } 1000 return prev; 1001 } 1002 1003 1009 private boolean isViewConetxt(String id) { 1010 return fContextIdsToBindings.containsKey(id); 1011 } 1012 1013 1016 private void saveViewBindings() { 1017 try { 1018 Document document = DebugPlugin.newDocument(); 1019 Element root = document.createElement(XML_ELEMENT_VIEW_BINDINGS); 1020 document.appendChild(root); 1021 Set done = new HashSet (); 1022 Iterator bindings = fContextIdsToBindings.values().iterator(); 1023 while (bindings.hasNext()) { 1024 DebugContextViewBindings binding = (DebugContextViewBindings) bindings.next(); 1025 binding.saveBindings(document, root, done); 1026 } 1027 String prefValue = ""; if (root.hasChildNodes()) { 1029 prefValue = DebugPlugin.serializeDocument(document); 1030 } 1031 fIgnoreChanges = true; 1032 DebugUITools.getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_USER_VIEW_BINDINGS, prefValue); 1033 } catch (CoreException e) { 1034 DebugUIPlugin.log(e); 1035 } finally { 1036 fIgnoreChanges = false; 1037 } 1038 1039 } 1040 1041 1046 public String [] getEnabledPerspectives() { 1047 return (String []) fEnabledPerspectives.toArray(new String [fEnabledPerspectives.size()]); 1048 } 1049 1050 1055 public void showViewQuiet(String viewId) { 1056 IWorkbenchPage page = fWindow.getActivePage(); 1057 if (page != null) { 1058 try { 1059 fIgnoreChanges = true; 1060 IViewPart part = page.showView(viewId, null, IWorkbenchPage.VIEW_VISIBLE); 1061 if (!page.isPartVisible(part)) { 1062 page.bringToTop(part); 1063 } 1064 } catch (PartInitException e) { 1065 DebugUIPlugin.log(e); 1066 } finally { 1067 fIgnoreChanges = false; 1068 } 1069 } 1070 } 1071 1072 1075 public void perspectivePreDeactivate(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 1076 if (page.getWorkbenchWindow().equals(fWindow)) { 1077 clean(perspective); 1078 } 1079 } 1080} 1081 | Popular Tags |