01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jsp.launching;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IResource;
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.debug.core.DebugPlugin;
16: import org.eclipse.debug.core.IBreakpointManager;
17: import org.eclipse.debug.core.model.IBreakpoint;
18: import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint;
19: import org.eclipse.jdt.debug.core.JDIDebugModel;
20: import org.eclipse.jface.action.Action;
21: import org.eclipse.jface.action.IAction;
22: import org.eclipse.jface.text.source.IVerticalRulerInfo;
23: import org.eclipse.ui.IEditorInput;
24: import org.eclipse.ui.texteditor.ITextEditor;
25:
26: /**
27: * ToggleJspBreakpointAction
28: */
29: public class ToggleJspBreakpointAction extends Action implements
30: IAction {
31:
32: private ITextEditor fEditor;
33: private IVerticalRulerInfo fRulerInfo;
34:
35: /* (non-Javadoc)
36: * @see org.eclipse.jface.action.IAction#run()
37: */
38: public void run() {
39: IBreakpointManager manager = DebugPlugin.getDefault()
40: .getBreakpointManager();
41: IBreakpoint[] breakpoints = manager.getBreakpoints();
42: IResource resource = getResource();
43: int lineNumber = fRulerInfo.getLineOfLastMouseButtonActivity() + 1;
44: for (int i = 0; i < breakpoints.length; i++) {
45: IBreakpoint bp = breakpoints[i];
46: if (bp instanceof IJavaStratumLineBreakpoint) {
47: IJavaStratumLineBreakpoint breakpoint = (IJavaStratumLineBreakpoint) bp;
48: if (breakpoint.getMarker().getResource().equals(
49: resource)) {
50: try {
51: if (breakpoint.getLineNumber() == lineNumber) {
52: // remove
53: breakpoint.delete();
54: return;
55: }
56: } catch (CoreException e) {
57: e.printStackTrace();
58: }
59: }
60: }
61: }
62: createBreakpoint();
63: }
64:
65: protected void createBreakpoint() {
66: IResource resource = getResource();
67: int lineNumber = fRulerInfo.getLineOfLastMouseButtonActivity() + 1;
68: try {
69: JDIDebugModel.createStratumBreakpoint(resource, null,
70: resource.getName(), null, null, lineNumber, -1, -1,
71: 0, true, null); //
72: } catch (CoreException e) {
73: e.printStackTrace();
74: }
75: }
76:
77: /**
78: * @param editor
79: * @param rulerInfo
80: */
81: public ToggleJspBreakpointAction(ITextEditor editor,
82: IVerticalRulerInfo rulerInfo) {
83: super (LaunchingMessages.ToggleJspBreakpointAction_2);
84: fEditor = editor;
85: fRulerInfo = rulerInfo;
86: }
87:
88: protected IResource getResource() {
89: IEditorInput input = fEditor.getEditorInput();
90: IResource resource = (IResource) input.getAdapter(IFile.class);
91: if (resource == null) {
92: resource = (IResource) input.getAdapter(IResource.class);
93: }
94: return resource;
95: }
96: }
|