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.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;
60 * @see IDebugModelPresentation
62 public class PHPDebugModelPresentation extends LabelProvider implements
63 IDebugModelPresentation {
65 protected HashMap fAttributes = new HashMap(3);
67 public PHPDebugModelPresentation() {
72 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
74 public String getEditorId(IEditorInput input, Object inputObject) {
75 IEditorRegistry registry = PlatformUI.getWorkbench()
77 IEditorDescriptor descriptor = registry.getDefaultEditor(input
79 if (descriptor != null)
80 return descriptor.getId();
86 * @see IDebugModelPresentation#setAttribute(String, Object)
88 public void setAttribute(String id, Object value) {
92 fAttributes.put(id, value);
96 * @see IDebugModelPresentation#getEditorInput(Object)
98 public IEditorInput getEditorInput(Object element) {
100 if (element instanceof IFile) {
101 return new FileEditorInput((IFile)element);
103 if( element instanceof LocalFileStorage) {
104 LocalFileStorage lfc= (LocalFileStorage)element;
105 return new StorageEditorInput(lfc,lfc.getFile());
107 if (element instanceof ILineBreakpoint) {
108 return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
114 * @see IDebugModelPresentation#getImage(Object)
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);
130 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT);
133 // private Image getVariableImage(XDebugVariable phpVar) {
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); }
140 // return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
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));
150 return XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_FIELD_PUBLIC);
152 private Image getValueImage(XDebugValue phpVar) {
153 if (phpVar != null) {
154 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
156 return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_VARIABLE);
160 * @see IDebugModelPresentation#getText(Object)
162 public String getText(Object element) {
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();
170 } catch (CoreException e) {
171 //return PHPDebugUiMessages
172 // .getString("PHPDebugModelPresentation.<not responding>"); //$NON-NLS-1$
178 * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
180 public void computeDetail(IValue value, IValueDetailListener listener) {
184 protected IBreakpoint getBreakpoint(IMarker marker) {
185 return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(
189 protected String getBreakpointText(IBreakpoint breakpoint)
190 throws CoreException {
191 if (breakpoint instanceof XDebugLineBreakpoint) {
192 return getLineBreakpointText((XDebugLineBreakpoint) breakpoint);
194 return ""; //$NON-NLS-1$
197 protected String getLineBreakpointText(XDebugLineBreakpoint breakpoint)
198 throws CoreException {
199 StringBuffer label = new StringBuffer();
201 label.append(breakpoint.getMarker().getResource().getFullPath());
202 label.append(" ["); //$NON-NLS-1$
203 //label.append(PHPDebugUiMessages
204 // .getString("PHPDebugModelPresentation.line")); //$NON-NLS-1$
206 label.append(breakpoint.getLineNumber());
209 /*if (breakpoint.getHitCount() > 0) {
210 label.append(" [skip count ");
211 label.append(breakpoint.getHitCount());
215 /*if (breakpoint.isConditionEnabled()) {
216 label.append(" [conditional]");
219 return label.toString();
223 * Returns the image associated with the given element or <code>null</code>
224 * if none is defined.
226 protected Image getDebugElementImage(Object element) {
228 if (element instanceof XDebugThread) {
229 XDebugThread thread = (XDebugThread) element;
230 if (thread.isSuspended()) {
232 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
233 } else if (thread.isTerminated()) {
235 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED);
238 .getImage(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
240 } else if (element instanceof XDebugStackFrame) {
242 .getImage(IDebugUIConstants.IMG_OBJS_STACKFRAME);
243 } else if (element instanceof XDebugTarget) {
244 XDebugTarget debugTarget = (XDebugTarget) element;
245 if (debugTarget.isTerminated()) {
247 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED);
250 .getImage(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET);
256 class StorageEditorInput extends PlatformObject implements
257 IStorageEditorInput {
260 private IStorage fStorage;
262 public StorageEditorInput(IStorage storage, File file) {
268 public IStorage getStorage() {
272 public ImageDescriptor getImageDescriptor() {
276 public String getName() {
277 return getStorage().getName();
280 public IPersistableElement getPersistable() {
284 public String getToolTipText() {
285 return getStorage().getFullPath().toOSString();
288 public boolean equals(Object object) {
289 return object instanceof StorageEditorInput
290 && getStorage().equals(
291 ((StorageEditorInput) object).getStorage());
294 public int hashCode() {
295 return getStorage().hashCode();
298 public boolean exists() {
299 return fFile.exists();