1 11 package org.eclipse.jdt.internal.debug.ui.breakpoints; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.model.IBreakpoint; 19 import org.eclipse.jdt.core.ISourceRange; 20 import org.eclipse.jdt.core.IType; 21 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 22 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint; 23 import org.eclipse.jdt.debug.core.JDIDebugModel; 24 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 25 import org.eclipse.jface.action.IAction; 26 import org.eclipse.jface.viewers.ISelection; 27 import org.eclipse.jface.viewers.IStructuredSelection; 28 import org.eclipse.swt.widgets.Event; 29 import org.eclipse.ui.IActionDelegate2; 30 import org.eclipse.ui.IObjectActionDelegate; 31 import org.eclipse.ui.IWorkbenchPart; 32 33 38 public class ToggleClassPrepareBreakpointAction implements IObjectActionDelegate, IActionDelegate2 { 39 40 private ISelection fSelection; 41 42 45 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 46 } 47 50 public void init(IAction action) { 51 } 52 55 public void dispose() { 56 } 57 60 public void runWithEvent(IAction action, Event event) { 61 run(action); 62 } 63 66 public void run(IAction action) { 67 IStructuredSelection ss = (IStructuredSelection)fSelection; 68 Iterator iterator = ss.iterator(); 69 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(JDIDebugModel.getPluginIdentifier()); 70 while (iterator.hasNext()) { 71 IType type = (IType) iterator.next(); 72 IBreakpoint existing = null; 73 try { 74 for (int i = 0; i < breakpoints.length; i++) { 75 IJavaBreakpoint breakpoint = (IJavaBreakpoint) breakpoints[i]; 76 if (breakpoint instanceof IJavaClassPrepareBreakpoint && 77 type.getFullyQualifiedName().equals(breakpoint.getTypeName())) { 78 existing = breakpoint; 79 break; 80 } 81 } 82 if (existing != null) { 83 existing.delete(); 84 } else { 85 int kind = IJavaClassPrepareBreakpoint.TYPE_CLASS; 86 if (!type.isClass()) { 87 kind = IJavaClassPrepareBreakpoint.TYPE_INTERFACE; 88 } 89 HashMap map = new HashMap (10); 90 BreakpointUtils.addJavaBreakpointAttributes(map, type); 91 92 ISourceRange range= type.getNameRange(); 93 int start= -1; 94 int end= -1; 95 if (range != null) { 96 start= range.getOffset(); 97 end= start + range.getLength(); 98 } 99 JDIDebugModel.createClassPrepareBreakpoint(BreakpointUtils.getBreakpointResource(type), type.getFullyQualifiedName(), kind, start, end, true, map); 100 } 101 } catch (CoreException e) { 102 103 } 104 } 105 } 106 109 public void selectionChanged(IAction action, ISelection selection) { 110 fSelection = selection; 111 } 112 } 113 | Popular Tags |