1 11 package org.eclipse.jdt.internal.debug.ui.breakpoints; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.core.runtime.Preferences; 15 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; 16 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.model.IBreakpoint; 19 import org.eclipse.debug.core.model.IExpression; 20 import org.eclipse.debug.ui.DebugUITools; 21 import org.eclipse.debug.ui.IDebugUIConstants; 22 import org.eclipse.debug.ui.IDebugView; 23 import org.eclipse.debug.ui.InspectPopupDialog; 24 import org.eclipse.debug.ui.contexts.DebugContextEvent; 25 import org.eclipse.debug.ui.contexts.IDebugContextListener; 26 import org.eclipse.debug.ui.contexts.IDebugContextManager; 27 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; 28 import org.eclipse.jdt.debug.core.IJavaObject; 29 import org.eclipse.jdt.debug.core.IJavaStackFrame; 30 import org.eclipse.jdt.debug.core.IJavaThread; 31 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaExceptionBreakpoint; 32 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; 33 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 34 import org.eclipse.jdt.internal.debug.ui.actions.PopupInspectAction; 35 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 36 import org.eclipse.jface.viewers.ISelection; 37 import org.eclipse.jface.viewers.IStructuredSelection; 38 import org.eclipse.swt.graphics.Point; 39 import org.eclipse.swt.graphics.Rectangle; 40 import org.eclipse.swt.widgets.Tree; 41 import org.eclipse.swt.widgets.TreeItem; 42 import org.eclipse.ui.IWorkbenchPage; 43 import org.eclipse.ui.IWorkbenchPart; 44 import org.eclipse.ui.IWorkbenchPartSite; 45 46 49 public class ExceptionInspector implements IDebugContextListener, IPropertyChangeListener { 50 51 54 public ExceptionInspector() { 55 Preferences pluginPreferences = JDIDebugUIPlugin.getDefault().getPluginPreferences(); 56 pluginPreferences.addPropertyChangeListener(this); 57 if (pluginPreferences.getBoolean(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION)) { 58 DebugUITools.getDebugContextManager().addDebugContextListener(this); 59 } 60 } 61 62 65 public void debugContextChanged(DebugContextEvent event) { 66 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 67 IWorkbenchPart part = event.getDebugContextProvider().getPart(); 68 if (part != null) { 69 IWorkbenchPartSite site = part.getSite(); 70 if (site != null && IDebugUIConstants.ID_DEBUG_VIEW.equals(site.getId())) { 71 IWorkbenchPage page = site.getWorkbenchWindow().getActivePage(); 72 if (page != null && page.isPartVisible(part)) { 73 ISelection selection = event.getContext(); 74 if (selection instanceof IStructuredSelection) { 75 IStructuredSelection ss = (IStructuredSelection) selection; 76 if (ss.size() == 1) { 77 Object firstElement = ss.getFirstElement(); 78 if (firstElement instanceof IAdaptable) { 79 IJavaStackFrame frame = (IJavaStackFrame) ((IAdaptable)firstElement).getAdapter(IJavaStackFrame.class); 80 if (frame != null) { 81 IJavaThread thread = (IJavaThread)frame.getThread(); 82 try { 83 if (frame.equals(thread.getTopStackFrame())) { 84 IBreakpoint[] breakpoints = thread.getBreakpoints(); 85 if (breakpoints.length == 1) { 86 if (breakpoints[0] instanceof IJavaExceptionBreakpoint) { 87 IJavaExceptionBreakpoint exception = (IJavaExceptionBreakpoint) breakpoints[0]; 88 IJavaObject lastException = ((JavaExceptionBreakpoint)exception).getLastException(); 89 if (lastException != null) { 90 IExpression exp = new JavaInspectExpression(exception.getExceptionTypeName(), lastException); 91 Tree tree = (Tree) ((IDebugView)part).getViewer().getControl(); 92 TreeItem[] selection2 = tree.getSelection(); 93 Rectangle bounds = selection2[0].getBounds(); 94 Point point = tree.toDisplay(bounds.x, bounds.y + bounds.height); 95 InspectPopupDialog dialog = new InspectPopupDialog(part.getSite().getShell(), 96 point, PopupInspectAction.ACTION_DEFININITION_ID, exp); 97 dialog.open(); 98 } 99 } 100 } 101 } 102 } catch (DebugException e) {} 103 } 104 } 105 } 106 } 107 } 108 } 109 } 110 } 111 } 112 113 116 public void contextChanged(ISelection selection, IWorkbenchPart part) {} 117 118 121 public void propertyChange(PropertyChangeEvent event) { 122 if (IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION.equals(event.getProperty())) { 123 IDebugContextManager manager = DebugUITools.getDebugContextManager(); 124 if (JDIDebugUIPlugin.getDefault().getPluginPreferences().getBoolean(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION)) { 125 manager.addDebugContextListener(this); 126 } else { 127 manager.removeDebugContextListener(this); 128 } 129 } 130 131 } 132 133 } 134 | Popular Tags |