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