1 package net.sourceforge.phpdt.internal.debug.ui;
5 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
6 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
9 import net.sourceforge.phpeclipse.builder.FileStorage;
11 import org.eclipse.core.resources.IFile;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.core.boot.BootLoader;
17 import org.eclipse.debug.core.ILaunchConfiguration;
18 import org.eclipse.debug.core.model.IPersistableSourceLocator;
19 import org.eclipse.debug.core.model.IStackFrame;
20 import org.eclipse.debug.ui.ISourcePresentation;
21 //import org.eclipse.ui.IEditorDescriptor;
22 import org.eclipse.ui.IEditorInput;
23 //import org.eclipse.ui.IEditorRegistry;
24 import org.eclipse.ui.IWorkbench;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchWindow;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.part.FileEditorInput;
30 public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
31 private String absoluteWorkingDirectory;
32 private Map fileMap = null;
33 private boolean remoteDebug;
34 private IPath remotePath;
35 private String projectName;
37 public PHPSourceLocator() {
41 public String getAbsoluteWorkingDirectory() {
42 return absoluteWorkingDirectory;
45 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
47 public String getMemento() throws CoreException {
52 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
54 public void initializeFromMemento(String memento) throws CoreException {
58 * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
60 public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
61 this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
62 this.remoteDebug=configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,false);
63 this.fileMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
64 this.projectName =configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
66 if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
67 this.remotePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase());
69 this.remotePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
76 * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
78 public Object getSourceElement(IStackFrame stackFrame) {
80 String key=((PHPStackFrame) stackFrame).getFileName();
87 IPath path = new Path(key);
88 if (remotePath.isPrefixOf(path))
91 path=path.removeFirstSegments(remotePath.matchingFirstSegments(path));
93 projectPath=(PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation());
94 file=(projectPath.append(path)).toString();
96 // file=(String)(fileMap.get(key));
106 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
108 public String getEditorId(IEditorInput input, Object element) {
109 return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId();
113 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
115 public IEditorInput getEditorInput(Object element) {
117 String filename = (String) element;
118 IWorkbench workbench = PlatformUI.getWorkbench();
119 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
120 IWorkbenchPage page = window.getActivePage();
121 IPath path = new Path(filename);
125 // If the file exists in the workspace, open it
126 IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path);
127 // IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
128 // if (eclipseFile == null) {
129 // filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
130 // eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
131 // if (eclipseFile == null) {
132 // PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
136 if (eclipseFile == null || !eclipseFile.exists()) {
137 // Otherwise open the stream directly
139 PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
142 FileStorage storage = new FileStorage(path);
143 storage.setReadOnly();
144 // IEditorRegistry registry = workbench.getEditorRegistry();
145 // IEditorDescriptor desc = registry.getDefaultEditor(filename);
146 // if (desc == null) {
147 // desc = registry.getDefaultEditor();
149 return new ExternalEditorInput(storage);
151 return new FileEditorInput(eclipseFile);