Replace deprecated org.eclipse.jface.text.rules.DefaultPartitioner with org.eclipse...
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / 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.phpdt.internal.debug.ui;
13
14 import java.util.HashMap;
15
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;
22
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;
40
41 /**
42  * @see IDebugModelPresentation
43  */
44 public class PHPDebugModelPresentation extends LabelProvider implements
45                 IDebugModelPresentation {
46
47         protected HashMap fAttributes = new HashMap(3);
48
49         public PHPDebugModelPresentation() {
50                 super();
51         }
52
53         /**
54          * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
55          */
56         public String getEditorId(IEditorInput input, Object inputObject) {
57                 IEditorRegistry registry = PlatformUI.getWorkbench()
58                                 .getEditorRegistry();
59                 IEditorDescriptor descriptor = registry.getDefaultEditor(input
60                                 .getName());
61                 if (descriptor != null)
62                         return descriptor.getId();
63
64                 return null;
65         }
66
67         /**
68          * @see IDebugModelPresentation#setAttribute(String, Object)
69          */
70         public void setAttribute(String id, Object value) {
71                 if (value == null) {
72                         return;
73                 }
74                 fAttributes.put(id, value);
75         }
76
77         /**
78          * @see IDebugModelPresentation#getEditorInput(Object)
79          */
80         public IEditorInput getEditorInput(Object item) {
81
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                         IFile eclipseFile = PHPDebugUiPlugin.getWorkspace().getRoot()
88                                         .getFile(ma.getResource().getFullPath());
89                         if (eclipseFile == null) {
90                                 return null;
91                         }
92                         return new FileEditorInput(eclipseFile);
93                 }
94                 return null;
95         }
96
97         /**
98          * @see IDebugModelPresentation#getImage(Object)
99          */
100         public Image getImage(Object element) {
101                 if (element instanceof PHPLineBreakpoint) {
102                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
103                 } else if (element instanceof IMarker) {
104                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
105                 } else if (element instanceof PHPStackFrame
106                                 || element instanceof PHPThread
107                                 || element instanceof IPHPDebugTarget) {
108                         return getDebugElementImage(element);
109                 } else if (element instanceof PHPVariable) {
110                         return getVariableImage((PHPVariable) element);
111                 } else if (element instanceof PHPValue) {
112                         return getValueImage((PHPValue) element);
113                 }
114                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
115         }
116
117         private Image getVariableImage(PHPVariable phpVar) {
118                 /*
119                  * if (phpVar != null) { if (phpVar.isLocal()) return
120                  * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
121                  * (phpVar.isHashValue()) return
122                  * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
123                  */
124                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
125         }
126
127         private Image getValueImage(PHPValue phpVar) {
128                 if (phpVar != null) {
129                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
130                 }
131                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
132         }
133
134         /**
135          * @see IDebugModelPresentation#getText(Object)
136          */
137         public String getText(Object element) {
138                 try {
139                         if (element instanceof PHPLineBreakpoint) {
140                                 return getBreakpointText((IBreakpoint) element);
141                         } else if (element instanceof PHPVariable) {
142                                 PHPVariable phpVar = (PHPVariable) element;
143                                 return phpVar.toString();
144                         }
145                 } catch (CoreException e) {
146                         return PHPDebugUiMessages
147                                         .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
148                 }
149                 return null;
150         }
151
152         /**
153          * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
154          */
155         public void computeDetail(IValue value, IValueDetailListener listener) {
156                 return;
157         }
158
159         protected IBreakpoint getBreakpoint(IMarker marker) {
160                 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
161                                 marker);
162         }
163
164         protected String getBreakpointText(IBreakpoint breakpoint)
165                         throws CoreException {
166                 if (breakpoint instanceof PHPLineBreakpoint) {
167                         return getLineBreakpointText((PHPLineBreakpoint) breakpoint);
168                 }
169                 return ""; //$NON-NLS-1$
170         }
171
172         protected String getLineBreakpointText(PHPLineBreakpoint breakpoint)
173                         throws CoreException {
174                 StringBuffer label = new StringBuffer();
175
176                 label.append(breakpoint.getMarker().getResource().getFullPath());
177                 label.append(" ["); //$NON-NLS-1$
178                 label.append(PHPDebugUiMessages
179                                 .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
180                 label.append(' ');
181                 label.append(breakpoint.getLineNumber());
182                 label.append(']');
183
184                 if (breakpoint.getHitCount() > 0) {
185                         label.append(" [skip count ");
186                         label.append(breakpoint.getHitCount());
187                         label.append(']');
188                 }
189
190                 if (breakpoint.isConditionEnabled()) {
191                         label.append(" [conditional]");
192                 }
193
194                 return label.toString();
195         }
196
197         /**
198          * Returns the image associated with the given element or <code>null</code>
199          * if none is defined.
200          */
201         protected Image getDebugElementImage(Object element) {
202                 Image image = null;
203                 if (element instanceof PHPThread) {
204                         PHPThread thread = (PHPThread) element;
205                         if (thread.isSuspended()) {
206                                 image = DebugUITools
207                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
208                         } else if (thread.isTerminated()) {
209                                 image = DebugUITools
210                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
211                         } else {
212                                 image = DebugUITools
213                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
214                         }
215                 } else if (element instanceof PHPStackFrame) {
216                         image = DebugUITools
217                                         .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
218                 } else if (element instanceof IPHPDebugTarget) {
219                         IPHPDebugTarget debugTarget = (IPHPDebugTarget) element;
220                         if (debugTarget.isTerminated()) {
221                                 image = DebugUITools
222                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
223                         } else {
224                                 image = DebugUITools
225                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
226                         }
227                 }
228                 return image;
229         }
230 }