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;
14 import java.util.HashMap;
16 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint;
18 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
19 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread;
20 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame;
21 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
22 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugValue;
23 import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
25 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
27 //import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
28 //import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
29 //import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IMarker;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.debug.core.DebugPlugin;
35 import org.eclipse.debug.core.model.IBreakpoint;
36 import org.eclipse.debug.core.model.IValue;
37 import org.eclipse.debug.ui.DebugUITools;
38 import org.eclipse.debug.ui.IDebugModelPresentation;
39 import org.eclipse.debug.ui.IDebugUIConstants;
40 import org.eclipse.debug.ui.IValueDetailListener;
41 import org.eclipse.jface.viewers.LabelProvider;
42 import org.eclipse.swt.graphics.Image;
43 import org.eclipse.ui.IEditorDescriptor;
44 import org.eclipse.ui.IEditorInput;
45 import org.eclipse.ui.IEditorRegistry;
46 import org.eclipse.ui.PlatformUI;
47 import org.eclipse.ui.part.FileEditorInput;
50 * @see IDebugModelPresentation
52 public class PHPDebugModelPresentation extends LabelProvider implements
53 IDebugModelPresentation {
55 protected HashMap fAttributes = new HashMap(3);
57 public PHPDebugModelPresentation() {
62 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
64 public String getEditorId(IEditorInput input, Object inputObject) {
65 IEditorRegistry registry = PlatformUI.getWorkbench()
67 IEditorDescriptor descriptor = registry.getDefaultEditor(input
69 if (descriptor != null)
70 return descriptor.getId();
76 * @see IDebugModelPresentation#setAttribute(String, Object)
78 public void setAttribute(String id, Object value) {
82 fAttributes.put(id, value);
86 * @see IDebugModelPresentation#getEditorInput(Object)
88 public IEditorInput getEditorInput(Object item) {
90 if (item instanceof XDebugLineBreakpoint) {
91 IBreakpoint bp = (IBreakpoint) item;
92 IMarker ma = bp.getMarker();
93 //IFile eclipseFile = PHPDebugUiPlugin.getWorkspace().getRoot()
94 // .getFileForLocation(ma.getResource().getLocation());
96 IFile eclipseFile = null; //XDebugUIPlugin.getWorkspace().getRoot()
97 //.getFile(ma.getResource().getFullPath());
98 if (eclipseFile == null) {
101 return new FileEditorInput(eclipseFile);
107 * @see IDebugModelPresentation#getImage(Object)
109 public Image getImage(Object element) {
110 if (element instanceof XDebugLineBreakpoint) {
111 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
112 } else if (element instanceof IMarker) {
113 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
114 } else if (element instanceof XDebugStackFrame
115 || element instanceof XDebugThread
116 || element instanceof XDebugTarget) {
117 return getDebugElementImage(element);
118 } else if (element instanceof XDebugVariable) {
119 return getVariableImage((XDebugVariable) element);
120 } else if (element instanceof XDebugValue) {
121 return getValueImage((XDebugValue) element);
123 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
126 private Image getVariableImage(XDebugVariable phpVar) {
128 * if (phpVar != null) { if (phpVar.isLocal()) return
129 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
130 * (phpVar.isHashValue()) return
131 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
133 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
136 private Image getValueImage(XDebugValue phpVar) {
137 if (phpVar != null) {
138 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
140 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
144 * @see IDebugModelPresentation#getText(Object)
146 public String getText(Object element) {
148 if (element instanceof XDebugLineBreakpoint) {
149 return getBreakpointText((IBreakpoint) element);
150 } else if (element instanceof XDebugVariable) {
151 XDebugVariable phpVar = (XDebugVariable) element;
152 return phpVar.toString();
154 } catch (CoreException e) {
155 //return PHPDebugUiMessages
156 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
162 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
164 public void computeDetail(IValue value, IValueDetailListener listener) {
168 protected IBreakpoint getBreakpoint(IMarker marker) {
169 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
173 protected String getBreakpointText(IBreakpoint breakpoint)
174 throws CoreException {
175 if (breakpoint instanceof XDebugLineBreakpoint) {
176 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
178 return ""; //$NON-NLS-1$
181 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
182 throws CoreException {
183 StringBuffer label = new StringBuffer();
185 label.append(breakpoint.getMarker().getResource().getFullPath());
186 label.append(" ["); //$NON-NLS-1$
187 //label.append(PHPDebugUiMessages
188 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
190 label.append(breakpoint.getLineNumber());
193 /*if (breakpoint.getHitCount() > 0) {
194 label.append(" [skip count ");
195 label.append(breakpoint.getHitCount());
199 /*if (breakpoint.isConditionEnabled()) {
200 label.append(" [conditional]");
203 return label.toString();
207 * Returns the image associated with the given element or <code>null</code>
208 * if none is defined.
210 protected Image getDebugElementImage(Object element) {
212 if (element instanceof XDebugThread) {
213 XDebugThread thread = (XDebugThread) element;
214 if (thread.isSuspended()) {
216 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
217 } else if (thread.isTerminated()) {
219 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
222 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
224 } else if (element instanceof XDebugStackFrame) {
226 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
227 } else if (element instanceof XDebugTarget) {
228 XDebugTarget debugTarget = (XDebugTarget) element;
229 if (debugTarget.isTerminated()) {
231 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
234 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);