KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > monitors > MonitorModelPresentation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation 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 API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.monitors;
12
13
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IValue;
16 import org.eclipse.debug.ui.DebugUITools;
17 import org.eclipse.debug.ui.IDebugModelPresentation;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.debug.ui.IValueDetailListener;
20 import org.eclipse.jdt.debug.core.IJavaObject;
21 import org.eclipse.jdt.debug.core.IJavaThread;
22 import org.eclipse.jdt.internal.debug.ui.ImageDescriptorRegistry;
23 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
24 import org.eclipse.jdt.internal.debug.ui.JDIImageDescriptor;
25 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.viewers.LabelProvider;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.ui.IEditorInput;
30
31 /**
32  * @see IDebugModelPresentation
33  */

34 public class MonitorModelPresentation extends LabelProvider implements IDebugModelPresentation {
35
36     protected ImageDescriptorRegistry fDebugImageRegistry= JDIDebugUIPlugin.getImageDescriptorRegistry();
37             
38     /**
39      * @see IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
40      */

41     public void computeDetail(IValue value, IValueDetailListener listener) {
42     }
43             
44     /**
45      * @see IDebugModelPresentation#getText(Object)
46      */

47     public String JavaDoc getText(Object JavaDoc item) {
48             
49         if (item instanceof DeadLocksViewContentProvider.ContentThreadWrapper) {
50             return getThreadDeadLockText((DeadLocksViewContentProvider.ContentThreadWrapper)item);
51         } else if (item instanceof DeadLocksViewContentProvider.ContentMonitorWrapper) {
52             StringBuffer JavaDoc res= new StringBuffer JavaDoc();
53             res.append(((DeadLocksViewContentProvider.ContentMonitorWrapper)item).fMonitor.toString());
54             res.append(MonitorMessages.getString("MonitorModelPresentation._owned_by..._1")); //$NON-NLS-1$
55
return res.toString();
56         } else if (item instanceof IJavaObject) {
57             return getMonitorText((IJavaObject)item);
58         } else if (item instanceof IJavaThread) {
59             return getThreadText((IJavaThread)item);
60         } else if (item instanceof ThreadsViewContentProvider.MonitorWrapper) {
61             return getMonitorWrapperText((ThreadsViewContentProvider.MonitorWrapper)item);
62         } else if (item instanceof MonitorsViewContentProvider.ThreadWrapper) {
63             return getThreadWrapperMonitorText((MonitorsViewContentProvider.ThreadWrapper)item);
64         } else if (item instanceof ThreadsViewContentProvider.ThreadWrapper) {
65             return getThreadWrapperThreadText((ThreadsViewContentProvider.ThreadWrapper)item);
66         } else {
67             return MonitorMessages.getString("MonitorModelPresentation.unsuported_type_1"); //$NON-NLS-1$
68
}
69     }
70
71     /**
72      * Text for a ThreadWrapper in DeadLocksViewContentProvider
73      */

74     protected String JavaDoc getThreadDeadLockText(DeadLocksViewContentProvider.ContentThreadWrapper thread){
75         StringBuffer JavaDoc res= new StringBuffer JavaDoc();
76         try{
77             res.append(thread.fThread.getName());
78         } catch(DebugException e){
79         }
80         
81         if(thread.caughtInADeadLock){
82             res.append(MonitorMessages.getString("MonitorModelPresentation._(caught_in_the_deadlock)_2")); //$NON-NLS-1$
83
} else {
84             res.append(MonitorMessages.getString("MonitorModelPresentation._waiting_for..._2")); //$NON-NLS-1$
85
}
86         return res.toString();
87     }
88
89     /**
90      * Text for monitors
91      */

92     protected String JavaDoc getMonitorText(IJavaObject monitor) {
93         return monitor.toString();
94     }
95
96     /**
97      * Text for MonitorWrapper in ThreadsViewContentProvider
98      */

99     protected String JavaDoc getMonitorWrapperText(ThreadsViewContentProvider.MonitorWrapper monitor) {
100         StringBuffer JavaDoc res= new StringBuffer JavaDoc(monitor.monitor.toString());
101         if(monitor.state==ThreadsViewContentProvider.MonitorWrapper.OWNED_MONITOR) {
102             res.append(MonitorMessages.getString("MonitorModelPresentation._(owned)_4")); //$NON-NLS-1$
103
} else if(monitor.state==ThreadsViewContentProvider.MonitorWrapper.CONTENDED_MONITOR) {
104             res.append(MonitorMessages.getString("MonitorModelPresentation._(contended)_5")); //$NON-NLS-1$
105
}
106         return res.toString();
107     }
108
109     /**
110      * Text for ThreadWrapper in ThreadsViewContentProvider
111      */

112     protected String JavaDoc getThreadWrapperThreadText(ThreadsViewContentProvider.ThreadWrapper thread) {
113         StringBuffer JavaDoc res= new StringBuffer JavaDoc();
114         try{
115             res.append(thread.thread.getName());
116         } catch(DebugException e){
117         }
118         
119         if(thread.isCaughtInDeadlock) {
120             res.append(MonitorMessages.getString("MonitorModelPresentation._(caught_in_a_deadlock)_6")); //$NON-NLS-1$
121
}
122         return res.toString();
123     }
124
125     /**
126      * Text for ThreadWrapper in MonitorsViewContentProvider
127      */

128     protected String JavaDoc getThreadWrapperMonitorText(MonitorsViewContentProvider.ThreadWrapper thread) {
129         StringBuffer JavaDoc res= new StringBuffer JavaDoc();
130         try{
131             res.append(thread.thread.getName());
132         } catch(DebugException e){
133         }
134         
135         if(thread.state == MonitorsViewContentProvider.ThreadWrapper.OWNING_THREAD) {
136             res.append(MonitorMessages.getString("MonitorModelPresentation._(owning)_7")); //$NON-NLS-1$
137
} else if(thread.state == MonitorsViewContentProvider.ThreadWrapper.IN_CONTENTION_FOR_MONITOR) {
138             res.append(MonitorMessages.getString("MonitorModelPresentation._(contending)_8")); //$NON-NLS-1$
139
}
140         return res.toString();
141     }
142
143     /**
144      * Text for threads
145      */

146     protected String JavaDoc getThreadText(IJavaThread thread){
147         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
148         try{
149             res.append(thread.getName());
150         } catch(DebugException e){
151         }
152         return res.toString();
153     }
154
155     /**
156      * Maps an element to an appropriate image.
157      *
158      * @see IDebugModelPresentation#getImage(Object)
159      */

160     public Image getImage(Object JavaDoc item) {
161                 
162         if (item instanceof ThreadsViewContentProvider.ThreadWrapper) {
163             return getThreadWrapperThreadImage(((ThreadsViewContentProvider.ThreadWrapper)item).thread);
164         } else if (item instanceof ThreadsViewContentProvider.MonitorWrapper) {
165             ThreadsViewContentProvider.MonitorWrapper monitorWrapper= (ThreadsViewContentProvider.MonitorWrapper)item;
166             JDIImageDescriptor descriptor= null;
167             int flags= computeMonitorAdornmentFlags(monitorWrapper);
168             descriptor= new JDIImageDescriptor(JavaDebugImages.DESC_OBJ_MONITOR, flags);
169             return fDebugImageRegistry.get(descriptor);
170         } else if (item instanceof MonitorsViewContentProvider.ThreadWrapper) {
171             MonitorsViewContentProvider.ThreadWrapper threadWrapper= (MonitorsViewContentProvider.ThreadWrapper)item;
172             JDIImageDescriptor descriptor= null;
173             int flags= computeThreadAdornmentFlags(threadWrapper);
174             if (threadWrapper.thread.isSuspended()) {
175                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED), flags);
176             } else {
177                 descriptor= new JDIImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING), flags);
178             }
179             return fDebugImageRegistry.get(descriptor);
180         } else if (item instanceof IJavaObject) {
181             return getMonitorImage();
182         } else if (item instanceof DeadLocksViewContentProvider.ContentMonitorWrapper) {
183             return getMonitorImage();
184             
185         } else if (item instanceof DeadLocksViewContentProvider.ContentThreadWrapper ) {
186             return getThreadWrapperThreadImage(((DeadLocksViewContentProvider.ContentThreadWrapper)item).fThread);
187         }
188         
189         return null;
190     }
191
192     /**
193      * Image for a ThreadWrapper in ThreadsViewContentProvider
194      */

