1 11 package org.eclipse.jdt.internal.debug.ui.console; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.core.model.IBreakpoint; 21 import org.eclipse.jdt.core.IClassFile; 22 import org.eclipse.jdt.core.ICompilationUnit; 23 import org.eclipse.jdt.core.IType; 24 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; 25 import org.eclipse.jdt.debug.core.JDIDebugModel; 26 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 27 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 28 import org.eclipse.jdt.internal.debug.ui.actions.JavaBreakpointPropertiesAction; 29 import org.eclipse.jdt.internal.debug.ui.breakpoints.AddExceptionAction; 30 import org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage; 31 import org.eclipse.jface.viewers.StructuredSelection; 32 import org.eclipse.ui.console.TextConsole; 33 34 37 public class JavaExceptionHyperLink extends JavaStackTraceHyperlink { 38 39 private String fExceptionName = null; 40 41 49 public JavaExceptionHyperLink(TextConsole console, String exceptionName) { 50 super(console); 51 fExceptionName = exceptionName; 52 } 53 54 57 public void linkActivated() { 58 try { 59 IBreakpoint[] breakpoints = DebugPlugin.getDefault() 61 .getBreakpointManager().getBreakpoints( 62 JDIDebugModel.getPluginIdentifier()); 63 for (int i = 0; i < breakpoints.length; i++) { 64 IBreakpoint breakpoint = breakpoints[i]; 65 if (breakpoint instanceof IJavaExceptionBreakpoint) { 66 IJavaExceptionBreakpoint exceptionBreakpoint = (IJavaExceptionBreakpoint) breakpoint; 67 if (fExceptionName 68 .equals(exceptionBreakpoint.getTypeName())) { 69 showProperties(exceptionBreakpoint); 70 return; 71 } 72 } 73 } 74 startSourceSearch(fExceptionName, -1); 76 } catch (CoreException e) { 77 JDIDebugUIPlugin.statusDialog(e.getStatus()); 78 return; 79 } 80 } 81 82 87 private void showProperties(IJavaExceptionBreakpoint breakpoint) { 88 JavaBreakpointPropertiesAction action = new JavaBreakpointPropertiesAction(); 89 action.selectionChanged(null, new StructuredSelection(breakpoint)); 90 action.run(null); 91 } 92 93 96 protected void processSearchResult(Object source, String typeName, int lineNumber) { 97 try { 98 IResource res = ResourcesPlugin.getWorkspace().getRoot(); 99 IType type = null; 100 if (source instanceof ICompilationUnit) { 101 type = ((ICompilationUnit) source).findPrimaryType(); 102 } else if (source instanceof IClassFile) { 103 type = ((IClassFile) source).getType(); 104 } else if (source instanceof IType) { 105 type = (IType) source; 106 } 107 if (type != null) { 108 res = BreakpointUtils.getBreakpointResource(type); 109 } 110 Map map = new HashMap (); 111 map.put(JavaBreakpointPage.ATTR_DELETE_ON_CANCEL, 112 JavaBreakpointPage.ATTR_DELETE_ON_CANCEL); 113 IJavaExceptionBreakpoint breakpoint = JDIDebugModel 114 .createExceptionBreakpoint(res, fExceptionName, true, true, 115 AddExceptionAction.isChecked(type), false, map); 116 showProperties(breakpoint); 117 } catch (CoreException e) { 118 JDIDebugUIPlugin.statusDialog(e.getStatus()); 119 } 120 } 121 122 } 123 | Popular Tags |