1 11 package org.eclipse.ant.internal.ui.editor.actions; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.ant.internal.ui.AntUIPlugin; 17 import org.eclipse.ant.internal.ui.debug.IAntDebugConstants; 18 import org.eclipse.ant.internal.ui.debug.model.AntDebugElement; 19 import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint; 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IMarker; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IAdaptable; 24 import org.eclipse.core.runtime.IStatus; 25 import org.eclipse.core.runtime.NullProgressMonitor; 26 import org.eclipse.core.runtime.Status; 27 import org.eclipse.debug.core.model.IBreakpoint; 28 import org.eclipse.debug.core.model.IDebugTarget; 29 import org.eclipse.debug.core.model.ISuspendResume; 30 import org.eclipse.debug.ui.actions.IRunToLineTarget; 31 import org.eclipse.debug.ui.actions.RunToLineHandler; 32 import org.eclipse.jface.text.IDocument; 33 import org.eclipse.jface.text.ITextSelection; 34 import org.eclipse.jface.viewers.ISelection; 35 import org.eclipse.ui.IEditorInput; 36 import org.eclipse.ui.IEditorPart; 37 import org.eclipse.ui.IWorkbenchPart; 38 import org.eclipse.ui.texteditor.IDocumentProvider; 39 import org.eclipse.ui.texteditor.ITextEditor; 40 41 44 public class RunToLineAdapter implements IRunToLineTarget { 45 46 49 public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException { 50 IEditorPart editorPart = (IEditorPart)part; 51 IEditorInput input = editorPart.getEditorInput(); 52 String errorMessage = null; 53 if (input == null) { 54 errorMessage = AntEditorActionMessages.getString("RunToLineAdapter.0"); } else { 56 ITextEditor textEditor = (ITextEditor)editorPart; 57 IDocumentProvider provider= textEditor.getDocumentProvider(); 58 IDocument document= provider.getDocument(input); 59 60 if (document == null) { 61 errorMessage = AntEditorActionMessages.getString("RunToLineAdapter.1"); } else { 63 64 ITextSelection textSelection = (ITextSelection) selection; 65 int lineNumber = textSelection.getStartLine() + 1; 66 67 IBreakpoint breakpoint= null; 68 Map attributes = getRunToLineAttributes(); 69 IFile file = (IFile)input.getAdapter(IFile.class); 70 if (file == null) { 71 errorMessage= AntEditorActionMessages.getString("RunToLineAdapter.2"); } else { 73 breakpoint= new AntLineBreakpoint(file, lineNumber, attributes, false); 74 breakpoint.setPersisted(false); 75 errorMessage = AntEditorActionMessages.getString("RunToLineAdapter.3"); if (target instanceof IAdaptable) { 77 IDebugTarget debugTarget = (IDebugTarget) ((IAdaptable)target).getAdapter(IDebugTarget.class); 78 if (debugTarget != null) { 79 RunToLineHandler handler = new RunToLineHandler(debugTarget, target, breakpoint); 80 handler.run(new NullProgressMonitor()); 81 return; 82 } 83 } 84 } 85 } 86 } 87 throw new CoreException(new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), AntUIPlugin.INTERNAL_ERROR, 88 errorMessage, null)); 89 } 90 91 private Map getRunToLineAttributes() { 92 Map attributes = new HashMap (); 93 attributes.put(IMarker.TRANSIENT, Boolean.TRUE); 94 attributes.put(IAntDebugConstants.ANT_RUN_TO_LINE, Boolean.TRUE); 95 return attributes; 96 } 97 98 101 public boolean canRunToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) { 102 return target instanceof AntDebugElement; 103 } 104 } 105 | Popular Tags |