KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > breakpoints > ToggleClassPrepareBreakpointAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.breakpoints;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
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 /**
34  * Toggles a class prepare breakpoint for a selected type
35  *
36  * @since 3.0
37  */

38 public class ToggleClassPrepareBreakpointAction implements IObjectActionDelegate, IActionDelegate2 {
39     
40     private ISelection fSelection;
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
44      */

45     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
46     }
47     /* (non-Javadoc)
48      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
49      */

50     public void init(IAction action) {
51     }
52     /* (non-Javadoc)
53      * @see org.eclipse.ui.IActionDelegate2#dispose()
54      */

55     public void dispose() {
56     }
57     /* (non-Javadoc)
58      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
59      */

60     public void runWithEvent(IAction action, Event event) {
61         run(action);
62     }
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
65      */

66     public void run(IAction action) {
67         IStructuredSelection ss = (IStructuredSelection)fSelection;
68         Iterator JavaDoc 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 JavaDoc map = new HashMap JavaDoc(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     /* (non-Javadoc)
107      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
108      */

109     public void selectionChanged(IAction action, ISelection selection) {
110         fSelection = selection;
111     }
112 }
113
Popular Tags