Merged xdebug from 1.3.x
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / php / launching / PHPDebugModelPresentation.java
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
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  Vicente Fernando - www.alfersoft.com.ar
11  **********************************************************************/
12 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
13
14 import java.util.HashMap;
15
16 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint;
17
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;
24
25 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
26
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;
30
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;
48
49 /**
50  * @see IDebugModelPresentation
51  */
52 public class PHPDebugModelPresentation extends LabelProvider implements
53                 IDebugModelPresentation {
54
55         protected HashMap fAttributes = new HashMap(3);
56
57         public PHPDebugModelPresentation() {
58                 super();
59         }
60
61         /**
62          * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
63          */
64         public String getEditorId(IEditorInput input, Object inputObject) {
65                 IEditorRegistry registry = PlatformUI.getWorkbench()
66                                 .getEditorRegistry();
67                 IEditorDescriptor descriptor = registry.getDefaultEditor(input
68                                 .getName());
69                 if (descriptor != null)
70                         return descriptor.getId();
71
72                 return null;
73         }
74
75         /**
76          * @see IDebugModelPresentation#setAttribute(String, Object)
77          */
78         public void setAttribute(String id, Object value) {
79                 if (value == null) {
80                         return;
81                 }
82                 fAttributes.put(id, value);
83         }
84
85         /**
86          * @see IDebugModelPresentation#getEditorInput(Object)
87          */
88         public IEditorInput getEditorInput(Object item) {
89
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());
95                         
96                         IFile eclipseFile = null; //XDebugUIPlugin.getWorkspace().getRoot()
97                                         //.getFile(ma.getResource().getFullPath());
98                         if (eclipseFile == null) {
99                                 return null;
100                         }
101                         return new FileEditorInput(eclipseFile);
102                 }
103                 return null;
104         }
105
106         /**
107          * @see IDebugModelPresentation#getImage(Object)
108          */
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);
122                 }
123                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
124         }
125
126         private Image getVariableImage(XDebugVariable phpVar) {
127                 /*
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); }
132                  */
133                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
134         }
135
136         private Image getValueImage(XDebugValue phpVar) {
137                 if (phpVar != null) {
138                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
139                 }
140                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
141         }
142
143         /**
144          * @see IDebugModelPresentation#getText(Object)
145          */
146         public String getText(Object element) {
147                 try {
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();
153                         }
154                 } catch (CoreException e) {
155                         //return PHPDebugUiMessages
156                                 //      .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
157                 }
158                 return null;
159         }
160
161         /**
162          * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
163          */
164         public void computeDetail(IValue value, IValueDetailListener listener) {
165                 return;
166         }
167
168         protected IBreakpoint getBreakpoint(IMarker marker) {
169                 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
170                                 marker);
171         }
172
173         protected String getBreakpointText(IBreakpoint breakpoint)
174                         throws CoreException {
175                 if (breakpoint instanceof XDebugLineBreakpoint) {
176                         return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
177                 }
178                 return ""; //$NON-NLS-1$
179         }
180
181         protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
182                         throws CoreException {
183                 StringBuffer label = new StringBuffer();
184
185                 label.append(breakpoint.getMarker().getResource().getFullPath());
186                 label.append(" ["); //$NON-NLS-1$
187                 //label.append(PHPDebugUiMessages
188                         //      .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
189                 label.append(' ');
190                 label.append(breakpoint.getLineNumber());
191                 label.append(']');
192
193                 /*if (breakpoint.getHitCount() > 0) {
194                         label.append(" [skip count ");
195                         label.append(breakpoint.getHitCount());
196                         label.append(']');
197                 }*/
198
199                 /*if (breakpoint.isConditionEnabled()) {
200                         label.append(" [conditional]");
201                 }*/
202
203                 return label.toString();
204         }
205
206         /**
207          * Returns the image associated with the given element or <code>null</code>
208          * if none is defined.
209          */
210         protected Image getDebugElementImage(Object element) {
211                 Image image = null;
212                 if (element instanceof XDebugThread) {
213                         XDebugThread thread = (XDebugThread) element;
214                         if (thread.isSuspended()) {
215                                 image = DebugUITools
216                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
217                         } else if (thread.isTerminated()) {
218                                 image = DebugUITools
219                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
220                         } else {
221                                 image = DebugUITools
222                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
223                         }
224                 } else if (element instanceof XDebugStackFrame) {
225                         image = DebugUITools
226                                         .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
227                 } else if (element instanceof XDebugTarget) {
228                         XDebugTarget debugTarget = (XDebugTarget) element;
229                         if (debugTarget.isTerminated()) {
230                                 image = DebugUITools
231                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
232                         } else {
233                                 image = DebugUITools
234                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
235                         }
236                 }
237                 return image;
238         }
239 }