1 11 12 package org.eclipse.debug.internal.ui.views.memory; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.internal.ui.actions.ActionMessages; 19 import org.eclipse.debug.ui.DebugUITools; 20 import org.eclipse.debug.ui.actions.IAddMemoryBlocksTarget; 21 import org.eclipse.debug.ui.memory.IMemoryRenderingSite; 22 23 29 public class RetargetAddMemoryBlockAction extends AddMemoryBlockAction { 30 31 public RetargetAddMemoryBlockAction(IMemoryRenderingSite site) 32 { 33 super(site); 34 } 35 36 public RetargetAddMemoryBlockAction(IMemoryRenderingSite site, boolean addDefaultRenderings) 37 { 38 super(site, addDefaultRenderings); 39 } 40 41 public RetargetAddMemoryBlockAction(String text, int style, IMemoryRenderingSite site) 42 { 43 super(text, style, site); 44 } 45 46 public void run() { 47 Object debugContext = DebugUITools.getDebugContext(); 49 IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext); 50 51 if (target != null) 52 { 53 try { 54 if (target.supportsAddMemoryBlocks(getMemoryView())) 55 { 56 target.addMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection()); 57 } 58 else 59 super.run(); 60 } catch (CoreException e) { 61 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.RetargetAddMemoryBlockAction_0, ActionMessages.RetargetAddMemoryBlockAction_1, e); 62 } 63 } 64 else 65 { 66 super.run(); 67 } 68 } 69 70 protected void updateAction(Object debugContext) { 71 72 try { 73 IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext); 74 75 if (target != null) 76 { 77 if (target.supportsAddMemoryBlocks(getMemoryView())) 78 { 79 if (getMemoryView().getSite().getSelectionProvider() != null) 80 setEnabled(target.canAddMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection())); 81 else 82 super.updateAction(debugContext); 83 } 84 else 85 super.updateAction(debugContext); 86 } 87 else 88 { 89 super.updateAction(debugContext); 90 } 91 } catch (CoreException e) { 92 DebugUIPlugin.log(e); 93 } 94 } 95 96 private IAddMemoryBlocksTarget getAddMemoryBlocksTarget(Object debugContext) 97 { 98 IMemoryBlockRetrieval standardMemRetrieval = MemoryViewUtil.getMemoryBlockRetrieval(debugContext); 99 100 if (standardMemRetrieval == null) 101 return null; 102 103 IAddMemoryBlocksTarget target = null; 104 105 if (standardMemRetrieval instanceof IAddMemoryBlocksTarget) 106 { 107 target = (IAddMemoryBlocksTarget) standardMemRetrieval; 108 } 109 else if (standardMemRetrieval instanceof IAdaptable) 110 { 111 target = (IAddMemoryBlocksTarget)((IAdaptable)standardMemRetrieval).getAdapter(IAddMemoryBlocksTarget.class); 112 } 113 return target; 114 } 115 } 116 | Popular Tags |