| /******************************************************************************* |
| * Copyright (c) 2007 Chase Technology Ltd - http://www.chasetechnology.co.uk |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Doug Satchwell (Chase Technology Ltd) - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.wst.xsl.internal.debug.ui.model; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.debug.core.DebugPlugin; |
| import org.eclipse.debug.core.model.IBreakpoint; |
| import org.eclipse.debug.core.model.ILineBreakpoint; |
| import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; |
| import org.eclipse.jface.text.ITextSelection; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.texteditor.ITextEditor; |
| import org.eclipse.wst.xsl.core.XSLCore; |
| import org.eclipse.wst.xsl.launching.model.IXSLConstants; |
| import org.eclipse.wst.xsl.launching.model.XSLLineBreakpoint; |
| |
| /** |
| * An <code>IToggleBreakpointsTarget</code> for XSL breakpoints. |
| * |
| * @author Doug Satchwell |
| */ |
| public class XSLLineBreakpointAdapter implements IToggleBreakpointsTarget |
| { |
| public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException |
| { |
| ITextEditor textEditor = getEditor(part); |
| if (textEditor != null) |
| { |
| IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class); |
| ITextSelection textSelection = (ITextSelection) selection; |
| int lineNumber = textSelection.getStartLine(); |
| IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IXSLConstants.ID_XSL_DEBUG_MODEL); |
| for (IBreakpoint breakpoint : breakpoints) |
| { |
| if (resource.equals(breakpoint.getMarker().getResource())) |
| { |
| if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) |
| { |
| // remove |
| breakpoint.delete(); |
| return; |
| } |
| } |
| } |
| // create line breakpoint (doc line numbers start at 0) |
| XSLLineBreakpoint lineBreakpoint = new XSLLineBreakpoint(resource, lineNumber + 1, 1, 1); |
| DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); |
| } |
| } |
| |
| public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) |
| { |
| return getEditor(part) != null; |
| } |
| |
| /** |
| * Returns the editor being used to edit a XSL file, associated with the |
| * given part, or <code>null</code> if none. |
| */ |
| private ITextEditor getEditor(IWorkbenchPart part) |
| { |
| if (part instanceof ITextEditor) |
| { |
| ITextEditor editorPart = (ITextEditor) part; |
| IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); |
| if (resource != null && resource.getType() == IResource.FILE) |
| { |
| if (XSLCore.isXSLFile((IFile)resource)) |
| { |
| return editorPart; |
| } |
| } |
| } |
| return null; |
| } |
| |
| public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException |
| { |
| } |
| |
| public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) |
| { |
| return false; |
| } |
| |
| public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException |
| { |
| } |
| |
| public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) |
| { |
| return false; |
| } |
| } |