1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.model.IDebugElement; 15 import org.eclipse.debug.core.model.IDebugTarget; 16 import org.eclipse.debug.core.model.IMemoryBlock; 17 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 18 import org.eclipse.debug.internal.ui.DebugUIMessages; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.ui.memory.IMemoryRendering; 21 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer; 22 import org.eclipse.debug.ui.memory.IMemoryRenderingType; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.PlatformUI; 25 26 29 public class AddMemoryRenderingAction extends AddMemoryBlockAction { 30 31 private IMemoryRenderingContainer fContainer; 32 33 public AddMemoryRenderingAction(IMemoryRenderingContainer container) 34 { 35 super(DebugUIMessages.AddMemoryRenderingAction_Add_renderings, AS_PUSH_BUTTON, container.getMemoryRenderingSite()); 36 setToolTipText(DebugUIMessages.AddMemoryRenderingAction_Add_renderings); 37 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, DebugUIPlugin.getUniqueIdentifier() + ".AddRenderingContextAction_context"); fContainer = container; 39 } 40 41 44 public void run() { 45 46 Shell shell = DebugUIPlugin.getShell(); 48 49 IDebugElement elem = getDebugElement(fCurrentContext); 50 51 if (elem != null) 52 { 53 AddMemoryRenderingDialog dialog = new AddMemoryRenderingDialog(shell, fSite); 54 dialog.open(); 55 56 Object [] renderings = dialog.getResult(); 58 59 IMemoryBlock blk = dialog.getMemoryBlock(); 60 61 if (blk == null) 62 return; 63 64 IDebugTarget debugTarget = elem.getDebugTarget(); 66 IMemoryBlockRetrieval standardMemRetrieval = (IMemoryBlockRetrieval)elem.getAdapter(IMemoryBlockRetrieval.class); 67 68 if (standardMemRetrieval == null) 69 { 70 standardMemRetrieval = debugTarget; 71 } 72 73 if (standardMemRetrieval == null) 74 return; 75 76 for (int i=0; i<renderings.length; i++) 78 { 79 if (renderings[i] instanceof IMemoryRenderingType) 80 { 81 try { 82 IMemoryRendering rendering = ((IMemoryRenderingType)renderings[i]).createRendering(); 83 if (rendering != null) 84 { 85 rendering.init(fContainer, blk); 86 fContainer.addMemoryRendering(rendering); 87 } 88 } catch (CoreException e) { 89 MemoryViewUtil.openError(DebugUIMessages.AddMemoryRenderingAction_Add_rendering_failed, DebugUIMessages.AddMemoryRenderingAction_Unable_to_add_selected_renderings, e); 90 } 91 } 92 } 93 } 94 } 95 96 private IDebugElement getDebugElement(Object elem) 97 { 98 if (!(elem instanceof IDebugElement)) 100 return null; 101 return (IDebugElement)elem; 102 } 103 } 104 | Popular Tags |