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.XDebugUIPluginImages;
25 //import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
26 //import net.sourceforge.phpeclipse.xdebug.ui.php.launching.CopyOfPHPDebugModelPresentation.StorageEditorInput;
28 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
30 //import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
31 //import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
32 //import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
34 import org.eclipse.core.resources.IFile;
35 import org.eclipse.core.resources.IMarker;
36 import org.eclipse.core.resources.IStorage;
37 import org.eclipse.core.runtime.CoreException;
38 import org.eclipse.core.runtime.PlatformObject;
39 import org.eclipse.debug.core.DebugException;
40 import org.eclipse.debug.core.DebugPlugin;
41 import org.eclipse.debug.core.model.IBreakpoint;
42 import org.eclipse.debug.core.model.ILineBreakpoint;
43 import org.eclipse.debug.core.model.IValue;
44 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
45 import org.eclipse.debug.ui.DebugUITools;
46 import org.eclipse.debug.ui.IDebugModelPresentation;
47 import org.eclipse.debug.ui.IDebugUIConstants;
48 import org.eclipse.debug.ui.IValueDetailListener;
49 import org.eclipse.jface.resource.ImageDescriptor;
50 import org.eclipse.jface.viewers.LabelProvider;
51 import org.eclipse.swt.graphics.Image;
52 import org.eclipse.ui.IEditorDescriptor;
53 import org.eclipse.ui.IEditorInput;
54 import org.eclipse.ui.IEditorRegistry;
55 import org.eclipse.ui.IPersistableElement;
56 import org.eclipse.ui.IStorageEditorInput;
57 import org.eclipse.ui.PlatformUI;
58 import org.eclipse.ui.part.FileEditorInput;
61 * @see IDebugModelPresentation
63 public class PHPDebugModelPresentation extends LabelProvider implements
64 IDebugModelPresentation {
66 protected HashMap fAttributes = new HashMap(3);
68 public PHPDebugModelPresentation() {
73 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
75 public String getEditorId(IEditorInput input, Object inputObject) {
76 IEditorRegistry registry = PlatformUI.getWorkbench()
78 IEditorDescriptor descriptor = registry.getDefaultEditor(input
80 if (descriptor != null)
81 return descriptor.getId();
87 * @see IDebugModelPresentation#setAttribute(String, Object)
89 public void setAttribute(String id, Object value) {
93 fAttributes.put(id, value);
97 * @see IDebugModelPresentation#getEditorInput(Object)
99 public IEditorInput getEditorInput(Object element) {
101 if (element instanceof IFile) {
102 return new FileEditorInput((IFile)element);
104 if( element instanceof LocalFileStorage) {
105 LocalFileStorage lfc= (LocalFileStorage)element;
106 return new StorageEditorInput(lfc,lfc.getFile());
108 if (element instanceof ILineBreakpoint) {
109 return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
115 * @see IDebugModelPresentation#getImage(Object)
117 public Image getImage(Object element) {
118 if (element instanceof XDebugLineBreakpoint) {
119 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
120 } else if (element instanceof IMarker) {
121 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
122 } else if (element instanceof XDebugStackFrame
123 || element instanceof XDebugThread
124 || element instanceof XDebugTarget) {
125 return getDebugElementImage(element);
126 } else if (element instanceof XDebugVariable) {
127 return getVariableImage((XDebugVariable) element);
128 } else if (element instanceof XDebugValue) {
129 return getValueImage((XDebugValue) element);
131 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
134 // private Image getVariableImage(XDebugVariable phpVar) {
136 * if (phpVar != null) { if (phpVar.isLocal()) return
137 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
138 * (phpVar.isHashValue()) return
139 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
141 // return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
144 private Image getVariableImage(XDebugVariable phpVar) {
145 if (phpVar.getVisibility().equals("protected")) {
146 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PROTECTED);
147 } else if (phpVar.getVisibility().equals("private")) {
148 return (XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PRIVATE));
151 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PUBLIC);
153 private Image getValueImage(XDebugValue phpVar) {
154 if (phpVar != null) {
155 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
157 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
161 * @see IDebugModelPresentation#getText(Object)
163 public String getText(Object element) {
165 if (element instanceof XDebugLineBreakpoint) {
166 return getBreakpointText((IBreakpoint) element);
167 } else if (element instanceof XDebugVariable) {
168 XDebugVariable phpVar = (XDebugVariable) element;
169 return phpVar.getName() + "= " + phpVar.getValueString();//toString();
171 } catch (CoreException e) {
172 //return PHPDebugUiMessages
173 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
179 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
181 public void computeDetail(IValue value, IValueDetailListener listener) {
184 detail = value.getValueString();
185 } catch (DebugException e) {
187 listener.detailComputed(value, detail);
191 protected IBreakpoint getBreakpoint(IMarker marker) {
192 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
196 protected String getBreakpointText(IBreakpoint breakpoint)
197 throws CoreException {
198 if (breakpoint instanceof XDebugLineBreakpoint) {
199 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
201 return ""; //$NON-NLS-1$
204 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
205 throws CoreException {
206 StringBuffer label = new StringBuffer();
208 label.append(breakpoint.getMarker().getResource().getFullPath());
209 label.append(" ["); //$NON-NLS-1$
210 //label.append(PHPDebugUiMessages
211 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
213 label.append(breakpoint.getLineNumber());
216 /*if (breakpoint.getHitCount() > 0) {
217 label.append(" [skip count ");
218 label.append(breakpoint.getHitCount());
222 /*if (breakpoint.isConditionEnabled()) {
223 label.append(" [conditional]");
226 return label.toString();
230 * Returns the image associated with the given element or <code>null</code>
231 * if none is defined.
233 protected Image getDebugElementImage(Object element) {
235 if (element instanceof XDebugThread) {
236 XDebugThread thread = (XDebugThread) element;
237 if (thread.isSuspended()) {
239 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
240 } else if (thread.isTerminated()) {
242 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
245 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
247 } else if (element instanceof XDebugStackFrame) {
249 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
250 } else if (element instanceof XDebugTarget) {
251 XDebugTarget debugTarget = (XDebugTarget) element;
252 if (debugTarget.isTerminated()) {
254 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
257 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
263 class StorageEditorInput extends PlatformObject implements
264 IStorageEditorInput {
267 private IStorage fStorage;
269 public StorageEditorInput(IStorage storage, File file) {
275 public IStorage getStorage() {
279 public ImageDescriptor getImageDescriptor() {
283 public String getName() {
284 return getStorage().getName();
287 public IPersistableElement getPersistable() {
291 public String getToolTipText() {
292 return getStorage().getFullPath().toOSString();
295 public boolean equals(Object object) {
296 return object instanceof StorageEditorInput
297 && getStorage().equals(
298 ((StorageEditorInput) object).getStorage());
301 public int hashCode() {
302 return getStorage().hashCode();
305 public boolean exists() {
306 return fFile.exists();