KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.monitors;
12
13 import org.eclipse.core.runtime.IAdapterFactory;
14 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
15 import org.eclipse.jdt.debug.core.IJavaStackFrame;
16 import org.eclipse.jdt.debug.core.IJavaThread;
17 import org.eclipse.jdt.internal.debug.ui.variables.JavaStackFrameContentProvider;
18
19 /**
20  * Adapter factory that generates content adapters for java debug elements to
21  * provide thread monitor information in the debug view.
22  */

23 public class MonitorsAdapterFactory implements IAdapterFactory {
24     
25     private static IElementContentProvider fgCPThread;
26     private static IElementContentProvider fgCPFrame = new JavaStackFrameContentProvider();
27     private static IElementContentProvider fgCPOwnedMonitor;
28     private static IElementContentProvider fgCPWaitingThread;
29     private static IElementContentProvider fgCPContendedMonitor;
30     private static IElementContentProvider fgCPOwningThread;
31     
32     /* (non-Javadoc)
33      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
34      */

35     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
36         
37         if (IElementContentProvider.class.equals(adapterType)) {
38             if (adaptableObject instanceof IJavaThread) {
39                 return getThreadPresentation();
40             }
41             if (adaptableObject instanceof IJavaStackFrame) {
42                 return fgCPFrame;
43             }
44             if (adaptableObject instanceof JavaOwnedMonitor) {
45                 return getOwnedMonitorContentProvider();
46             }
47             if (adaptableObject instanceof JavaWaitingThread) {
48                 return getWaitingThreadContentProvider();
49             }
50             if (adaptableObject instanceof JavaContendedMonitor) {
51                 return getContendedMonitorContentProvider();
52             }
53             if (adaptableObject instanceof JavaOwningThread) {
54                 return getOwningThreadContentProvider();
55             }
56         }
57         return null;
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
62      */

63     public Class JavaDoc[] getAdapterList() {
64         return new Class JavaDoc[] {IElementContentProvider.class};
65     }
66
67     private IElementContentProvider getThreadPresentation() {
68         if (fgCPThread == null) {
69             fgCPThread = new JavaThreadContentProvider();
70         }
71         return fgCPThread;
72     }
73     
74     private IElementContentProvider getOwnedMonitorContentProvider() {
75         if (fgCPOwnedMonitor == null) {
76             fgCPOwnedMonitor = new OwnedMonitorContentProvider();
77         }
78         return fgCPOwnedMonitor;
79     }
80     
81     private IElementContentProvider getWaitingThreadContentProvider() {
82         if (fgCPWaitingThread == null) {
83             fgCPWaitingThread = new WaitingThreadContentProvider();
84         }
85         return fgCPWaitingThread;
86     }
87     
88     private IElementContentProvider getContendedMonitorContentProvider() {
89         if (fgCPContendedMonitor == null) {
90             fgCPContendedMonitor = new ContendedMonitorContentProvider();
91         }
92         return fgCPContendedMonitor;
93     }
94     
95     private IElementContentProvider getOwningThreadContentProvider() {
96         if (fgCPOwningThread == null) {
97             fgCPOwningThread = new OwningThreadContentProvider();
98         }
99         return fgCPOwningThread;
100     }
101 }
102
Popular Tags