1 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 28 public class JavaBreakpointWorkbenchAdapterFactory implements IAdapterFactory { 29 public Object getAdapter(Object adaptableObject, Class 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 [] getChildren(Object o) { 37 return null; 38 } 39 40 public ImageDescriptor getImageDescriptor(Object object) { 41 return null; 42 } 43 44 50 public String getLabel(Object o) { 51 if (!(o instanceof IJavaBreakpoint)) { 52 return null; 53 } 54 IJavaBreakpoint breakpoint = (IJavaBreakpoint) o; 55 StringBuffer label = new StringBuffer (); 56 try { 57 String 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(" - "); 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 getParent(Object 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 [] getAdapterList() { 122 return new Class [] { IWorkbenchAdapter.class }; 123 } 124 } 125 | Popular Tags |