1 11 package org.eclipse.jdt.internal.debug.ui.display; 12 13 14 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 15 import org.eclipse.jface.text.BadLocationException; 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.ITextSelection; 18 import org.eclipse.jface.text.ITextViewer; 19 20 23 public class DataDisplay implements IDataDisplay { 24 25 28 private ITextViewer fTextViewer; 29 30 35 public DataDisplay(ITextViewer viewer) { 36 setTextViewer(viewer); 37 } 38 39 42 public void clear() { 43 IDocument document= getTextViewer().getDocument(); 44 if (document != null) { 45 document.set(""); } 47 } 48 49 52 public void displayExpression(String expression) { 53 IDocument document= fTextViewer.getDocument(); 54 int offset= document.getLength(); 55 try { 56 if (offset != document.getLineInformationOfOffset(offset).getOffset()) { 58 expression= System.getProperty("line.separator") + expression.trim(); } 60 document.replace(offset, 0, expression); 61 fTextViewer.setSelectedRange(offset + expression.length(), 0); 62 fTextViewer.revealRange(offset, expression.length()); 63 } catch (BadLocationException ble) { 64 JDIDebugUIPlugin.log(ble); 65 } 66 } 67 68 71 public void displayExpressionValue(String value) { 72 value= System.getProperty("line.separator") + '\t' + value; ITextSelection selection= (ITextSelection)fTextViewer.getSelectionProvider().getSelection(); 74 75 int offset= selection.getOffset() + selection.getLength(); 76 int length= value.length(); 77 try { 78 fTextViewer.getDocument().replace(offset, 0, value); 79 } catch (BadLocationException ble) { 80 JDIDebugUIPlugin.log(ble); 81 } 82 fTextViewer.setSelectedRange(offset + length, 0); 83 fTextViewer.revealRange(offset, length); 84 } 85 86 91 private void setTextViewer(ITextViewer viewer) { 92 fTextViewer = viewer; 93 } 94 95 100 protected ITextViewer getTextViewer() { 101 return fTextViewer; 102 } 103 } 104 | Popular Tags |