1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.debug.core.DebugEvent; 15 import org.eclipse.debug.core.DebugException; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.IDebugEventSetListener; 18 import org.eclipse.jdt.debug.core.IJavaThread; 19 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; 20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 21 import org.eclipse.jface.viewers.StructuredSelection; 22 import org.eclipse.jface.viewers.Viewer; 23 import org.eclipse.ui.IViewPart; 24 25 29 public class ShowSystemThreadsAction extends ViewFilterAction implements IDebugEventSetListener { 30 31 34 protected String getPreferenceKey() { 35 return IJavaDebugUIConstants.PREF_SHOW_SYSTEM_THREADS; 36 } 37 38 41 public boolean select(Viewer viewer, Object parentElement, Object element) { 42 if (!getValue()) { 43 44 IJavaThread thread = getJavaThread(element); 45 46 if (thread != null) { 47 try { 48 return !thread.isSystemThread() || thread.isSuspended(); 50 } catch (DebugException e) { 51 } 52 } 53 } 54 return true; 55 } 56 57 private IJavaThread getJavaThread(Object element) { 58 IJavaThread thread = null; 59 60 if (element instanceof IJavaThread) 61 thread = (IJavaThread) element; 62 else if (element instanceof IAdaptable) 63 thread = (IJavaThread) ((IAdaptable)element).getAdapter(IJavaThread.class); 64 65 return thread; 66 } 67 68 71 public void init(IViewPart view) { 72 super.init(view); 73 DebugPlugin.getDefault().addDebugEventListener(this); 74 } 75 78 public void dispose() { 79 super.dispose(); 80 DebugPlugin.getDefault().removeDebugEventListener(this); 81 } 82 83 86 public void handleDebugEvents(DebugEvent[] events) { 87 if (getValue()) { 88 return; 90 } 91 for (int i = 0; i < events.length; i++) { 92 DebugEvent event = events[i]; 93 switch (event.getKind()) { 94 case DebugEvent.SUSPEND: 95 if (event.getDetail() == DebugEvent.BREAKPOINT) { 96 refresh(event.getSource(), true); 97 } 98 break; 99 case DebugEvent.RESUME: 100 if (event.getDetail() == DebugEvent.CLIENT_REQUEST) { 101 refresh(event.getSource(), false); 102 } 103 break; 104 } 105 } 106 } 107 108 private void refresh(Object source, final boolean select) { 109 final IJavaThread thread = getJavaThread(source); 110 if (thread != null) { 111 try { 112 if (thread.isSystemThread()) { 113 Runnable r = new Runnable () { 114 public void run() { 115 getStructuredViewer().refresh(); 116 if (select) { 117 Object tos; 118 try { 119 tos = thread.getTopStackFrame(); 120 if (tos != null) { 121 getStructuredViewer().setSelection(new StructuredSelection(tos)); 122 } 123 } catch (DebugException e) { 124 } 125 } 126 } 127 }; 128 JDIDebugUIPlugin.getStandardDisplay().asyncExec(r); 129 return; 130 } 131 } catch (DebugException e) { 132 } 133 } 134 } 135 } 136 | Popular Tags |