KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > actions > ToggleLineBreakpointAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.ant.internal.ui.editor.actions;
12
13 import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
14 import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
15 import org.eclipse.core.resources.IResource;
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.debug.core.model.ILineBreakpoint;
20 import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
21 import org.eclipse.jface.text.ITextSelection;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.ui.IEditorInput;
25 import org.eclipse.ui.IEditorPart;
26 import org.eclipse.ui.IFileEditorInput;
27 import org.eclipse.ui.IWorkbenchPart;
28
29 public class ToggleLineBreakpointAction implements IToggleBreakpointsTarget {
30     
31     /* (non-Javadoc)
32      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
33      */

34     public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
35         IEditorPart editorPart = (IEditorPart)part;
36         IEditorInput editorInput = editorPart.getEditorInput();
37         IResource resource= null;
38         if (editorInput instanceof IFileEditorInput) {
39             resource= ((IFileEditorInput)editorInput).getFile();
40         }
41         if (resource == null) {
42             Display.getCurrent().beep();
43             return;
44         }
45         
46         ITextSelection textSelection = (ITextSelection) selection;
47         int lineNumber = textSelection.getStartLine();
48         IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
49         for (int i = 0; i < breakpoints.length; i++) {
50             IBreakpoint breakpoint = breakpoints[i];
51             if (resource.equals(breakpoint.getMarker().getResource())) {
52                 if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) {
53                     // remove
54
breakpoint.delete();
55                     return;
56                 }
57             }
58         }
59         // create line breakpoint (doc line numbers start at 0)
60
new AntLineBreakpoint(resource, lineNumber + 1);
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
65      */

66     public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
67         return selection instanceof ITextSelection;
68     }
69     
70     /* (non-Javadoc)
71      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
72      */

73     public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
78      */

79     public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
80         return false;
81     }
82     
83     /* (non-Javadoc)
84      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
85      */

86     public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
87     }
88     
89     /* (non-Javadoc)
90      * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
91      */

92     public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
93         return false;
94     }
95 }
96
Popular Tags