KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JavaBreakpointWorkbenchAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IAdapterFactory;
15 import org.eclipse.jdt.core.IMember;
16 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
17 import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
18 import org.eclipse.jdt.debug.core.IJavaPatternBreakpoint;
19 import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint;
20 import org.eclipse.jdt.debug.core.IJavaTargetPatternBreakpoint;
21 import org.eclipse.jdt.ui.JavaElementLabelProvider;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.ui.model.IWorkbenchAdapter;
24
25 /**
26  * Adapter factory for java breakpoints.
27  */

28 public class JavaBreakpointWorkbenchAdapterFactory implements IAdapterFactory {
29     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
30         if (adapterType != IWorkbenchAdapter.class || !(adaptableObject instanceof IJavaBreakpoint)) {
31             return null;
32         }
33         return new IWorkbenchAdapter() {
34             private JavaElementLabelProvider fJavaLabelProvider;
35
36             public Object JavaDoc[] getChildren(Object JavaDoc o) {
37                 return null;
38             }
39
40             public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
41                 return null;
42             }
43
44             /**
45              * Returns a label for breakpoints that doesn't include information
46              * which the user can edit. This assures that this label can be used
47              * in situations where the user is changing values (like the title bar
48              * of the property dialog).
49              */

50             public String JavaDoc getLabel(Object JavaDoc o) {
51                 if (!(o instanceof IJavaBreakpoint)) {
52                     return null;
53                 }
54                 IJavaBreakpoint breakpoint = (IJavaBreakpoint) o;
55                 StringBuffer JavaDoc label = new StringBuffer JavaDoc();
56                 try {
57                     String JavaDoc type= breakpoint.getTypeName();
58                     if (type != null) {
59                         label.append(type);
60                     }
61                 } catch (CoreException e) {
62                     JDIDebugUIPlugin.log(e);
63                 }
64                 if (breakpoint instanceof IJavaPatternBreakpoint) {
65                     try {
66                         label.append(((IJavaPatternBreakpoint) breakpoint).getSourceName());
67                     } catch (CoreException e) {
68                         JDIDebugUIPlugin.log(e);
69                     }
70                 } else if (breakpoint instanceof IJavaTargetPatternBreakpoint) {
71                     try {
72                         label.append(((IJavaTargetPatternBreakpoint) breakpoint).getSourceName());
73                     } catch (CoreException e) {
74                         JDIDebugUIPlugin.log(e);
75                     }
76                 } else if (breakpoint instanceof IJavaStratumLineBreakpoint) {
77                     try {
78                         label.append(((IJavaStratumLineBreakpoint) breakpoint).getSourceName());
79                     } catch (CoreException e) {
80                         JDIDebugUIPlugin.log(e);
81                     }
82                 }
83                 if (breakpoint instanceof IJavaLineBreakpoint) {
84                     IJavaLineBreakpoint lineBreakpoint= ((IJavaLineBreakpoint) breakpoint);
85                     try {
86                         int lineNumber= lineBreakpoint.getLineNumber();
87                         if (lineNumber != -1) {
88                             label.append(DebugUIMessages.JavaBreakpointWorkbenchAdapterFactory_1);
89                             label.append(lineNumber);
90                             label.append(']');
91                         }
92                     } catch (CoreException e) {
93                         JDIDebugUIPlugin.log(e);
94                     }
95                     try {
96                         IMember member= BreakpointUtils.getMember(lineBreakpoint);
97                         if (member != null) {
98                             label.append(" - "); //$NON-NLS-1$
99
label.append(getJavaLabelProvider().getText(member));
100                         }
101                     } catch (CoreException e) {
102                         JDIDebugUIPlugin.log(e);
103                     }
104                 }
105                 return label.toString();
106             }
107
108             public Object JavaDoc getParent(Object JavaDoc o) {
109                 return null;
110             }
111             
112             protected JavaElementLabelProvider getJavaLabelProvider() {
113                 if (fJavaLabelProvider == null) {
114                     fJavaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
115                 }
116                 return fJavaLabelProvider;
117             }
118         };
119     }
120
121     public Class JavaDoc[] getAdapterList() {
122         return new Class JavaDoc[] { IWorkbenchAdapter.class };
123     }
124 }
125
Popular Tags