1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import java.util.ArrayList ; 14 import java.util.Enumeration ; 15 import java.util.HashSet ; 16 import java.util.Hashtable ; 17 import java.util.Set ; 18 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.debug.core.DebugException; 24 import org.eclipse.debug.core.DebugPlugin; 25 import org.eclipse.debug.core.model.IDebugElement; 26 import org.eclipse.debug.core.model.IDebugTarget; 27 import org.eclipse.debug.core.model.IMemoryBlock; 28 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 29 import org.eclipse.debug.internal.ui.DebugUIPlugin; 30 import org.eclipse.debug.internal.ui.views.memory.renderings.CreateRendering; 31 import org.eclipse.debug.ui.DebugUITools; 32 import org.eclipse.debug.ui.IDebugUIConstants; 33 import org.eclipse.debug.ui.contexts.DebugContextEvent; 34 import org.eclipse.debug.ui.memory.IMemoryRendering; 35 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer; 36 import org.eclipse.debug.ui.memory.IMemoryRenderingSite; 37 import org.eclipse.debug.ui.memory.IMemoryRenderingSynchronizationService; 38 import org.eclipse.debug.ui.memory.IResettableMemoryRendering; 39 import org.eclipse.jface.action.IAction; 40 import org.eclipse.jface.viewers.ISelection; 41 import org.eclipse.jface.viewers.IStructuredSelection; 42 import org.eclipse.jface.viewers.StructuredSelection; 43 import org.eclipse.swt.SWT; 44 import org.eclipse.swt.SWTException; 45 import org.eclipse.swt.events.SelectionEvent; 46 import org.eclipse.swt.widgets.Composite; 47 import org.eclipse.swt.widgets.Control; 48 import org.eclipse.swt.widgets.Display; 49 import org.eclipse.swt.widgets.TabFolder; 50 import org.eclipse.swt.widgets.TabItem; 51 import org.eclipse.ui.IViewPart; 52 import org.eclipse.ui.IWorkbenchPart; 53 import org.eclipse.ui.PlatformUI; 54 import org.eclipse.ui.progress.UIJob; 55 56 57 58 64 public class RenderingViewPane extends AbstractMemoryViewPane implements IMemoryRenderingContainer{ 65 66 public static final String RENDERING_VIEW_PANE_ID = DebugUIPlugin.getUniqueIdentifier() + ".MemoryView.RenderingViewPane"; 68 private Hashtable fTabFolderForMemoryBlock = new Hashtable (); 69 private Hashtable fMemoryBlockFromTabFolder = new Hashtable (); 70 71 private AddMemoryRenderingAction fAddMemoryRenderingAction; 72 73 private IAction fRemoveMemoryRenderingAction; 74 private ViewPaneRenderingMgr fRenderingMgr; 75 76 private IMemoryRenderingSite fRenderingSite; 77 private Set fAddedRenderings = new HashSet (); 78 private Set fAddedMemoryBlocks = new HashSet (); 79 80 private boolean fIsDisposed = false; 81 82 97 public RenderingViewPane(IViewPart parent) { 98 super(parent); 99 100 if (parent instanceof IMemoryRenderingSite) 101 fRenderingSite = (IMemoryRenderingSite)parent; 102 else 103 { 104 DebugUIPlugin.logErrorMessage("Parent for the rendering view pane is invalid."); } 106 } 107 108 111 public void memoryBlocksAdded(final IMemoryBlock[] memoryBlocks) { 112 Display.getDefault().asyncExec(new Runnable () { 113 public void run() { 114 115 if (isDisposed()) 116 return; 117 118 if (memoryBlocks == null || memoryBlocks.length <= 0) 120 return; 121 122 for (int i=0; i<memoryBlocks.length; i++) 123 { 124 IMemoryBlock memory = memoryBlocks[i]; 125 126 if (!fTabFolderForMemoryBlock.containsKey(memory)) 127 { 128 createFolderForMemoryBlock(memory); 129 } 130 fAddedMemoryBlocks.add(memory); 131 updateToolBarActionsEnablement(); 132 } 133 }}); 134 } 135 136 private IMemoryBlockRetrieval getMemoryBlockRetrieval(IMemoryBlock memoryBlock) 137 { 138 IMemoryBlockRetrieval retrieval = (IMemoryBlockRetrieval)memoryBlock.getAdapter(IMemoryBlockRetrieval.class); 139 140 if (retrieval == null) 141 { 142 retrieval = memoryBlock.getDebugTarget(); 143 } 144 145 return retrieval; 146 } 147 148 151 public void memoryBlocksRemoved(final IMemoryBlock[] memoryBlocks) { 152 Display.getDefault().asyncExec(new Runnable () { 153 public void run() { 154 for (int j=0; j<memoryBlocks.length; j++) 155 { 156 IMemoryBlock memory = memoryBlocks[j]; 157 if (fTabFolderForMemoryBlock == null) 158 { 159 return; 160 } 161 162 IMemoryRendering[] renderings = fRenderingMgr.getRenderingsFromMemoryBlock(memory); 164 165 for (int k=0; k<renderings.length; k++) 166 { 167 removeMemoryRendering(renderings[k]); 168 } 169 170 TabFolder tabFolder = 172 (TabFolder) fTabFolderForMemoryBlock.get(memory); 173 174 if (tabFolder == null) 175 continue; 176 177 fTabFolderForMemoryBlock.remove(memory); 178 fMemoryBlockFromTabFolder.remove(tabFolder); 179 fTabFolderForDebugView.remove(getMemoryBlockRetrieval(memory)); 180 181 if (!tabFolder.isDisposed()) { 182 183 IMemoryBlockRetrieval retrieve = (IMemoryBlockRetrieval)memory.getAdapter(IMemoryBlockRetrieval.class); 184 if (retrieve == null) 185 { 186 retrieve = memory.getDebugTarget(); 187 } 188 189 if (fTabFolderForDebugView.contains(tabFolder)) 190 { 191 fTabFolderForDebugView.remove(retrieve); 192 } 193 194 TabItem[] items = tabFolder.getItems(); 196 197 for (int i=0; i<items.length; i++) 198 { 199 disposeTab(items[i]); 200 } 201 202 tabFolder.dispose(); 204 205 if (tabFolder == fStackLayout.topControl) 207 { 208 209 212 ISelection selection = DebugUIPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection(IDebugUIConstants.ID_MEMORY_VIEW); 213 IMemoryBlock blk = getMemoryBlock(selection); 214 215 if (blk != null) 216 { 217 218 if (blk != memory) 221 handleMemoryBlockSelection(null, blk); 222 else if ((MemoryViewUtil.getMemoryBlockManager().getMemoryBlocks(memory.getDebugTarget()).length > 0)) 223 { 224 blk = MemoryViewUtil.getMemoryBlockManager().getMemoryBlocks(memory.getDebugTarget())[0]; 225 handleMemoryBlockSelection(null, blk); 226 } 227 else 228 { 229 emptyFolder(); 230 } 231 } 232 else if (MemoryViewUtil.getMemoryBlockManager().getMemoryBlocks(memory.getDebugTarget()).length > 0) 233 { blk = MemoryViewUtil.getMemoryBlockManager().getMemoryBlocks(memory.getDebugTarget())[0]; 235 handleMemoryBlockSelection(null, blk); 236 } 237 else 238 { 239 emptyFolder(); 240 241 } 242 } 243 244 } 247 248 fAddedMemoryBlocks.remove(memory); 249 updateToolBarActionsEnablement(); 250 } 251 } 252 }); 253 254 } 255 256 259 public void selectionChanged(final IWorkbenchPart part, final ISelection selection) { 260 if (fIsDisposed) 261 return; 262 263 if(part == RenderingViewPane.this) 265 return; 266 267 if (!(selection instanceof IStructuredSelection)) 268 return; 269 270 if (selection == AbstractMemoryViewPane.EMPTY) 271 return; 272 273 UIJob job = new UIJob("RenderingViewPane selectionChanged"){ 275 public IStatus runInUIThread(IProgressMonitor monitor) { 276 try { 277 278 if (isDisposed()) 279 return Status.OK_STATUS; 280 281 if (selection.isEmpty()) 282 { 283 if (part.getSite().getId().equals(IDebugUIConstants.ID_MEMORY_VIEW)) 286 { 287 if (part == getMemoryRenderingSite().getSite().getPart()) 288 { 289 IMemoryViewTab lastViewTab = getTopMemoryTab(); 290 291 if (lastViewTab != null) 292 lastViewTab.setEnabled(false); 293 294 emptyFolder(); 295 } 296 } 297 298 305 return Status.OK_STATUS; 306 } 307 308 IMemoryViewTab lastViewTab = getTopMemoryTab(); 310 311 if (!(selection instanceof IStructuredSelection)) 312 return Status.OK_STATUS; 313 314 Object elem = ((IStructuredSelection)selection).getFirstElement(); 315 316 if (elem instanceof IMemoryBlock) 317 { 318 if (part == getMemoryRenderingSite()) 320 { 321 IMemoryBlock memBlock = (IMemoryBlock)elem; 323 324 if (fTabFolderForMemoryBlock == null) 326 { 327 if (lastViewTab != null) 328 lastViewTab.setEnabled(false); 329 330 emptyFolder(); 331 return Status.OK_STATUS; 332 } 333 334 handleMemoryBlockSelection(lastViewTab, memBlock); 335 } 336 } 337 } 338 catch(SWTException se) 339 { 340 DebugUIPlugin.log(se); 341 } 342 return Status.OK_STATUS; 343 }}; 344 job.setSystem(true); 345 job.schedule(); 346 } 347 348 public void handleMemoryBlockSelection(final IMemoryViewTab lastViewTab, final IMemoryBlock memBlock) { 349 if (memBlock.getDebugTarget().isDisconnected() 351 || memBlock.getDebugTarget().isTerminated()) { 352 emptyFolder(); 353 return; 354 } 355 356 TabFolder currentFolder = (TabFolder) fStackLayout.topControl; 358 if (currentFolder != null && !currentFolder.isDisposed()) { 359 IMemoryBlock currentBlk = (IMemoryBlock) fMemoryBlockFromTabFolder.get(currentFolder); 360 if (currentBlk != null) { 361 if (currentBlk == memBlock) 362 return; 363 } 364 } 365 366 if (getTopMemoryTab() != null) { 367 if (getTopMemoryTab().getRendering().getMemoryBlock() == memBlock) { 368 return; 369 } 370 } 371 372 if (fTabFolderForMemoryBlock.containsKey(memBlock)) { 375 if (fStackLayout.topControl != (TabFolder) fTabFolderForMemoryBlock.get(memBlock)) { 376 setTabFolder((TabFolder) fTabFolderForMemoryBlock.get(memBlock)); 377 fViewPaneCanvas.layout(); 378 } 379 } else { TabFolder folder = new TabFolder(fViewPaneCanvas, SWT.NULL); 381 382 fTabFolderForMemoryBlock.put(memBlock, folder); 383 fMemoryBlockFromTabFolder.put(folder, memBlock); 384 setTabFolder((TabFolder) fTabFolderForMemoryBlock.get(memBlock)); 385 fViewPaneCanvas.layout(); 386 fAddedMemoryBlocks.add(memBlock); 387 } 388 389 IMemoryRendering[] renderings = fRenderingMgr.getRenderingsFromMemoryBlock(memBlock); 391 TabFolder toDisplay = (TabFolder) fStackLayout.topControl; 392 393 if (toDisplay.getItemCount() == 0) { 394 restoreViewTabs(renderings); 395 } 396 397 IMemoryViewTab newViewTab = getTopMemoryTab(); 399 400 if (lastViewTab != null && lastViewTab != newViewTab) { 401 lastViewTab.setEnabled(false); 402 } 403 404 if (newViewTab != null) { 405 if (!newViewTab.isEnabled()) { 407 if (fVisible) { 409 newViewTab.setEnabled(fVisible); 410 } 411 } 412 } 413 414 IMemoryViewTab viewTab = getTopMemoryTab(); 415 if (viewTab != null) 416 setRenderingSelection(viewTab.getRendering()); 417 418 if (viewTab == null && fRenderingMgr.getRenderings().length == 0) { 419 if (toDisplay != fEmptyTabFolder) { 421 TabItem newItem = new TabItem(toDisplay, SWT.NULL); 422 CreateRendering rendering = new CreateRendering(getInstance()); 423 rendering.init(getInstance(), memBlock); 424 MemoryViewTab createTab = new MemoryViewTab(newItem,rendering, getInstance()); 425 setRenderingSelection(createTab.getRendering()); 426 } 427 } 428 429 updateToolBarActionsEnablement(); 431 } 432 433 public void memoryBlockRenderingAdded(final IMemoryRendering rendering) { 434 435 Display.getDefault().asyncExec(new Runnable () { 436 public void run() { 437 438 if (isDisposed()) 439 return; 440 441 if (fAddedRenderings.contains(rendering)) 442 return; 443 444 IMemoryBlock memoryblk = rendering.getMemoryBlock(); 445 446 TabFolder tabFolder = (TabFolder) fTabFolderForMemoryBlock.get(memoryblk); 447 448 if (tabFolder == null) 449 { 450 tabFolder = createFolderForMemoryBlock(memoryblk); 451 } 452 453 if (tabFolder.getItemCount() >= 1) { 454 TabItem[] items = tabFolder.getItems(); 455 for (int i=0; i<items.length; i++) 456 { 457 TabItem item = items[i]; 459 if (item.getData() instanceof MemoryViewTab) { 460 MemoryViewTab viewTab = (MemoryViewTab) item.getData(); 461 if (viewTab.getRendering() instanceof CreateRendering) { 462 disposeTab(item); 463 } 464 } 465 } 466 } 467 468 if (tabFolder == fStackLayout.topControl) 469 { 470 if (getTopMemoryTab() != null) { 472 deactivateRendering(getTopMemoryTab()); 473 getTopMemoryTab().setEnabled(false); 474 } 475 } 476 fAddedRenderings.add(rendering); 477 TabItem tab = new TabItem(tabFolder, SWT.NULL); 478 479 MemoryViewTab viewTab = new MemoryViewTab(tab, rendering,getInstance()); 480 tabFolder.setSelection(tabFolder.indexOf(tab)); 481 482 if (tabFolder == fStackLayout.topControl) 483 { 484 setRenderingSelection(viewTab.getRendering()); 485 486 IMemoryViewTab top = getTopMemoryTab(); 488 if (top != null) 489 top.setEnabled(fVisible); 490 } 491 else 492 { 493 deactivateRendering(viewTab); 494 viewTab.setEnabled(false); 495 } 496 497 updateToolBarActionsEnablement(); 498 } 499 }); 500 } 501 502 505 public void memoryBlockRenderingRemoved(final IMemoryRendering rendering) { 506 final IMemoryBlock memory = rendering.getMemoryBlock(); 507 508 Display.getDefault().asyncExec(new Runnable () 510 { 511 public void run() 512 { 513 if (!fAddedRenderings.contains(rendering)) 514 return; 515 516 fAddedRenderings.remove(rendering); 517 518 TabFolder tabFolder = (TabFolder) fStackLayout.topControl; 519 520 if (tabFolder.isDisposed()) 521 return; 522 523 TabItem[] tabs = tabFolder.getItems(); 524 boolean foundTab = false; 525 for (int i = 0; i < tabs.length; i++) 526 { 527 IMemoryViewTab viewTab = (IMemoryViewTab) tabs[i].getData(); 528 529 if (tabs[i].isDisposed()) 530 continue; 531 532 533 if (viewTab.getRendering().getMemoryBlock() == memory) 534 { 535 if (viewTab.getRendering() == rendering) 536 { 537 foundTab = true; 538 disposeTab(tabs[i]); 539 break; 540 } 541 542 } 543 } 544 545 if (!foundTab) 549 { 550 Enumeration enumeration = fTabFolderForMemoryBlock.elements(); 551 while (enumeration.hasMoreElements()) 552 { 553 TabFolder otherTabFolder = (TabFolder) enumeration.nextElement(); 554 tabs = otherTabFolder.getItems(); 555 IMemoryViewTab viewTab = null; 556 for (int i = 0; i < tabs.length; i++) 557 { 558 viewTab = (IMemoryViewTab) tabs[i].getData(); 559 if (viewTab.getRendering().getMemoryBlock() == memory) 560 { 561 if (viewTab.getRendering() == rendering) 562 { 563 foundTab = true; 564 disposeTab(tabs[i]); 565 break; 566 } 567 } 568 } 569 } 570 } 571 IMemoryViewTab top = getTopMemoryTab(); 572 573 if (top != null) 575 setRenderingSelection(top.getRendering()); 576 else 577 { 578 if (tabFolder != fEmptyTabFolder) 579 { 580 IDebugTarget target = memory.getDebugTarget(); 581 582 if (!target.isDisconnected() && !target.isTerminated() && !isMeomryBlockRemoved(memory)) 584 { 585 TabItem newItem = new TabItem(tabFolder, SWT.NULL); 586 CreateRendering createRendering = new CreateRendering(getInstance()); 587 createRendering.init(getInstance(), memory); 588 589 MemoryViewTab viewTab = new MemoryViewTab(newItem, createRendering, getInstance()); 590 tabFolder.setSelection(0); 591 setRenderingSelection(viewTab.getRendering()); 592 } 593 } 594 } 595 596 updateToolBarActionsEnablement(); 597 } 598 }); 599 600 } 601 602 606 private boolean isMeomryBlockRemoved(IMemoryBlock memoryBlock) 607 { 608 IMemoryBlockRetrieval retrieval = getMemoryBlockRetrieval(memoryBlock); 609 IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval); 610 boolean removed = true; 611 612 for (int i=0; i<memoryBlocks.length; i++) 613 { 614 if (memoryBlocks[i] == memoryBlock) 615 removed = false; 616 } 617 618 return removed; 619 } 620 621 622 625 protected void setRenderingSelection(IMemoryRendering rendering) { 626 627 if (rendering != null) 628 { 629 fSelectionProvider.setSelection(new StructuredSelection(rendering)); 630 } 631 } 632 633 private void restoreViewTabs(IMemoryRendering[] renderings) 634 { 635 for (int i=0; i<renderings.length; i++) 636 { 637 memoryBlockRenderingAdded(renderings[i]); 638 } 639 } 640 641 private void handleDebugElementSelection(final IMemoryViewTab lastViewTab, final IDebugElement element) 642 { 643 IMemoryBlockRetrieval currentRetrieve = null; 645 646 TabFolder tabFolder = (TabFolder) fStackLayout.topControl; 648 649 IMemoryBlock currentBlock = (IMemoryBlock)fMemoryBlockFromTabFolder.get(tabFolder); 651 652 if (currentBlock != null) 653 { 654 currentRetrieve = (IMemoryBlockRetrieval)currentBlock.getAdapter(IMemoryBlockRetrieval.class); 655 656 if (currentRetrieve == null) 657 { 658 currentRetrieve = currentBlock.getDebugTarget(); 659 } 660 661 if (currentRetrieve != null && tabFolder != null) 663 { 664 fTabFolderForDebugView.put(currentRetrieve, tabFolder); 665 } 666 } 667 668 IMemoryBlockRetrieval retrieve = (IMemoryBlockRetrieval)element.getAdapter(IMemoryBlockRetrieval.class); 670 IDebugTarget debugTarget = element.getDebugTarget(); 671 672 if (retrieve == null) 674 retrieve = debugTarget; 675 676 if (retrieve != currentRetrieve) 679 { 680 TabFolder folder = (TabFolder)fTabFolderForDebugView.get(retrieve); 681 682 if (folder != null) 683 { 684 setTabFolder(folder); 685 fTabFolderForDebugView.put(retrieve, folder); 686 fViewPaneCanvas.layout(); 687 } 688 else 689 { 690 IMemoryBlock blocks[] = MemoryViewUtil.getMemoryBlockManager().getMemoryBlocks(retrieve); 693 694 if (blocks.length > 0) 695 { 696 handleMemoryBlockSelection(null, blocks[0]); 697 } 698 else 699 { 700 emptyFolder(); 701 fTabFolderForDebugView.put(retrieve, fEmptyTabFolder); 702 fViewPaneCanvas.layout(); 703 } 704 } 705 } 706 707 IMemoryViewTab newViewTab = getTopMemoryTab(); 709 710 if (lastViewTab != null && lastViewTab != newViewTab) 711 { 712 lastViewTab.setEnabled(false); 713 } 714 715 if (newViewTab != null) 716 { 717 if (!newViewTab.isEnabled()) 719 { 720 if (fVisible) 722 { 723 newViewTab.setEnabled(fVisible); 724 } 725 } 726 727 if (lastViewTab != newViewTab) 729 setRenderingSelection(newViewTab.getRendering()); 730 } 731 updateToolBarActionsEnablement(); 733 } 734 735 protected void addListeners() { 736 super.addListeners(); 737 738 fParent.getSite().getSelectionProvider().addSelectionChangedListener(this); 742 } 743 protected void removeListeners() { 744 super.removeListeners(); 745 fParent.getSite().getSelectionProvider().removeSelectionChangedListener(this); 746 } 747 748 751 public void widgetSelected(SelectionEvent e) { 752 753 if (getTopMemoryTab() == null) 754 return; 755 756 IMemoryRendering rendering = getTopMemoryTab().getRendering(); 757 758 if (rendering != null) 759 { 760 fSelectionProvider.setSelection(new StructuredSelection(rendering)); 761 } 762 763 } 764 765 768 public void widgetDefaultSelected(SelectionEvent e) { 769 } 770 771 public Object getCurrentSelection() { 772 if (getTopMemoryTab() != null) 773 if (getTopMemoryTab().getRendering() != null) 774 return getTopMemoryTab().getRendering(); 775 return null; 776 } 777 778 781 public IMemoryViewTab[] getAllViewTabs() { 782 783 TabFolder folder = (TabFolder) fStackLayout.topControl; 785 TabItem[] items = folder.getItems(); 786 787 IMemoryViewTab[] viewTabs = new IMemoryViewTab[folder.getItemCount()]; 788 789 for(int i=0; i<items.length; i++){ 790 viewTabs[i] = (IMemoryViewTab)items[i].getData(); 791 } 792 793 return viewTabs; 794 } 795 796 799 public void moveToTop(IMemoryViewTab viewTab) { 800 801 IMemoryViewTab lastViewTab = getTopMemoryTab(); 802 803 if (viewTab == lastViewTab) 804 return; 805 806 TabFolder folder = (TabFolder) fStackLayout.topControl; 808 TabItem[] items = folder.getItems(); 809 810 for (int i = 0; i < items.length; i++) { 811 IMemoryViewTab tab = 812 (IMemoryViewTab) items[i].getData(); 813 if (viewTab == tab) { 814 815 boolean isEnabled = lastViewTab.isEnabled(); 816 817 lastViewTab.setEnabled(false); 819 folder.setSelection(i); 820 821 setRenderingSelection(tab.getRendering()); 822 823 getTopMemoryTab().setEnabled(isEnabled && fVisible); 824 break; 825 } 826 } 827 } 828 829 public void restoreViewPane() { 830 831 833 ISelection selection = null; 834 if (fParent.getSite().getSelectionProvider() != null) 835 selection = fParent.getSite().getSelectionProvider().getSelection(); 836 837 IMemoryBlock memoryBlock = null; 838 if (selection != null) 839 { 840 memoryBlock = getMemoryBlock(selection); 841 } 842 843 if (memoryBlock == null) 844 { 845 selection = fSelectionProvider.getSelection(); 847 848 if (MemoryViewUtil.isValidSelection(selection)) 849 { 850 Object elem = ((IStructuredSelection)selection).getFirstElement(); 851 852 if (!(elem instanceof IMemoryBlock)) 853 return; 854 855 memoryBlock = (IMemoryBlock)elem; 856 } 857 } 858 859 if (memoryBlock == null) 860 { 861 IAdaptable context = DebugUITools.getDebugContext(); 863 if (context != null) 864 { 865 IMemoryBlockRetrieval retrieval = (IMemoryBlockRetrieval)context.getAdapter(IMemoryBlockRetrieval.class); 866 if (retrieval == null && context instanceof IDebugElement) 867 { 868 retrieval = ((IDebugElement)context).getDebugTarget(); 869 } 870 if (retrieval != null) 871 { 872 IMemoryBlock[] blocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval); 873 if (blocks.length > 0) 874 memoryBlock = blocks[0]; 875 } 876 } 877 } 878 879 if (memoryBlock != null) 880 { 881 if (!fTabFolderForMemoryBlock.containsKey(memoryBlock)) 882 { 883 TabFolder folder = new TabFolder(fViewPaneCanvas, SWT.NULL); 886 887 fTabFolderForMemoryBlock.put(memoryBlock, folder); 888 fMemoryBlockFromTabFolder.put(folder, memoryBlock); 889 setTabFolder((TabFolder)fTabFolderForMemoryBlock.get(memoryBlock)); 890 fTabFolderForDebugView.put(getMemoryBlockRetrieval(memoryBlock), fTabFolderForMemoryBlock.get(memoryBlock)); 891 fViewPaneCanvas.layout(); 892 fAddedMemoryBlocks.add(memoryBlock); 893 } 894 895 if (fTabFolderForMemoryBlock.containsKey(memoryBlock)) 896 { 897 TabFolder toDisplay = (TabFolder)fTabFolderForMemoryBlock.get(memoryBlock); 898 899 if (toDisplay != null) 900 { 901 setTabFolder(toDisplay); 902 fTabFolderForDebugView.put(getMemoryBlockRetrieval(memoryBlock), toDisplay); 903 fViewPaneCanvas.layout(); 904 905 IMemoryRendering[] renderings = fRenderingMgr.getRenderingsFromMemoryBlock(memoryBlock); 907 908 if (toDisplay.getItemCount() == 0 || (getTopMemoryTab().getRendering() instanceof CreateRendering)) 909 { 910 restoreViewTabs(renderings); 911 } 912 } 913 } 914 915 917 IMemoryViewTab top = getTopMemoryTab(); 918 919 if (top != null) 920 { 921 top.setEnabled(fVisible); 922 } 923 else 924 { 925 TabFolder folder = (TabFolder)fStackLayout.topControl; 926 if (folder != fEmptyTabFolder) 927 { 928 TabItem newItem = new TabItem(folder, SWT.NULL); 929 CreateRendering rendering = new CreateRendering(this); 930 rendering.init(getInstance(), memoryBlock); 931 new MemoryViewTab(newItem, rendering, this); 932 folder.setSelection(0); 933 setRenderingSelection(rendering); 934 } 935 } 936 } 937 } 938 939 public void dispose() { 940 fIsDisposed = true; 941 super.dispose(); 942 fAddMemoryRenderingAction.dispose(); 943 944 fTabFolderForMemoryBlock.clear(); 945 fTabFolderForMemoryBlock = null; 946 947 fMemoryBlockFromTabFolder.clear(); 948 fMemoryBlockFromTabFolder = null; 949 950 fRenderingMgr.dispose(); 951 fRenderingMgr = null; 952 953 fAddedMemoryBlocks.clear(); 954 fAddedRenderings.clear(); 955 } 956 957 public Control createViewPane(Composite parent, String paneId, String label) { 958 Control control = super.createViewPane(parent, paneId, label); 959 fRenderingMgr = new ViewPaneRenderingMgr(this); 960 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugUIConstants.PLUGIN_ID + ".MemoryRenderingView_context"); return control; 962 } 963 964 public IAction[] getActions() { 965 ArrayList actions = new ArrayList (); 966 967 if (fAddMemoryRenderingAction == null) 968 fAddMemoryRenderingAction = new AddMemoryRenderingAction(this); 969 actions.add(fAddMemoryRenderingAction); 970 971 if (fRemoveMemoryRenderingAction == null) 972 fRemoveMemoryRenderingAction = new RemoveMemoryRenderingAction(this); 973 974 fRemoveMemoryRenderingAction.setEnabled(false); 975 actions.add(fRemoveMemoryRenderingAction); 976 977 return (IAction[])actions.toArray(new IAction[actions.size()]); 978 } 979 980 protected void updateToolBarActionsEnablement() 982 { 983 IDebugTarget target = getSelectedDebugTarget(); 984 if (target != null) 985 { 986 ISelection selection = fSelectionProvider.getSelection(); 987 if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) 988 { 989 Object sel = ((IStructuredSelection)selection).getFirstElement(); 990 if (sel instanceof CreateRendering) 991 fRemoveMemoryRenderingAction.setEnabled(false); 992 else 993 fRemoveMemoryRenderingAction.setEnabled(true); 994 } 995 else 996 { 997 fRemoveMemoryRenderingAction.setEnabled(false); 998 } 999 } 1000 else 1001 { 1002 fRemoveMemoryRenderingAction.setEnabled(false); 1003 } 1004 } 1005 1006 private IDebugTarget getSelectedDebugTarget() 1007 { 1008 Object context = DebugUITools.getDebugContext(); 1009 if (context != null && context instanceof IDebugElement) 1010 { 1011 return ((IDebugElement)context).getDebugTarget(); 1012 } 1013 return null; 1014 } 1015 1018 protected void emptyFolder() { 1019 super.emptyFolder(); 1020 updateToolBarActionsEnablement(); 1021 fSelectionProvider.setSelection(AbstractMemoryViewPane.EMPTY); 1022 } 1023 1024 1027 public void addMemoryRendering(IMemoryRendering rendering) { 1028 1029 if (rendering == null) 1030 return; 1031 1032 memoryBlockRenderingAdded(rendering); 1033 fRenderingMgr.addMemoryBlockRendering(rendering); 1034 1035 } 1036 1037 1040 public void removeMemoryRendering(IMemoryRendering rendering) { 1041 1042 if (rendering == null) 1043 return; 1044 1045 memoryBlockRenderingRemoved(rendering); 1046 1047 if (fRenderingMgr != null) 1048 fRenderingMgr.removeMemoryBlockRendering(rendering); 1049 1050 } 1051 1052 private RenderingViewPane getInstance() 1053 { 1054 return this; 1055 } 1056 1057 private IMemoryBlock getMemoryBlock(ISelection selection) 1058 { 1059 if (!(selection instanceof IStructuredSelection)) 1060 return null; 1061 1062 if (selection.isEmpty() || ((IStructuredSelection)selection).size() > 1) 1064 { 1065 return null; 1066 } 1067 1068 Object elem = ((IStructuredSelection)selection).getFirstElement(); 1069 1070 if (elem instanceof IMemoryBlock) 1071 return (IMemoryBlock)elem; 1072 else if (elem instanceof IMemoryRendering) 1073 return ((IMemoryRendering)elem).getMemoryBlock(); 1074 else 1075 return null; 1076 } 1077 1078 private void deactivateRendering(IMemoryViewTab viewTab) 1079 { 1080 if (viewTab == null) 1081 return; 1082 1083 if (!viewTab.isDisposed()) 1084 { 1085 viewTab.getRendering().deactivated(); 1086 } 1087 } 1088 1089 1092 public IMemoryRenderingSite getMemoryRenderingSite() { 1093 return fRenderingSite; 1094 } 1095 1096 1099 public String getId() { 1100 return getPaneId(); 1101 } 1102 1103 1106 public IMemoryRendering[] getRenderings() { 1107 return fRenderingMgr.getRenderings(); 1108 } 1109 1110 1113 public IMemoryRendering getActiveRendering() { 1114 if (getTopMemoryTab() == null) 1115 return null; 1116 return getTopMemoryTab().getRendering(); 1117 } 1118 1119 1126 public void resetRenderings(IMemoryBlock memoryBlock, boolean resetVisible) 1127 { 1128 if (resetVisible && !isVisible()) 1131 return; 1132 1133 if(resetVisible) 1134 { 1135 IMemoryRendering rendering = getActiveRendering(); 1136 if (rendering != null) 1137 { 1138 if (rendering.getMemoryBlock() == memoryBlock) 1139 { 1140 if (rendering instanceof IResettableMemoryRendering) 1141 { 1142 IResettableMemoryRendering resettableRendering = (IResettableMemoryRendering)rendering; 1143 try { 1144 resettableRendering.resetRendering(); 1145 } catch (DebugException e) { 1146 } 1150 } 1151 } 1152 } 1153 } 1154 else 1155 { 1156 IMemoryRendering[] renderings = fRenderingMgr.getRenderingsFromMemoryBlock(memoryBlock); 1158 1159 IMemoryRendering originalProvider = null; 1161 IMemoryRenderingSynchronizationService service = getMemoryRenderingSite().getSynchronizationService(); 1162 if (service != null) 1163 originalProvider = service.getSynchronizationProvider(); 1164 1165 for (int i=0; i<renderings.length; i++) 1166 { 1167 if (renderings[i] instanceof IResettableMemoryRendering) 1168 { 1169 try { 1170 1171 if (service != null) 1183 service.setSynchronizationProvider(renderings[i]); 1184 ((IResettableMemoryRendering)renderings[i]).resetRendering(); 1185 } catch (DebugException e) { 1186 } 1190 } 1191 } 1192 1193 if (service != null) 1195 service.setSynchronizationProvider(originalProvider); 1196 } 1197 } 1198 1199 private boolean isDisposed() 1200 { 1201 return fIsDisposed; 1202 } 1203 1204 public void contextActivated(final ISelection selection) { 1205 1206 UIJob job = new UIJob("contextActivated"){ public IStatus runInUIThread(IProgressMonitor monitor) 1208 { 1209 if (isDisposed()) 1210 return Status.OK_STATUS; 1211 1212 IMemoryViewTab lastViewTab = getTopMemoryTab(); 1213 1214 if (MemoryViewUtil.isValidSelection(selection)) 1215 { 1216 if (!(selection instanceof IStructuredSelection)) 1217 return Status.OK_STATUS; 1218 1219 Object elem = ((IStructuredSelection)selection).getFirstElement(); 1220 1221 if (elem instanceof IDebugElement) 1222 { 1223 handleDebugElementSelection(lastViewTab, (IDebugElement)elem); 1224 } 1225 } 1226 else 1227 { 1228 if (lastViewTab != null) 1229 lastViewTab.setEnabled(false); 1230 1231 if (fStackLayout.topControl != fEmptyTabFolder) 1232 emptyFolder(); 1233 1234 } 1235 return Status.OK_STATUS; 1236 }}; 1237 job.setSystem(true); 1238 job.schedule(); 1239 } 1240 1241 1244 private TabFolder createFolderForMemoryBlock(IMemoryBlock memory) { 1245 TabFolder folder = new TabFolder(fViewPaneCanvas, SWT.NULL); 1246 1247 fTabFolderForMemoryBlock.put(memory, folder); 1248 fMemoryBlockFromTabFolder.put(folder, memory); 1249 fTabFolderForDebugView.put(getMemoryBlockRetrieval(memory), folder); 1250 1251 IMemoryRendering[] renderings = fRenderingMgr.getRenderingsFromMemoryBlock(memory); 1253 if (renderings.length == 0) 1254 { 1255 TabItem newItem = new TabItem(folder, SWT.NULL); 1256 CreateRendering rendering = new CreateRendering(getInstance()); 1257 rendering.init(getInstance(), memory); 1258 new MemoryViewTab(newItem, rendering, getInstance()); 1259 folder.setSelection(0); 1260 } 1261 1262 return folder; 1263 } 1264 1265 1268 public void debugContextChanged(DebugContextEvent event) { 1269 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 1270 contextActivated(event.getContext()); 1271 } 1272 1273 } 1274} 1275 | Popular Tags |