This commit was generated by cvs2svn to compensate for changes in r50,
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / PHPSourceLocator.java
diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java
new file mode 100644 (file)
index 0000000..c4e4e3f
--- /dev/null
@@ -0,0 +1,81 @@
+package net.sourceforge.phpdt.internal.debug.ui;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IPersistableSourceLocator;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.ui.ISourcePresentation;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
+
+public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
+  private String absoluteWorkingDirectory;
+
+  public PHPSourceLocator() {
+
+  }
+
+  public String getAbsoluteWorkingDirectory() {
+    return absoluteWorkingDirectory;
+  }
+  /**
+   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
+   */
+  public String getMemento() throws CoreException {
+    return null;
+  }
+
+  /**
+   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
+   */
+  public void initializeFromMemento(String memento) throws CoreException {
+  }
+
+  /**
+   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
+   */
+  public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
+    this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
+  }
+
+  /**
+   * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
+   */
+  public Object getSourceElement(IStackFrame stackFrame) {
+    return null;
+    //return ((PHPStackFrame) stackFrame).getFileName();
+  }
+
+  /**
+   * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
+   */
+  public String getEditorId(IEditorInput input, Object element) {
+    return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId();
+  }
+
+  /**
+   * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
+   */
+  public IEditorInput getEditorInput(Object element) {
+
+    String filename = (String) element;
+    IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
+    if (eclipseFile == null) {
+      filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
+      eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
+      if (eclipseFile == null) {
+        PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
+        return null;
+      }
+    }
+    return new FileEditorInput(eclipseFile);
+
+  }
+
+}