8ff384807c777f499dcbc5cbd9c45bae3df61048
[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 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;
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 ((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 }