fd31b8595822c648fd682c0931e8a79f4d3a856e
[phpeclipse.git] /
1 package net.sourceforge.phpdt.internal.debug.ui;
2
3 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
5
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;
17
18 public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
19   private String absoluteWorkingDirectory;
20
21   public PHPSourceLocator() {
22
23   }
24
25   public String getAbsoluteWorkingDirectory() {
26     return absoluteWorkingDirectory;
27   }
28   /**
29    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
30    */
31   public String getMemento() throws CoreException {
32     return null;
33   }
34
35   /**
36    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
37    */
38   public void initializeFromMemento(String memento) throws CoreException {
39   }
40
41   /**
42    * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
43    */
44   public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
45     this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
46   }
47
48   /**
49    * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
50    */
51   public Object getSourceElement(IStackFrame stackFrame) {
52     return null;
53     //return ((PHPStackFrame) stackFrame).getFileName();
54   }
55
56   /**
57    * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
58    */
59   public String getEditorId(IEditorInput input, Object element) {
60     return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId();
61   }
62
63   /**
64    * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
65    */
66   public IEditorInput getEditorInput(Object element) {
67
68     String filename = (String) element;
69     IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
70     if (eclipseFile == null) {
71       filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
72       eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
73       if (eclipseFile == null) {
74         PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
75         return null;
76       }
77     }
78     return new FileEditorInput(eclipseFile);
79
80   }
81
82 }