1 11 package org.eclipse.jdt.internal.debug.ui.breakpoints; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.core.runtime.jobs.Job; 22 import org.eclipse.debug.core.DebugPlugin; 23 import org.eclipse.debug.core.model.IBreakpoint; 24 import org.eclipse.jdt.core.ISourceRange; 25 import org.eclipse.jdt.core.IType; 26 import org.eclipse.jdt.core.search.SearchEngine; 27 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 28 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint; 29 import org.eclipse.jdt.debug.core.JDIDebugModel; 30 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 31 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 32 import org.eclipse.jdt.ui.IJavaElementSearchConstants; 33 import org.eclipse.jdt.ui.JavaUI; 34 import org.eclipse.jface.action.IAction; 35 import org.eclipse.jface.dialogs.IDialogConstants; 36 import org.eclipse.jface.viewers.ISelection; 37 import org.eclipse.swt.widgets.Shell; 38 import org.eclipse.ui.IWorkbenchWindow; 39 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 40 import org.eclipse.ui.dialogs.SelectionDialog; 41 42 45 public class AddClassPrepareBreakpointAction implements IWorkbenchWindowActionDelegate { 46 47 50 private IWorkbenchWindow workbenchWindow; 51 52 57 private void createBreakpoints(final Object [] selection) { 58 try { 59 for (int i = 0; i < selection.length; i++) { 60 final IType type = (IType) selection[i]; 61 final IResource resource = BreakpointUtils.getBreakpointResource(type); 62 final Map map = new HashMap (10); 63 BreakpointUtils.addJavaBreakpointAttributes(map, type); 64 int kind = IJavaClassPrepareBreakpoint.TYPE_CLASS; 65 if (!type.isClass()) { 66 kind = IJavaClassPrepareBreakpoint.TYPE_INTERFACE; 67 } 68 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(JDIDebugModel.getPluginIdentifier()); 69 boolean exists = false; 70 for (int j = 0; j < breakpoints.length; j++) { 71 IJavaBreakpoint breakpoint = (IJavaBreakpoint) breakpoints[j]; 72 if (breakpoint instanceof IJavaClassPrepareBreakpoint) { 73 if (breakpoint.getTypeName().equals(type.getFullyQualifiedName())) { 74 exists = true; 75 break; 76 } 77 } 78 } 79 if (!exists) { 80 ISourceRange range = type.getNameRange(); 81 int start = -1; 82 int end = -1; 83 if (range != null) { 84 start = range.getOffset(); 85 end = start + range.getLength(); 86 } 87 final int finalKind = kind; 88 final int finalStart = start; 89 final int finalEnd = end; 90 new Job(BreakpointMessages.AddClassPrepareBreakpointAction_2) { 91 protected IStatus run(IProgressMonitor monitor) { 92 try { 93 JDIDebugModel.createClassPrepareBreakpoint(resource, type.getFullyQualifiedName(), finalKind, finalStart, finalEnd, true, map); 94 return Status.OK_STATUS; 95 } catch (CoreException e) { 96 return e.getStatus(); 97 } 98 } 99 100 }.schedule(); 101 } 102 } 103 } catch(CoreException e) { 104 JDIDebugUIPlugin.statusDialog(e.getStatus()); 105 } 106 } 107 108 111 public void run(IAction action) { 112 Shell shell = JDIDebugUIPlugin.getActiveWorkbenchShell(); 113 SelectionDialog dialog = null; 114 try { 115 dialog = JavaUI.createTypeDialog(shell, workbenchWindow, 116 SearchEngine.createWorkspaceScope(), 117 IJavaElementSearchConstants.CONSIDER_CLASSES, 118 true, "", null); dialog.setTitle(BreakpointMessages.AddClassPrepareBreakpointAction_0); 120 dialog.setMessage(BreakpointMessages.AddClassPrepareBreakpointAction_1); 121 if (dialog.open() == IDialogConstants.OK_ID) { 122 createBreakpoints(dialog.getResult()); 123 } 124 } catch (CoreException e) {JDIDebugUIPlugin.log(e);} 125 } 126 127 130 public void selectionChanged(IAction action, ISelection selection) {} 131 132 135 public void dispose() { 136 workbenchWindow = null; 137 } 138 139 142 public void init(IWorkbenchWindow window) { 143 workbenchWindow = window; 144 } 145 } 146 | Popular Tags |