1 11 package org.eclipse.debug.internal.ui.views.memory.renderings; 12 13 import java.math.BigInteger ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.debug.core.model.IMemoryBlock; 20 import org.eclipse.debug.core.model.IMemoryBlockExtension; 21 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTableRendering; 22 import org.eclipse.debug.internal.ui.memory.provisional.MemoryViewPresentationContext; 23 import org.eclipse.debug.internal.ui.viewers.TableUpdatePolicy; 24 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 25 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 26 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; 27 import org.eclipse.debug.ui.memory.IMemoryRendering; 28 import org.eclipse.ui.progress.UIJob; 29 30 36 public class AsyncTableRenderingUpdatePolicy extends TableUpdatePolicy 37 { 38 public void modelChanged(IModelDelta node, IModelProxy proxy) { 39 40 AbstractVirtualContentTableModel model = getTableViewer().getVirtualContentModel(); 42 43 if (model != null) 44 { 45 IContentChangeComputer computer = null; 46 if (model instanceof IContentChangeComputer) 47 computer = (IContentChangeComputer)model; 48 49 clearCache(computer); 50 51 if (!containsEvent(node)) 52 { 53 return; 54 } 55 56 if (node.getElement() instanceof IMemoryBlock && (node.getFlags() & IModelDelta.CONTENT) != 0) 57 { 58 if (computer != null && getTableViewer() != null) 59 { 60 if (!getTableViewer().getRendering().isDisplayingError()) 62 { 63 computer.cache(model.getElements()); 65 } 66 } 67 68 notifyRendering(node, proxy); 72 handleMemoryBlockChanged((IMemoryBlock)node.getElement(), node); 73 return; 74 75 } 76 else if (node.getElement() instanceof IMemoryBlock && (node.getFlags() & IModelDelta.STATE) != 0) 77 { 78 handleMemoryBlockChanged((IMemoryBlock)node.getElement(), node); 81 return; 82 } 83 } 84 85 super.modelChanged(node, proxy); 86 } 87 88 91 protected void clearCache(IContentChangeComputer computer) { 92 if (computer != null) 93 computer.clearCache(); 94 } 95 96 private void notifyRendering(IModelDelta node, IModelProxy proxy) { 97 if (getTableViewer() != null) 98 { 99 IModelChangedListener listener = (IModelChangedListener)getTableViewer().getRendering().getAdapter(IModelChangedListener.class); 100 if (listener != null) 101 listener.modelChanged(node, proxy); 102 } 103 } 104 105 protected void handleMemoryBlockChanged(IMemoryBlock mb, IModelDelta delta) 106 { 107 try { 108 if (getViewer().getPresentationContext() instanceof MemoryViewPresentationContext) 109 { 110 MemoryViewPresentationContext context = (MemoryViewPresentationContext)getViewer().getPresentationContext(); 111 final AbstractAsyncTableRendering rendering = getTableRendering(context); 112 if (rendering != null) 113 { 114 if ((delta.getFlags() & IModelDelta.CONTENT) != 0) 115 { 116 TableRenderingContentDescriptor descriptor = (TableRenderingContentDescriptor)rendering.getAdapter(TableRenderingContentDescriptor.class); 117 118 if (descriptor != null) 119 { 120 final BigInteger address = getMemoryBlockBaseAddress(mb); 121 if (!descriptor.isMemoryBlockBaseAddressInitialized() || !address.equals(descriptor.getContentBaseAddress())) 122 { 123 descriptor.updateContentBaseAddress(); 124 UIJob job = new UIJob("go to address"){ 126 public IStatus runInUIThread(IProgressMonitor monitor) { 127 try { 128 rendering.goToAddress(address); 129 } catch (DebugException e) { 130 if (getTableViewer() != null) 131 getTableViewer().handlePresentationFailure(null, e.getStatus()); 132 } 133 return Status.OK_STATUS; 134 }}; 135 job.setSystem(true); 136 job.schedule(); 137 } 138 else 139 { 140 rendering.refresh(); 141 } 142 } 143 } 144 else 145 { 146 rendering.updateLabels(); 147 } 148 } 149 } 150 } catch (DebugException e) { 151 if (getTableViewer() != null) 152 getTableViewer().handlePresentationFailure(null, e.getStatus()); 153 } 154 } 155 156 private BigInteger getMemoryBlockBaseAddress(IMemoryBlock mb) throws DebugException 157 { 158 if (mb instanceof IMemoryBlockExtension) 159 return ((IMemoryBlockExtension)mb).getBigBaseAddress(); 160 else 161 return BigInteger.valueOf(mb.getStartAddress()); 162 } 163 164 private AsyncTableRenderingViewer getTableViewer() 165 { 166 if (getViewer() instanceof AsyncTableRenderingViewer) 167 return (AsyncTableRenderingViewer)getViewer(); 168 return null; 169 } 170 171 private boolean containsEvent(IModelDelta delta) 172 { 173 if (getViewer().getPresentationContext() instanceof MemoryViewPresentationContext) 174 { 175 MemoryViewPresentationContext context = (MemoryViewPresentationContext) getViewer().getPresentationContext(); 176 if (context.getRendering() instanceof AbstractAsyncTableRendering) 177 { 178 AbstractAsyncTableRendering rendering = (AbstractAsyncTableRendering)context.getRendering(); 179 if (!rendering.isVisible()) 180 return false; 181 } 182 } 183 return true; 184 } 185 186 protected AbstractAsyncTableRendering getTableRendering(MemoryViewPresentationContext context) 187 { 188 IMemoryRendering memRendering = context.getRendering(); 189 if (memRendering != null && memRendering instanceof AbstractAsyncTableRendering) 190 { 191 return (AbstractAsyncTableRendering)memRendering; 192 } 193 return null; 194 } 195 } | Popular Tags |