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.phpdt.internal.debug.ui;
14 import java.util.HashMap;
16 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
17 import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
18 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
19 import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
20 import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
21 import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.core.resources.IMarker;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.debug.core.DebugPlugin;
27 import org.eclipse.debug.core.model.IBreakpoint;
28 import org.eclipse.debug.core.model.IValue;
29 import org.eclipse.debug.ui.DebugUITools;
30 import org.eclipse.debug.ui.IDebugModelPresentation;
31 import org.eclipse.debug.ui.IDebugUIConstants;
32 import org.eclipse.debug.ui.IValueDetailListener;
33 import org.eclipse.jface.viewers.LabelProvider;
34 import org.eclipse.swt.graphics.Image;
35 import org.eclipse.ui.IEditorDescriptor;
36 import org.eclipse.ui.IEditorInput;
37 import org.eclipse.ui.IEditorRegistry;
38 import org.eclipse.ui.PlatformUI;
39 import org.eclipse.ui.part.FileEditorInput;
42 * @see IDebugModelPresentation
44 public class PHPDebugModelPresentation extends LabelProvider implements
45 IDebugModelPresentation {
47 protected HashMap fAttributes = new HashMap(3);
49 public PHPDebugModelPresentation() {
54 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
56 public String getEditorId(IEditorInput input, Object inputObject) {
57 IEditorRegistry registry = PlatformUI.getWorkbench()
59 IEditorDescriptor descriptor = registry.getDefaultEditor(input
61 if (descriptor != null)
62 return descriptor.getId();
68 * @see IDebugModelPresentation#setAttribute(String, Object)
70 public void setAttribute(String id, Object value) {
74 fAttributes.put(id, value);
78 * @see IDebugModelPresentation#getEditorInput(Object)
80 public IEditorInput getEditorInput(Object item) {
82 if (item instanceof PHPLineBreakpoint) {
83 IBreakpoint bp = (IBreakpoint) item;
84 IMarker ma = bp.getMarker();
85 IFile eclipseFile = PHPDebugUiPlugin.getWorkspace().getRoot()
86 .getFileForLocation(ma.getResource().getLocation());
87 if (eclipseFile == null) {
90 return new FileEditorInput(eclipseFile);
96 * @see IDebugModelPresentation#getImage(Object)
98 public Image getImage(Object element) {
99 if (element instanceof PHPLineBreakpoint) {
100 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
101 } else if (element instanceof IMarker) {
102 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
103 } else if (element instanceof PHPStackFrame
104 || element instanceof PHPThread
105 || element instanceof IPHPDebugTarget) {
106 return getDebugElementImage(element);
107 } else if (element instanceof PHPVariable) {
108 return getVariableImage((PHPVariable) element);
109 } else if (element instanceof PHPValue) {
110 return getValueImage((PHPValue) element);
112 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
115 private Image getVariableImage(PHPVariable phpVar) {
117 * if (phpVar != null) { if (phpVar.isLocal()) return
118 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
119 * (phpVar.isHashValue()) return
120 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
122 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
125 private Image getValueImage(PHPValue phpVar) {
126 if (phpVar != null) {
127 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
129 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
133 * @see IDebugModelPresentation#getText(Object)
135 public String getText(Object element) {
137 if (element instanceof PHPLineBreakpoint) {
138 return getBreakpointText((IBreakpoint) element);
139 } else if (element instanceof PHPVariable) {
140 PHPVariable phpVar = (PHPVariable) element;
141 return phpVar.toString();
143 } catch (CoreException e) {
144 return PHPDebugUiMessages
145 .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
151 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
153 public void computeDetail(IValue value, IValueDetailListener listener) {
157 protected IBreakpoint getBreakpoint(IMarker marker) {
158 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
162 protected String getBreakpointText(IBreakpoint breakpoint)
163 throws CoreException {
164 if (breakpoint instanceof PHPLineBreakpoint) {
165 return getLineBreakpointText((PHPLineBreakpoint) breakpoint);
167 return ""; //$NON-NLS-1$
170 protected String getLineBreakpointText(PHPLineBreakpoint breakpoint)
171 throws CoreException {
172 StringBuffer label = new StringBuffer();
174 label.append(breakpoint.getMarker().getResource().getFullPath());
175 label.append(" ["); //$NON-NLS-1$
176 label.append(PHPDebugUiMessages
177 .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
179 label.append(breakpoint.getLineNumber());
182 if (breakpoint.getHitCount() > 0) {
183 label.append(" [skip count ");
184 label.append(breakpoint.getHitCount());
188 if (breakpoint.isConditionEnabled()) {
189 label.append(" [conditional]");
192 return label.toString();
196 * Returns the image associated with the given element or <code>null</code>
197 * if none is defined.
199 protected Image getDebugElementImage(Object element) {
201 if (element instanceof PHPThread) {
202 PHPThread thread = (PHPThread) element;
203 if (thread.isSuspended()) {
205 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
206 } else if (thread.isTerminated()) {
208 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
211 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
213 } else if (element instanceof PHPStackFrame) {
215 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
216 } else if (element instanceof IPHPDebugTarget) {
217 IPHPDebugTarget debugTarget = (IPHPDebugTarget) element;
218 if (debugTarget.isTerminated()) {
220 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
223 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);