1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
15 import java.util.HashMap;
17 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint;
19 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
20 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread;
21 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame;
22 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
23 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugValue;
24 import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
25 import net.sourceforge.phpeclipse.xdebug.ui.php.launching.CopyOfPHPDebugModelPresentation.StorageEditorInput;
27 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
29 //import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
30 //import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
31 //import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
33 import org.eclipse.core.resources.IFile;
34 import org.eclipse.core.resources.IMarker;
35 import org.eclipse.core.resources.IStorage;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.PlatformObject;
38 import org.eclipse.debug.core.DebugPlugin;
39 import org.eclipse.debug.core.model.IBreakpoint;
40 import org.eclipse.debug.core.model.ILineBreakpoint;
41 import org.eclipse.debug.core.model.IValue;
42 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
43 import org.eclipse.debug.ui.DebugUITools;
44 import org.eclipse.debug.ui.IDebugModelPresentation;
45 import org.eclipse.debug.ui.IDebugUIConstants;
46 import org.eclipse.debug.ui.IValueDetailListener;
47 import org.eclipse.jface.resource.ImageDescriptor;
48 import org.eclipse.jface.viewers.LabelProvider;
49 import org.eclipse.swt.graphics.Image;
50 import org.eclipse.ui.IEditorDescriptor;
51 import org.eclipse.ui.IEditorInput;
52 import org.eclipse.ui.IEditorRegistry;
53 import org.eclipse.ui.IPersistableElement;
54 import org.eclipse.ui.IStorageEditorInput;
55 import org.eclipse.ui.PlatformUI;
56 import org.eclipse.ui.part.FileEditorInput;
59 * @see IDebugModelPresentation
61 public class PHPDebugModelPresentation extends LabelProvider implements
62 IDebugModelPresentation {
64 protected HashMap fAttributes = new HashMap(3);
66 public PHPDebugModelPresentation() {
71 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
73 public String getEditorId(IEditorInput input, Object inputObject) {
74 IEditorRegistry registry = PlatformUI.getWorkbench()
76 IEditorDescriptor descriptor = registry.getDefaultEditor(input
78 if (descriptor != null)
79 return descriptor.getId();
85 * @see IDebugModelPresentation#setAttribute(String, Object)
87 public void setAttribute(String id, Object value) {
91 fAttributes.put(id, value);
95 * @see IDebugModelPresentation#getEditorInput(Object)
97 public IEditorInput getEditorInputA(Object item) {
99 if (item instanceof XDebugLineBreakpoint) {
100 IBreakpoint bp = (IBreakpoint) item;
101 IMarker ma = bp.getMarker();
102 //IFile eclipseFile = PHPDebugUiPlugin.getWorkspace().getRoot()
103 // .getFileForLocation(ma.getResource().getLocation());
105 IFile eclipseFile = null; //XDebugUIPlugin.getWorkspace().getRoot()
106 //.getFile(ma.getResource().getFullPath());
107 if (eclipseFile == null) {
110 return new FileEditorInput(eclipseFile);
115 public IEditorInput getEditorInput(Object element) {
117 if (element instanceof IFile) {
118 return new FileEditorInput((IFile)element);
120 if( element instanceof LocalFileStorage) {
121 LocalFileStorage lfc= (LocalFileStorage)element;
122 return new StorageEditorInput(lfc,lfc.getFile());
124 if (element instanceof ILineBreakpoint) {
125 return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
131 * @see IDebugModelPresentation#getImage(Object)
133 public Image getImage(Object element) {
134 if (element instanceof XDebugLineBreakpoint) {
135 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
136 } else if (element instanceof IMarker) {
137 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
138 } else if (element instanceof XDebugStackFrame
139 || element instanceof XDebugThread
140 || element instanceof XDebugTarget) {
141 return getDebugElementImage(element);
142 } else if (element instanceof XDebugVariable) {
143 return getVariableImage((XDebugVariable) element);
144 } else if (element instanceof XDebugValue) {
145 return getValueImage((XDebugValue) element);
147 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
150 private Image getVariableImage(XDebugVariable phpVar) {
152 * if (phpVar != null) { if (phpVar.isLocal()) return
153 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
154 * (phpVar.isHashValue()) return
155 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
157 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
160 private Image getValueImage(XDebugValue phpVar) {
161 if (phpVar != null) {
162 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
164 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
168 * @see IDebugModelPresentation#getText(Object)
170 public String getText(Object element) {
172 if (element instanceof XDebugLineBreakpoint) {
173 return getBreakpointText((IBreakpoint) element);
174 } else if (element instanceof XDebugVariable) {
175 XDebugVariable phpVar = (XDebugVariable) element;
176 return phpVar.toString();
178 } catch (CoreException e) {
179 //return PHPDebugUiMessages
180 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
186 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
188 public void computeDetail(IValue value, IValueDetailListener listener) {
192 protected IBreakpoint getBreakpoint(IMarker marker) {
193 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
197 protected String getBreakpointText(IBreakpoint breakpoint)
198 throws CoreException {
199 if (breakpoint instanceof XDebugLineBreakpoint) {
200 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
202 return ""; //$NON-NLS-1$
205 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
206 throws CoreException {
207 StringBuffer label = new StringBuffer();
209 label.append(breakpoint.getMarker().getResource().getFullPath());
210 label.append(" ["); //$NON-NLS-1$
211 //label.append(PHPDebugUiMessages
212 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
214 label.append(breakpoint.getLineNumber());
217 /*if (breakpoint.getHitCount() > 0) {
218 label.append(" [skip count ");
219 label.append(breakpoint.getHitCount());
223 /*if (breakpoint.isConditionEnabled()) {
224 label.append(" [conditional]");
227 return label.toString();
231 * Returns the image associated with the given element or <code>null</code>
232 * if none is defined.
234 protected Image getDebugElementImage(Object element) {
236 if (element instanceof XDebugThread) {
237 XDebugThread thread = (XDebugThread) element;
238 if (thread.isSuspended()) {
240 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
241 } else if (thread.isTerminated()) {
243 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
246 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
248 } else if (element instanceof XDebugStackFrame) {
250 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
251 } else if (element instanceof XDebugTarget) {
252 XDebugTarget debugTarget = (XDebugTarget) element;
253 if (debugTarget.isTerminated()) {
255 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
258 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
264 class StorageEditorInput extends PlatformObject implements
265 IStorageEditorInput {
268 private IStorage fStorage;
270 public StorageEditorInput(IStorage storage, File file) {
276 public IStorage getStorage() {
280 public ImageDescriptor getImageDescriptor() {
284 public String getName() {
285 return getStorage().getName();
288 public IPersistableElement getPersistable() {
292 public String getToolTipText() {
293 return getStorage().getFullPath().toOSString();
296 public boolean equals(Object object) {
297 return object instanceof StorageEditorInput
298 && getStorage().equals(
299 ((StorageEditorInput) object).getStorage());
302 public int hashCode() {
303 return getStorage().hashCode();
306 public boolean exists() {
307 return fFile.exists();