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 if (((IMarker) element).getAttribute(IBreakpoint.ENABLED, false)) {
122 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
124 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED);
126 } else if (element instanceof XDebugStackFrame
127 || element instanceof XDebugThread
128 || element instanceof XDebugTarget) {
129 return getDebugElementImage(element);
130 } else if (element instanceof XDebugVariable) {
131 return getVariableImage((XDebugVariable) element);
132 } else if (element instanceof XDebugValue) {
133 return getValueImage((XDebugValue) element);
135 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
138 private Image getVariableImage(XDebugVariable phpVar) {
139 if (phpVar.getVisibility().equals("protected")) {
140 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PROTECTED);
141 } else if (phpVar.getVisibility().equals("private")) {
142 return (XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PRIVATE));
145 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PUBLIC);
147 private Image getValueImage(XDebugValue phpVar) {
148 if (phpVar != null) {
149 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
151 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
155 * @see IDebugModelPresentation#getText(Object)
157 public String getText(Object element) {
159 if (element instanceof XDebugLineBreakpoint) {
160 return getBreakpointText((IBreakpoint) element);
161 } else if (element instanceof XDebugVariable) {
162 XDebugVariable phpVar = (XDebugVariable) element;
163 return phpVar.getName() + "= " + phpVar.getValueString();//toString();
165 } catch (CoreException e) {
166 //return PHPDebugUiMessages
167 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
173 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
175 public void computeDetail(IValue value, IValueDetailListener listener) {
178 detail = value.getValueString();
179 } catch (DebugException e) {
181 listener.detailComputed(value, detail);
185 protected IBreakpoint getBreakpoint(IMarker marker) {
186 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
190 protected String getBreakpointText(IBreakpoint breakpoint)
191 throws CoreException {
192 if (breakpoint instanceof XDebugLineBreakpoint) {
193 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
195 return ""; //$NON-NLS-1$
198 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
199 throws CoreException {
200 StringBuffer label = new StringBuffer();
202 label.append(breakpoint.getMarker().getResource().getFullPath());
203 label.append(" ["); //$NON-NLS-1$
204 //label.append(PHPDebugUiMessages
205 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
207 label.append(breakpoint.getLineNumber());
210 /*if (breakpoint.getHitCount() > 0) {
211 label.append(" [skip count ");
212 label.append(breakpoint.getHitCount());
216 /*if (breakpoint.isConditionEnabled()) {
217 label.append(" [conditional]");
220 return label.toString();
224 * Returns the image associated with the given element or <code>null</code>
225 * if none is defined.
227 protected Image getDebugElementImage(Object element) {
229 if (element instanceof XDebugThread) {
230 XDebugThread thread = (XDebugThread) element;
231 if (thread.isSuspended()) {
233 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
234 } else if (thread.isTerminated()) {
236 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
239 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
241 } else if (element instanceof XDebugStackFrame) {
243 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
244 } else if (element instanceof XDebugTarget) {
245 XDebugTarget debugTarget = (XDebugTarget) element;
246 if (debugTarget.isTerminated()) {
248 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
251 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
257 class StorageEditorInput extends PlatformObject implements
258 IStorageEditorInput {
261 private IStorage fStorage;
263 public StorageEditorInput(IStorage storage, File file) {
269 public IStorage getStorage() {
273 public ImageDescriptor getImageDescriptor() {
277 public String getName() {
278 return getStorage().getName();
281 public IPersistableElement getPersistable() {
285 public String getToolTipText() {
286 return getStorage().getFullPath().toOSString();
289 public boolean equals(Object object) {
290 return object instanceof StorageEditorInput
291 && getStorage().equals(
292 ((StorageEditorInput) object).getStorage());
295 public int hashCode() {
296 return getStorage().hashCode();
299 public boolean exists() {
300 return fFile.exists();