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.XDebugUIPlugin;
25 //import net.sourceforge.phpeclipse.xdebug.ui.php.launching.CopyOfPHPDebugModelPresentation.StorageEditorInput;
27 //import net.sourceforge.phpdt.internal.debug.core.model.IPHPDebugTarget;
29 //import net.sourceforge.phpdt.internal.debug.core.model.PHPThread;
30 //import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
31 //import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
33 import org.eclipse.core.resources.IFile;
34 import org.eclipse.core.resources.IMarker;
35 import org.eclipse.core.resources.IStorage;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.PlatformObject;
38 import org.eclipse.debug.core.DebugPlugin;
39 import org.eclipse.debug.core.model.IBreakpoint;
40 import org.eclipse.debug.core.model.ILineBreakpoint;
41 import org.eclipse.debug.core.model.IValue;
42 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
43 import org.eclipse.debug.ui.DebugUITools;
44 import org.eclipse.debug.ui.IDebugModelPresentation;
45 import org.eclipse.debug.ui.IDebugUIConstants;
46 import org.eclipse.debug.ui.IValueDetailListener;
47 import org.eclipse.jface.resource.ImageDescriptor;
48 import org.eclipse.jface.viewers.LabelProvider;
49 import org.eclipse.swt.graphics.Image;
50 import org.eclipse.ui.IEditorDescriptor;
51 import org.eclipse.ui.IEditorInput;
52 import org.eclipse.ui.IEditorRegistry;
53 import org.eclipse.ui.IPersistableElement;
54 import org.eclipse.ui.IStorageEditorInput;
55 import org.eclipse.ui.PlatformUI;
56 import org.eclipse.ui.part.FileEditorInput;
59 * @see IDebugModelPresentation
61 public class PHPDebugModelPresentation extends LabelProvider implements
62 IDebugModelPresentation {
64 protected HashMap fAttributes = new HashMap(3);
66 public PHPDebugModelPresentation() {
71 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
73 public String getEditorId(IEditorInput input, Object inputObject) {
74 IEditorRegistry registry = PlatformUI.getWorkbench()
76 IEditorDescriptor descriptor = registry.getDefaultEditor(input
78 if (descriptor != null)
79 return descriptor.getId();
85 * @see IDebugModelPresentation#setAttribute(String, Object)
87 public void setAttribute(String id, Object value) {
91 fAttributes.put(id, value);
95 * @see IDebugModelPresentation#getEditorInput(Object)
97 public IEditorInput getEditorInput(Object element) {
99 if (element instanceof IFile) {
100 return new FileEditorInput((IFile)element);
102 if( element instanceof LocalFileStorage) {
103 LocalFileStorage lfc= (LocalFileStorage)element;
104 return new StorageEditorInput(lfc,lfc.getFile());
106 if (element instanceof ILineBreakpoint) {
107 return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
113 * @see IDebugModelPresentation#getImage(Object)
115 public Image getImage(Object element) {
116 if (element instanceof XDebugLineBreakpoint) {
117 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
118 } else if (element instanceof IMarker) {
119 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
120 } else if (element instanceof XDebugStackFrame
121 || element instanceof XDebugThread
122 || element instanceof XDebugTarget) {
123 return getDebugElementImage(element);
124 } else if (element instanceof XDebugVariable) {
125 return getVariableImage((XDebugVariable) element);
126 } else if (element instanceof XDebugValue) {
127 return getValueImage((XDebugValue) element);
129 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
132 private Image getVariableImage(XDebugVariable phpVar) {
134 * if (phpVar != null) { if (phpVar.isLocal()) return
135 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); if
136 * (phpVar.isHashValue()) return
137 * DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE); }
139 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
142 private Image getValueImage(XDebugValue phpVar) {
143 if (phpVar != null) {
144 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
146 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
150 * @see IDebugModelPresentation#getText(Object)
152 public String getText(Object element) {
154 if (element instanceof XDebugLineBreakpoint) {
155 return getBreakpointText((IBreakpoint) element);
156 } else if (element instanceof XDebugVariable) {
157 XDebugVariable phpVar = (XDebugVariable) element;
158 return phpVar.toString();
160 } catch (CoreException e) {
161 //return PHPDebugUiMessages
162 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
168 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
170 public void computeDetail(IValue value, IValueDetailListener listener) {
174 protected IBreakpoint getBreakpoint(IMarker marker) {
175 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
179 protected String getBreakpointText(IBreakpoint breakpoint)
180 throws CoreException {
181 if (breakpoint instanceof XDebugLineBreakpoint) {
182 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
184 return ""; //$NON-NLS-1$
187 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
188 throws CoreException {
189 StringBuffer label = new StringBuffer();
191 label.append(breakpoint.getMarker().getResource().getFullPath());
192 label.append(" ["); //$NON-NLS-1$
193 //label.append(PHPDebugUiMessages
194 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
196 label.append(breakpoint.getLineNumber());
199 /*if (breakpoint.getHitCount() > 0) {
200 label.append(" [skip count ");
201 label.append(breakpoint.getHitCount());
205 /*if (breakpoint.isConditionEnabled()) {
206 label.append(" [conditional]");
209 return label.toString();
213 * Returns the image associated with the given element or <code>null</code>
214 * if none is defined.
216 protected Image getDebugElementImage(Object element) {
218 if (element instanceof XDebugThread) {
219 XDebugThread thread = (XDebugThread) element;
220 if (thread.isSuspended()) {
222 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
223 } else if (thread.isTerminated()) {
225 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
228 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
230 } else if (element instanceof XDebugStackFrame) {
232 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
233 } else if (element instanceof XDebugTarget) {
234 XDebugTarget debugTarget = (XDebugTarget) element;
235 if (debugTarget.isTerminated()) {
237 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
240 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
246 class StorageEditorInput extends PlatformObject implements
247 IStorageEditorInput {
250 private IStorage fStorage;
252 public StorageEditorInput(IStorage storage, File file) {
258 public IStorage getStorage() {
262 public ImageDescriptor getImageDescriptor() {
266 public String getName() {
267 return getStorage().getName();
270 public IPersistableElement getPersistable() {
274 public String getToolTipText() {
275 return getStorage().getFullPath().toOSString();
278 public boolean equals(Object object) {
279 return object instanceof StorageEditorInput
280 && getStorage().equals(
281 ((StorageEditorInput) object).getStorage());
284 public int hashCode() {
285 return getStorage().hashCode();
288 public boolean exists() {
289 return fFile.exists();