028eb2c3591d10b04e512e15a3e8965c9416f9a5
[phpeclipse.git] /
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.io.File;
15 import java.util.HashMap;
16
17 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugLineBreakpoint;
18
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;
27
28 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
29
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;
33
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.DebugPlugin;
40 import org.eclipse.debug.core.model.IBreakpoint;
41 import org.eclipse.debug.core.model.ILineBreakpoint;
42 import org.eclipse.debug.core.model.IValue;
43 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
44 import org.eclipse.debug.ui.DebugUITools;
45 import org.eclipse.debug.ui.IDebugModelPresentation;
46 import org.eclipse.debug.ui.IDebugUIConstants;
47 import org.eclipse.debug.ui.IValueDetailListener;
48 import org.eclipse.jface.resource.ImageDescriptor;
49 import org.eclipse.jface.viewers.LabelProvider;
50 import org.eclipse.swt.graphics.Image;
51 import org.eclipse.ui.IEditorDescriptor;
52 import org.eclipse.ui.IEditorInput;
53 import org.eclipse.ui.IEditorRegistry;
54 import org.eclipse.ui.IPersistableElement;
55 import org.eclipse.ui.IStorageEditorInput;
56 import org.eclipse.ui.PlatformUI;
57 import org.eclipse.ui.part.FileEditorInput;
58
59 /**
60  * @see IDebugModelPresentation
61  */
62 public class PHPDebugModelPresentation extends LabelProvider implements
63                 IDebugModelPresentation {
64
65         protected HashMap fAttributes = new HashMap(3);
66
67         public PHPDebugModelPresentation() {
68                 super();
69         }
70
71         /**
72          * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
73          */
74         public String getEditorId(IEditorInput input, Object inputObject) {
75                 IEditorRegistry registry = PlatformUI.getWorkbench()
76                                 .getEditorRegistry();
77                 IEditorDescriptor descriptor = registry.getDefaultEditor(input
78                                 .getName());
79                 if (descriptor != null)
80                         return descriptor.getId();
81
82                 return null;
83         }
84
85         /**
86          * @see IDebugModelPresentation#setAttribute(String, Object)
87          */
88         public void setAttribute(String id, Object value) {
89                 if (value == null) {
90                         return;
91                 }
92                 fAttributes.put(id, value);
93         }
94
95         /**
96          * @see IDebugModelPresentation#getEditorInput(Object)
97          */
98         public IEditorInput getEditorInput(Object element) {
99
100                 if (element instanceof IFile) {
101                         return new FileEditorInput((IFile)element);
102                 }
103                 if( element instanceof LocalFileStorage) {
104                         LocalFileStorage lfc= (LocalFileStorage)element;
105                         return new StorageEditorInput(lfc,lfc.getFile());
106                 }
107                 if (element instanceof ILineBreakpoint) {
108                         return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
109                 }
110                 return null;
111         }
112         
113         /**
114          * @see IDebugModelPresentation#getImage(Object)
115          */
116         public Image getImage(Object element) {
117                 if (element instanceof XDebugLineBreakpoint) {
118                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
119                 } else if (element instanceof IMarker) {
120                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
121                 } else if (element instanceof XDebugStackFrame
122                                 || element instanceof XDebugThread
123                                 || element instanceof XDebugTarget) {
124                         return getDebugElementImage(element);
125                 } else if (element instanceof XDebugVariable) {
126                         return getVariableImage((XDebugVariable) element);
127                 } else if (element instanceof XDebugValue) {
128                         return getValueImage((XDebugValue) element);
129                 }
130                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
131         }
132
133 //      private Image getVariableImage(XDebugVariable phpVar) {
134                 /*
135                  * if (phpVar != null) { if (phpVar.isLocal()) return
136                  * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
137                  * (phpVar.isHashValue()) return
138                  * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
139                  */
140         //      return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
141         //}
142         
143         private Image getVariableImage(XDebugVariable phpVar) {
144                 if (phpVar.getVisibility().equals("protected")) {
145                         return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PROTECTED);                      
146                 }  else if (phpVar.getVisibility().equals("private")) {
147                         return (XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PRIVATE));                      
148                 }
149
150                 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PUBLIC);                 
151         }
152         private Image getValueImage(XDebugValue phpVar) {
153                 if (phpVar != null) {
154                         return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
155                 }
156                 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
157         }
158
159         /**
160          * @see IDebugModelPresentation#getText(Object)
161          */
162         public String getText(Object element) {
163                 try {
164                         if (element instanceof XDebugLineBreakpoint) {
165                                 return getBreakpointText((IBreakpoint) element);
166                         } else if (element instanceof XDebugVariable) {
167                                 XDebugVariable phpVar = (XDebugVariable) element;
168                                 return phpVar.toString();
169                         }
170                 } catch (CoreException e) {
171                         //return PHPDebugUiMessages
172                                 //      .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
173                 }
174                 return null;
175         }
176
177         /**
178          * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
179          */
180         public void computeDetail(IValue value, IValueDetailListener listener) {
181                 return;
182         }
183
184         protected IBreakpoint getBreakpoint(IMarker marker) {
185                 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
186                                 marker);
187         }
188
189         protected String getBreakpointText(IBreakpoint breakpoint)
190                         throws CoreException {
191                 if (breakpoint instanceof XDebugLineBreakpoint) {
192                         return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
193                 }
194                 return ""; //$NON-NLS-1$
195         }
196
197         protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
198                         throws CoreException {
199                 StringBuffer label = new StringBuffer();
200
201                 label.append(breakpoint.getMarker().getResource().getFullPath());
202                 label.append(" ["); //$NON-NLS-1$
203                 //label.append(PHPDebugUiMessages
204                         //      .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
205                 label.append(' ');
206                 label.append(breakpoint.getLineNumber());
207                 label.append(']');
208
209                 /*if (breakpoint.getHitCount() > 0) {
210                         label.append(" [skip count ");
211                         label.append(breakpoint.getHitCount());
212                         label.append(']');
213                 }*/
214
215                 /*if (breakpoint.isConditionEnabled()) {
216                         label.append(" [conditional]");
217                 }*/
218
219                 return label.toString();
220         }
221
222         /**
223          * Returns the image associated with the given element or <code>null</code>
224          * if none is defined.
225          */
226         protected Image getDebugElementImage(Object element) {
227                 Image image = null;
228                 if (element instanceof XDebugThread) {
229                         XDebugThread thread = (XDebugThread) element;
230                         if (thread.isSuspended()) {
231                                 image = DebugUITools
232                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
233                         } else if (thread.isTerminated()) {
234                                 image = DebugUITools
235                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
236                         } else {
237                                 image = DebugUITools
238                                                 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
239                         }
240                 } else if (element instanceof XDebugStackFrame) {
241                         image = DebugUITools
242                                         .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
243                 } else if (element instanceof XDebugTarget) {
244                         XDebugTarget debugTarget = (XDebugTarget) element;
245                         if (debugTarget.isTerminated()) {
246                                 image = DebugUITools
247                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
248                         } else {
249                                 image = DebugUITools
250                                                 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
251                         }
252                 }
253                 return image;
254         }
255
256     class StorageEditorInput extends PlatformObject implements
257         IStorageEditorInput {
258 private File fFile;
259
260 private IStorage fStorage;
261
262 public StorageEditorInput(IStorage storage, File file) {
263         super();
264         fStorage = storage;
265         fFile = file;
266 }
267
268 public IStorage getStorage() {
269         return fStorage;
270 }
271
272 public ImageDescriptor getImageDescriptor() {
273         return null;
274 }
275
276 public String getName() {
277         return getStorage().getName();
278 }
279
280 public IPersistableElement getPersistable() {
281         return null;
282 }
283
284 public String getToolTipText() {
285         return getStorage().getFullPath().toOSString();
286 }
287
288 public boolean equals(Object object) {
289         return object instanceof StorageEditorInput
290                         && getStorage().equals(
291                                         ((StorageEditorInput) object).getStorage());
292 }
293
294 public int hashCode() {
295         return getStorage().hashCode();
296 }
297
298 public boolean exists() {
299         return fFile.exists();
300 }
301 }
302 }