1 11 12 package org.eclipse.ant.internal.ui.debug.model; 13 14 import java.io.File ; 15 16 import org.eclipse.ant.internal.ui.AntUIPlugin; 17 import org.eclipse.ant.internal.ui.preferences.AntObjectLabelProvider; 18 import org.eclipse.core.filesystem.EFS; 19 import org.eclipse.core.filesystem.IFileStore; 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IMarker; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.debug.core.DebugException; 24 import org.eclipse.debug.core.model.IBreakpoint; 25 import org.eclipse.debug.core.model.ILineBreakpoint; 26 import org.eclipse.debug.core.model.IValue; 27 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; 28 import org.eclipse.debug.ui.IDebugModelPresentation; 29 import org.eclipse.debug.ui.IValueDetailListener; 30 import org.eclipse.jface.viewers.LabelProvider; 31 import org.eclipse.swt.graphics.Image; 32 import org.eclipse.ui.IEditorInput; 33 import org.eclipse.ui.ide.FileStoreEditorInput; 34 import org.eclipse.ui.part.FileEditorInput; 35 36 import com.ibm.icu.text.MessageFormat; 37 38 41 public class AntDebugModelPresentation extends LabelProvider implements IDebugModelPresentation { 42 43 46 public void setAttribute(String attribute, Object value) { 47 } 48 49 52 public Image getImage(Object element) { 53 if (element instanceof AntProperty) { 54 return AntObjectLabelProvider.getPropertyImage(); 55 } else if (element instanceof AntProperties) { 56 return AntObjectLabelProvider.getPropertyImage(); 57 } 58 return null; 59 } 60 61 64 public String getText(Object element) { 65 if (element instanceof AntStackFrame) { 66 AntStackFrame frame= (AntStackFrame) element; 67 return getStackFrameText(frame); 68 } else if (element instanceof AntThread) { 69 AntThread thread= (AntThread) element; 70 return getThreadText(thread); 71 } else if (element instanceof AntProperty) { 72 AntProperty property= (AntProperty) element; 73 return property.getText(); 74 } else if (element instanceof AntProperties) { 75 return ((AntProperties)element).getName(); 76 } 77 78 return null; 79 } 80 81 private String getThreadText(AntThread thread) { 82 String name= thread.getName(); 83 if (name != null) { 84 StringBuffer text= new StringBuffer (name); 85 if (thread.isSuspended()) { 86 IBreakpoint[] breakpoints= thread.getBreakpoints(); 87 if (breakpoints.length > 0) { 88 AntLineBreakpoint breakpoint= (AntLineBreakpoint) breakpoints[0]; 89 IMarker marker= breakpoint.getMarker(); 90 String fileName= marker.getResource().getFullPath().lastSegment(); 91 String lineNumber= Integer.toString(marker.getAttribute(IMarker.LINE_NUMBER, -1)); 92 String breakpointString= null; 93 if (breakpoint.isRunToLine()) { 94 breakpointString= MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_5, new String [] {lineNumber, fileName}); 95 } else { 96 breakpointString= MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_2, new String []{lineNumber, fileName}); 97 } 98 text.append(MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_3, new String []{breakpointString})); 99 } else { 100 text.append(DebugModelMessages.AntDebugModelPresentation_4); 101 } 102 } 103 104 return text.toString(); 105 } 106 return null; 107 } 108 109 private String getStackFrameText(AntStackFrame frame) { 110 String name= frame.getName(); 111 if (name != null) { 112 StringBuffer text= new StringBuffer (name); 113 int lineNumber= frame.getLineNumber(); 114 String lineNumberString= null; 115 if (lineNumber == 0) { 116 lineNumberString= DebugModelMessages.AntDebugModelPresentation_0; 117 } else { 118 lineNumberString= Integer.toString(lineNumber); 119 } 120 text.append(MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_1, new String []{lineNumberString})); 121 return text.toString(); 122 } 123 return null; 124 } 125 126 129 public void computeDetail(IValue value, IValueDetailListener listener) { 130 String detail = ""; try { 132 detail = value.getValueString(); 133 } catch (DebugException e) { 134 } 135 listener.detailComputed(value, detail); 136 } 137 138 141 public IEditorInput getEditorInput(Object element) { 142 if (element instanceof IFile) { 143 return new FileEditorInput((IFile)element); 144 } 145 if (element instanceof ILineBreakpoint) { 146 return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); 147 } 148 if (element instanceof LocalFileStorage) { 149 File file= ((LocalFileStorage)element).getFile(); 150 IFileStore fileStore; 151 try { 152 fileStore = EFS.getStore(file.toURI()); 153 return new FileStoreEditorInput(fileStore); 154 } catch (CoreException e) { 155 AntUIPlugin.log(e); 156 return null; 157 } 158 } 159 return null; 160 } 161 162 165 public String getEditorId(IEditorInput input, Object element) { 166 return "org.eclipse.ant.ui.internal.editor.AntEditor"; } 168 } 169 | Popular Tags |