1 package net.sourceforge.phpdt.internal.debug.ui;
3 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
5 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.core.runtime.IStatus;
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.debug.core.ILaunchConfiguration;
11 import org.eclipse.debug.core.model.IPersistableSourceLocator;
12 import org.eclipse.debug.core.model.IStackFrame;
13 import org.eclipse.debug.ui.ISourcePresentation;
14 import org.eclipse.ui.IEditorInput;
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.part.FileEditorInput;
18 public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
19 private String absoluteWorkingDirectory;
21 public PHPSourceLocator() {
25 public String getAbsoluteWorkingDirectory() {
26 return absoluteWorkingDirectory;
29 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
31 public String getMemento() throws CoreException {
36 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
38 public void initializeFromMemento(String memento) throws CoreException {
42 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
44 public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
45 this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
49 * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
51 public Object getSourceElement(IStackFrame stackFrame) {
52 return ((PHPStackFrame) stackFrame).getFileName();
56 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
58 public String getEditorId(IEditorInput input, Object element) {
59 return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String)element).getId();
63 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
65 public IEditorInput getEditorInput(Object element) {
67 String filename = (String) element;
68 IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
69 if (eclipseFile == null) {
70 filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
71 eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
72 if (eclipseFile == null) {
73 PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
77 return new FileEditorInput(eclipseFile);