1 11 12 package org.eclipse.debug.internal.ui.views.memory; 13 14 import java.math.BigInteger ; 15 import org.eclipse.debug.core.DebugException; 16 import org.eclipse.debug.core.model.IMemoryBlock; 17 import org.eclipse.debug.internal.core.memory.IExtendedMemoryBlock; 18 import org.eclipse.debug.internal.core.memory.MemoryByte; 19 import org.eclipse.debug.internal.ui.DebugUIMessages; 20 import org.eclipse.jface.viewers.IBaseLabelProvider; 21 import org.eclipse.jface.viewers.ICellModifier; 22 import org.eclipse.swt.widgets.TableItem; 23 24 27 public class MemoryViewCellModifier implements ICellModifier 28 { 29 private static final String PREFIX = "MemoryViewCellModifier."; public static final String TITLE = PREFIX + "failure_title"; public static final String FAILED = PREFIX + "failed"; public static final String DATA_IS_INVALID = PREFIX + "data_is_invalid"; public static final String DATA_IS_TOO_LONG = PREFIX + "data_is_too_long"; 35 private boolean editActionInvoked = false; 36 private ITableMemoryViewTab fViewTab; 37 38 public MemoryViewCellModifier(ITableMemoryViewTab viewTab) 39 { 40 fViewTab = viewTab; 41 } 42 43 46 public boolean canModify(Object element, String property) 47 { 48 boolean canModify = true; 49 try 50 { 51 if (!(element instanceof MemoryViewLine)) 52 return false; 53 54 if (!editActionInvoked) 55 return false; 56 57 if (fViewTab == null) 58 return false; 59 60 if (fViewTab.getMemoryBlock().supportsValueModification() == false) 61 { 62 return false; 63 } 64 65 MemoryViewLine line = (MemoryViewLine)element; 66 if (MemoryViewLine.P_ADDRESS.equals(property)) 67 return false; 68 else 69 { 70 int offset = Integer.valueOf(property, 16).intValue(); 71 int end = offset + fViewTab.getColumnSize(); 72 73 74 for (int i=offset; i<end; i++) 75 { 76 MemoryByte oneByte = line.getByte(i); 77 if ((oneByte.flags & MemoryByte.READONLY) == MemoryByte.READONLY) 80 { 81 canModify = false; 82 } 83 } 84 return canModify; 85 } 86 } 87 catch (NumberFormatException e) 88 { 89 canModify = false; 90 return canModify; 91 } 92 } 93 94 97 public Object getValue(Object element, String property) 98 { 99 101 if (!(element instanceof MemoryViewLine)) 102 return null; 103 104 MemoryViewLine line = (MemoryViewLine)element; 105 try 106 { 107 if (MemoryViewLine.P_ADDRESS.equals(property)) 108 return line.getAddress(); 109 else 110 { 111 int offset = Integer.valueOf(property, 16).intValue(); 112 int end = offset + fViewTab.getColumnSize(); 113 114 115 MemoryByte[] memory = line.getBytes(offset, end); 117 118 IBaseLabelProvider labelProvider = ((MemoryViewTab)fViewTab).getTableViewer().getLabelProvider(); 119 if(labelProvider instanceof AbstractTableViewTabLabelProvider) 120 { 121 122 if (line.isAvailable(offset, end)) 123 { 124 offset = Integer.valueOf(property, 16).intValue(); 126 AbstractMemoryRenderer renderer = ((AbstractTableViewTabLabelProvider)labelProvider).getRenderer(); 127 128 BigInteger address = new BigInteger (((MemoryViewLine)element).getAddress(), 16); 129 address = address.add(BigInteger.valueOf(offset)); 130 131 return renderer.getString(fViewTab.getRenderingId(), address, memory, line.getPaddedString()); 132 } 133 else 134 { 135 return line.getPaddedString(offset, end); 137 } 138 } 139 140 return ""; } 142 } 143 catch (NumberFormatException e) 144 { 145 return "00"; } 147 } 148 149 152 public void modify(Object element, String property, Object value) 153 { 154 MemoryViewLine line = null; 155 if (!(element instanceof MemoryViewLine)) 156 { 157 line = (MemoryViewLine)((TableItem)element).getData(); 158 } 159 else 160 { 161 line = (MemoryViewLine)element; 162 } 163 164 IMemoryBlock memory = fViewTab.getMemoryBlock(); 166 167 int lineOffset = Integer.valueOf(property, 16).intValue(); 168 169 long offset = getOffset(memory, line.getAddress(), lineOffset); 170 171 if (!(value instanceof String )) 173 return; 174 175 if (!(fViewTab instanceof MemoryViewTab)) 176 return; 177 178 try 179 { 180 byte[] bytes = null; 181 182 String oldValue = (String )getValue(line, property); 183 184 if (!oldValue.equals(value)) 185 { 186 IBaseLabelProvider labelProvider = ((MemoryViewTab)fViewTab).getTableViewer().getLabelProvider(); 188 if(labelProvider instanceof AbstractTableViewTabLabelProvider) 189 { 190 int offsetToLine = Integer.valueOf(property, 16).intValue(); 191 int end = offsetToLine + fViewTab.getColumnSize(); 192 193 MemoryByte[] oldArray= line.getBytes(offsetToLine, end); 194 195 BigInteger address = new BigInteger (line.getAddress(), 16); 196 address = address.add(BigInteger.valueOf(offsetToLine)); 197 198 bytes = ((AbstractTableViewTabLabelProvider)labelProvider).getRenderer().getBytes(fViewTab.getRenderingId(), address, oldArray, (String )value); 199 200 if (bytes == null) 201 return; 202 203 if (bytes.length == 0) 204 return; 205 } 206 else 207 return; 208 } 209 else 210 { 211 return; 213 } 214 215 216 memory.setValue(offset, bytes); 217 } 218 catch (DebugException e) 219 { 220 MemoryViewUtil.openError(DebugUIMessages.getString(TITLE), DebugUIMessages.getString(FAILED), e); 221 } 222 catch(NumberFormatException e) 223 { 224 MemoryViewUtil.openError(DebugUIMessages.getString(TITLE), 225 DebugUIMessages.getString(FAILED) + "\n" + DebugUIMessages.getString(DATA_IS_INVALID), null); } 227 228 } 229 230 private long getOffset(IMemoryBlock memory, String lineAddress, int lineOffset) { 231 232 BigInteger lineAddr = new BigInteger (lineAddress, 16); 233 BigInteger memoryAddr; 234 235 if (memory instanceof IExtendedMemoryBlock) 236 { 237 memoryAddr = ((IExtendedMemoryBlock)memory).getBigBaseAddress(); 238 } 239 else 240 { 241 memoryAddr = BigInteger.valueOf(memory.getStartAddress()); 242 } 243 244 if (memoryAddr == null) 245 memoryAddr = new BigInteger ("0"); 247 long offset = lineAddr.subtract(memoryAddr).longValue(); 248 249 return offset + lineOffset; 250 } 251 252 253 254 257 public void setEditActionInvoked(boolean editActionInvoked) { 258 this.editActionInvoked = editActionInvoked; 259 } 260 261 } 262 | Popular Tags |