1 package net.sourceforge.phpdt.internal.debug.ui;
 
   3 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
 
   4 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
 
   5 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
   6 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
 
   7 import net.sourceforge.phpeclipse.builder.FileStorage;
 
   9 import org.eclipse.core.resources.IFile;
 
  10 import org.eclipse.core.runtime.CoreException;
 
  11 import org.eclipse.core.runtime.IPath;
 
  12 import org.eclipse.core.runtime.IStatus;
 
  13 import org.eclipse.core.runtime.Path;
 
  14 import org.eclipse.debug.core.ILaunchConfiguration;
 
  15 import org.eclipse.debug.core.model.IPersistableSourceLocator;
 
  16 import org.eclipse.debug.core.model.IStackFrame;
 
  17 import org.eclipse.debug.ui.ISourcePresentation;
 
  18 import org.eclipse.ui.IEditorDescriptor;
 
  19 import org.eclipse.ui.IEditorInput;
 
  20 import org.eclipse.ui.IEditorRegistry;
 
  21 import org.eclipse.ui.IWorkbench;
 
  22 import org.eclipse.ui.IWorkbenchPage;
 
  23 import org.eclipse.ui.IWorkbenchWindow;
 
  24 import org.eclipse.ui.PlatformUI;
 
  25 import org.eclipse.ui.part.FileEditorInput;
 
  27 public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
 
  28   private String absoluteWorkingDirectory;
 
  30   public PHPSourceLocator() {
 
  34   public String getAbsoluteWorkingDirectory() {
 
  35     return absoluteWorkingDirectory;
 
  38    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
 
  40   public String getMemento() throws CoreException {
 
  45    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
 
  47   public void initializeFromMemento(String memento) throws CoreException {
 
  51    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
 
  53   public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
 
  54     this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
 
  58    * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
 
  60   public Object getSourceElement(IStackFrame stackFrame) {
 
  61     return ((PHPStackFrame) stackFrame).getFileName();
 
  65    * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
 
  67   public String getEditorId(IEditorInput input, Object element) {
 
  68     return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId();
 
  72    * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
 
  74   public IEditorInput getEditorInput(Object element) {
 
  76     String filename = (String) element;
 
  77     IWorkbench workbench = PlatformUI.getWorkbench();
 
  78     IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
 
  79     IWorkbenchPage page = window.getActivePage();
 
  80     IPath path = new Path(filename);
 
  82     // If the file exists in the workspace, open it
 
  83     IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path);
 
  84     //    IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
 
  85 //    if (eclipseFile == null) {
 
  86 //      filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
 
  87 //      eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
 
  88 //      if (eclipseFile == null) {
 
  89 //        PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
 
  93     if (eclipseFile == null || !eclipseFile.exists()) {
 
  94       //                Otherwise open the stream directly
 
  96         PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
 
  99       FileStorage storage = new FileStorage(path);
 
 100       storage.setReadOnly();
 
 101       //      IEditorRegistry registry = workbench.getEditorRegistry();
 
 102       //      IEditorDescriptor desc = registry.getDefaultEditor(filename);
 
 103       //      if (desc == null) {
 
 104       //        desc = registry.getDefaultEditor();
 
 106       return new ExternalEditorInput(storage);
 
 108     return new FileEditorInput(eclipseFile);