1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.model.IValue; 16 import org.eclipse.debug.ui.DebugUITools; 17 import org.eclipse.debug.ui.IDebugModelPresentation; 18 import org.eclipse.debug.ui.IDebugUIConstants; 19 import org.eclipse.debug.ui.IValueDetailListener; 20 import org.eclipse.jdt.debug.core.IJavaObject; 21 import org.eclipse.jdt.debug.core.IJavaThread; 22 import org.eclipse.jdt.internal.debug.ui.ImageDescriptorRegistry; 23 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 24 import org.eclipse.jdt.internal.debug.ui.JDIImageDescriptor; 25 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages; 26 import org.eclipse.jface.resource.ImageDescriptor; 27 import org.eclipse.jface.viewers.LabelProvider; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.ui.IEditorInput; 30 31 34 public class MonitorModelPresentation extends LabelProvider implements IDebugModelPresentation { 35 36 protected ImageDescriptorRegistry fDebugImageRegistry= JDIDebugUIPlugin.getImageDescriptorRegistry(); 37 38 41 public void computeDetail(IValue value, IValueDetailListener listener) { 42 } 43 44 47 public String getText(Object item) { 48 49 if (item instanceof DeadLocksViewContentProvider.ContentThreadWrapper) { 50 return getThreadDeadLockText((DeadLocksViewContentProvider.ContentThreadWrapper)item); 51 } else if (item instanceof DeadLocksViewContentProvider.ContentMonitorWrapper) { 52 StringBuffer res= new StringBuffer (); 53 res.append(((DeadLocksViewContentProvider.ContentMonitorWrapper)item).fMonitor.toString()); 54 res.append(MonitorMessages.getString("MonitorModelPresentation._owned_by..._1")); return res.toString(); 56 } else if (item instanceof IJavaObject) { 57 return getMonitorText((IJavaObject)item); 58 } else if (item instanceof IJavaThread) { 59 return getThreadText((IJavaThread)item); 60 } else if (item instanceof ThreadsViewContentProvider.MonitorWrapper) { 61 return getMonitorWrapperText((ThreadsViewContentProvider.MonitorWrapper)item); 62 } else if (item instanceof MonitorsViewContentProvider.ThreadWrapper) { 63 return getThreadWrapperMonitorText((MonitorsViewContentProvider.ThreadWrapper)item); 64 } else if (item instanceof ThreadsViewContentProvider.ThreadWrapper) { 65 return getThreadWrapperThreadText((ThreadsViewContentProvider.ThreadWrapper)item); 66 } else { 67 return MonitorMessages.getString("MonitorModelPresentation.unsuported_type_1"); } 69 } 70 71 74 protected String getThreadDeadLockText(DeadLocksViewContentProvider.ContentThreadWrapper thread){ 75 StringBuffer res= new StringBuffer (); 76 try{ 77 res.append(thread.fThread.getName()); 78 } catch(DebugException e){ 79 } 80 81 if(thread.caughtInADeadLock){ 82 res.append(MonitorMessages.getString("MonitorModelPresentation._(caught_in_the_deadlock)_2")); } else { 84 res.append(MonitorMessages.getString("MonitorModelPresentation._waiting_for..._2")); } 86 return res.toString(); 87 } 88 89 92 protected String getMonitorText(IJavaObject monitor) { 93 return monitor.toString(); 94 } 95 96 99 protected String getMonitorWrapperText(ThreadsViewContentProvider.MonitorWrapper monitor) { 100 StringBuffer res= new StringBuffer (monitor.monitor.toString()); 101 if(monitor.state==ThreadsViewContentProvider.MonitorWrapper.OWNED_MONITOR) { 102 res.append(MonitorMessages.getString("MonitorModelPresentation._(owned)_4")); } else if(monitor.state==ThreadsViewContentProvider.MonitorWrapper.CONTENDED_MONITOR) { 104 res.append(MonitorMessages.getString("MonitorModelPresentation._(contended)_5")); } 106 return res.toString(); 107 } 108 109 112 protected String getThreadWrapperThreadText(ThreadsViewContentProvider.ThreadWrapper thread) { 113 StringBuffer res= new StringBuffer (); 114 try{ 115 res.append(thread.thread.getName()); 116 } catch(DebugException e){ 117 } 118 119 if(thread.isCaughtInDeadlock) { 120 res.append(MonitorMessages.getString("MonitorModelPresentation._(caught_in_a_deadlock)_6")); } 122 return res.toString(); 123 } 124 125 128 protected String getThreadWrapperMonitorText(MonitorsViewContentProvider.ThreadWrapper thread) { 129 StringBuffer res= new StringBuffer (); 130 try{ 131 res.append(thread.thread.getName()); 132 } catch(DebugException e){ 133 } 134 135 if(thread.state == MonitorsViewContentProvider.ThreadWrapper.OWNING_THREAD) { 136 res.append(MonitorMessages.getString("MonitorModelPresentation._(owning)_7")); } else if(thread.state == MonitorsViewContentProvider.ThreadWrapper.IN_CONTENTION_FOR_MONITOR) { 138 res.append(MonitorMessages.getString("MonitorModelPresentation._(contending)_8")); } 140 return res.toString(); 141 } 142 143 146 protected String getThreadText(IJavaThread thread){ 147 StringBuffer res = new StringBuffer (); 148 try{ 149 res.append(thread.getName()); 150 } catch(DebugException e){ 151 } 152 return res.toString(); 153 } 154 155 160 public Image getImage(Object item) { 161 162 if (item instanceof ThreadsViewContentProvider.ThreadWrapper) { 163 return getThreadWrapperThreadImage(((ThreadsViewContentProvider.ThreadWrapper)item).thread); 164 } else if (item instanceof ThreadsViewContentProvider.MonitorWrapper) { 165 ThreadsViewContentProvider.MonitorWrapper monitorWrapper= (ThreadsViewContentProvider.MonitorWrapper)item; 166 JDIImageDescriptor descriptor= null; 167 int flags= computeMonitorAdornmentFlags(monitorWrapper); 168 descriptor= new JDIImageDescriptor(JavaDebugImages.DESC_OBJ_MONITOR, flags); 169 return fDebugImageRegistry.get(descriptor); 170 } else if (item instanceof MonitorsViewContentProvider.ThreadWrapper) { 171 MonitorsViewContentProvider.ThreadWrapper threadWrapper= (MonitorsViewContentProvider.ThreadWrapper)item; 172 JDIImageDescriptor descriptor= null; 173 int flags= computeThreadAdornmentFlags(threadWrapper); 174 if (threadWrapper.thread.isSuspended()) { 175 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED), flags); 176 } else { 177 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING), flags); 178 } 179 return fDebugImageRegistry.get(descriptor); 180 } else if (item instanceof IJavaObject) { 181 return getMonitorImage(); 182 } else if (item instanceof DeadLocksViewContentProvider.ContentMonitorWrapper) { 183 return getMonitorImage(); 184 185 } else if (item instanceof DeadLocksViewContentProvider.ContentThreadWrapper ) { 186 return getThreadWrapperThreadImage(((DeadLocksViewContentProvider.ContentThreadWrapper)item).fThread); 187 } 188 189 return null; 190 } 191 192 195 private Image getThreadWrapperThreadImage(IJavaThread thread){ 196 ImageDescriptor descriptor= null; 197 if (thread.isSuspended()) { 198 descriptor= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED); 199 } else { 200 descriptor= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING); 201 } 202 return fDebugImageRegistry.get(descriptor); 203 } 204 205 208 private Image getMonitorImage(){ 209 return fDebugImageRegistry.get(JavaDebugImages.DESC_OBJ_MONITOR); 210 } 211 212 215 public IEditorInput getEditorInput(Object item) { 216 return null; 217 } 218 219 222 public String getEditorId(IEditorInput input, Object inputObject) { 223 return null; 224 } 225 226 229 public void setAttribute(String id, Object value) { 230 } 231 232 237 private int computeMonitorAdornmentFlags(ThreadsViewContentProvider.MonitorWrapper wrapper) { 238 int flags= 0; 239 240 if (wrapper.state == ThreadsViewContentProvider.MonitorWrapper.CONTENDED_MONITOR) { 241 flags |= JDIImageDescriptor.CONTENTED_MONITOR; 242 } 243 if (wrapper.state == ThreadsViewContentProvider.MonitorWrapper.OWNED_MONITOR) { 244 flags |= JDIImageDescriptor.OWNED_MONITOR; 245 } 246 return flags; 247 } 248 249 254 private int computeThreadAdornmentFlags(MonitorsViewContentProvider.ThreadWrapper wrapper) { 255 int flags= 0; 256 257 if (wrapper.state == MonitorsViewContentProvider.ThreadWrapper.IN_CONTENTION_FOR_MONITOR) { 258 flags |= JDIImageDescriptor.IN_CONTENTION_FOR_MONITOR; 259 } 260 if (wrapper.state == MonitorsViewContentProvider.ThreadWrapper.OWNING_THREAD) { 261 flags |= JDIImageDescriptor.OWNS_MONITOR; 262 } 263 return flags; 264 } 265 } 266 | Popular Tags |