1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import java.math.BigInteger ; 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.IMemoryBlockManager; 23 import org.eclipse.debug.core.model.IDebugElement; 24 import org.eclipse.debug.core.model.IDebugTarget; 25 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 26 import org.eclipse.debug.internal.ui.DebugUIPlugin; 27 import org.eclipse.jface.dialogs.MessageDialog; 28 import org.eclipse.jface.viewers.ISelection; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.progress.UIJob; 33 34 39 public class MemoryViewUtil { 40 41 public static final int[] ignoreKeyEvents = 42 { 43 SWT.ARROW_UP, 44 SWT.ARROW_DOWN, 45 SWT.ARROW_LEFT, 46 SWT.ARROW_RIGHT, 47 SWT.PAGE_UP, 48 SWT.PAGE_DOWN, 49 SWT.HOME, 50 SWT.END, 51 SWT.INSERT, 52 SWT.F1, 53 SWT.F2, 54 SWT.F3, 55 SWT.F4, 56 SWT.F5, 57 SWT.F6, 58 SWT.F7, 59 SWT.F8, 60 SWT.F9, 61 SWT.F10, 62 SWT.F11, 63 SWT.F12, 64 SWT.F13, 65 SWT.F14, 66 SWT.F15, 67 SWT.HELP, 68 SWT.CAPS_LOCK, 69 SWT.NUM_LOCK, 70 SWT.SCROLL_LOCK, 71 SWT.PAUSE, 72 SWT.BREAK, 73 SWT.PRINT_SCREEN, 74 SWT.ESC, 75 SWT.CTRL, 76 SWT.ALT, 77 SWT.SHIFT 78 }; 79 80 public static ArrayList MEMORY_BLOCKS_HISTORY = new ArrayList (); 81 82 86 static public boolean isValidSelection(ISelection selection) { 87 88 if (!(selection instanceof IStructuredSelection)) 89 return false; 90 91 if (selection.isEmpty() || ((IStructuredSelection)selection).size() > 1) 93 { 94 return false; 95 } 96 97 Object elem = ((IStructuredSelection)selection).getFirstElement(); 98 99 return isValidContext(elem); 100 } 101 102 103 107 public static boolean isValidContext(Object elem) { 108 if (!(elem instanceof IDebugElement)) 110 return false; 111 112 IDebugTarget debugTarget = ((IDebugElement)elem).getDebugTarget(); 113 IMemoryBlockRetrieval memRetrieval =(IMemoryBlockRetrieval) ((IDebugElement)elem).getAdapter(IMemoryBlockRetrieval.class); 114 115 if (memRetrieval == null) 116 { 117 memRetrieval = debugTarget; 119 } 120 121 if (debugTarget == null) 122 return false; 123 124 if (debugTarget.isTerminated() || debugTarget.isDisconnected()) 126 return false; 127 128 if (memRetrieval.supportsStorageRetrieval()) { 129 return true; 130 } 131 132 return false; 133 } 134 135 136 142 static public void openError (final String title, final String message, final Exception e) 143 { 144 UIJob uiJob = new UIJob("open error"){ 146 public IStatus runInUIThread(IProgressMonitor monitor) { 147 String detail = ""; if (e != null) 150 detail = e.getMessage(); 151 152 Shell shell = DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); 153 154 MessageDialog.openError( 155 shell, 156 title, 157 message + "\n" + detail); return Status.OK_STATUS; 159 }}; 160 uiJob.setSystem(true); 161 uiJob.schedule(); 162 } 163 164 static IMemoryBlockManager getMemoryBlockManager() 165 { 166 return DebugPlugin.getDefault().getMemoryBlockManager(); 167 } 168 169 static public boolean isLinuxGTK() 170 { 171 String ws = Platform.getWS(); 172 return ws.equals(Platform.WS_GTK); 173 } 174 175 181 public static boolean isValidEditEvent(int event) { 182 for (int i = 0; i < MemoryViewUtil.ignoreKeyEvents.length; i++) { 183 if (event == MemoryViewUtil.ignoreKeyEvents[i]) 184 return false; 185 } 186 return true; 187 } 188 189 public static BigInteger alignToBoundary(BigInteger integer, int numberOfUnitsPerLine) 190 { 191 BigInteger [] result = integer.divideAndRemainder(BigInteger.valueOf(numberOfUnitsPerLine)); 192 integer = integer.subtract(result[1]); 193 return integer; 194 } 195 196 public static void addHistory(String expression) 197 { 198 if (!MEMORY_BLOCKS_HISTORY.contains(expression)) 199 MEMORY_BLOCKS_HISTORY.add(0, expression); 200 201 if (MEMORY_BLOCKS_HISTORY.size() > 5) 202 MEMORY_BLOCKS_HISTORY.remove(MEMORY_BLOCKS_HISTORY.size()-1); 203 } 204 205 public static String [] getHistory() 206 { 207 return (String [])MEMORY_BLOCKS_HISTORY.toArray(new String [MEMORY_BLOCKS_HISTORY.size()]); 208 } 209 210 public static IMemoryBlockRetrieval getMemoryBlockRetrieval(Object object) 211 { 212 IMemoryBlockRetrieval retrieval = null; 213 214 if (object instanceof IAdaptable) 215 { 216 IAdaptable adaptable = (IAdaptable)object; 217 retrieval = (IMemoryBlockRetrieval)adaptable.getAdapter(IMemoryBlockRetrieval.class); 218 } 219 220 if (retrieval == null && object instanceof IDebugElement) 221 { 222 IDebugElement de = (IDebugElement)object; 223 retrieval = de.getDebugTarget(); 224 } 225 226 return retrieval; 227 } 228 } 229 | Popular Tags |