195     private Image getThreadWrapperThreadImage(IJavaThread thread){
196         ImageDescriptor descriptor= null;
197         if (thread.isSuspended()) {
198             descriptor= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED);
199         } else {
200             descriptor= DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_THREAD_RUNNING);
201         }
202         return fDebugImageRegistry.get(descriptor);
203     }
204
205     /**
206      * Image for monitors
207      */

208     private Image getMonitorImage(){
209         return fDebugImageRegistry.get(JavaDebugImages.DESC_OBJ_MONITOR);
210     }
211
212     /**
213      * @see IDebugModelPresentation#getEditorInput(Object)
214      */

215     public IEditorInput getEditorInput(Object JavaDoc item) {
216         return null;
217     }
218
219     /**
220      * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
221      */

222     public String JavaDoc getEditorId(IEditorInput input, Object JavaDoc inputObject) {
223         return null;
224     }
225
226     /**
227      * @see IDebugModelPresentation#setAttribute(String, Object)
228      */

229     public void setAttribute(String JavaDoc id, Object JavaDoc value) {
230     }
231     
232     /**
233      * Returns the adornment flags for the monitor.
234      * These flags are used to render appropriate overlay
235      * icons for the monitor.
236      */

237     private int computeMonitorAdornmentFlags(ThreadsViewContentProvider.MonitorWrapper wrapper) {
238         int flags= 0;
239         
240         if (wrapper.state == ThreadsViewContentProvider.MonitorWrapper.CONTENDED_MONITOR) {
241             flags |= JDIImageDescriptor.CONTENTED_MONITOR;
242         }
243         if (wrapper.state == ThreadsViewContentProvider.MonitorWrapper.OWNED_MONITOR) {
244             flags |= JDIImageDescriptor.OWNED_MONITOR;
245         }
246         return flags;
247     }
248     
249     /**
250      * Returns the adornment flags for the thread.
251      * These flags are used to render appropriate overlay
252      * icons for the thread.
253      */

254     private int computeThreadAdornmentFlags(MonitorsViewContentProvider.ThreadWrapper wrapper) {
255         int flags= 0;
256         
257         if (wrapper.state == MonitorsViewContentProvider.ThreadWrapper.IN_CONTENTION_FOR_MONITOR) {
258             flags |= JDIImageDescriptor.IN_CONTENTION_FOR_MONITOR;
259         }
260         if (wrapper.state == MonitorsViewContentProvider.ThreadWrapper.OWNING_THREAD) {
261             flags |= JDIImageDescriptor.OWNS_MONITOR;
262         }
263         return flags;
264     }
265 }
266
Popular Tags