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