1 11 package org.eclipse.compare.internal; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.widgets.Composite; 15 import org.eclipse.swt.widgets.Control; 16 17 import org.eclipse.jface.text.source.SourceViewer; 18 import org.eclipse.jface.text.Document; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.compare.*; 22 import org.eclipse.compare.structuremergeviewer.ICompareInput; 23 24 25 public class SimpleTextViewer extends AbstractViewer { 26 27 private SourceViewer fSourceViewer; 28 private ICompareInput fInput; 29 30 31 SimpleTextViewer(Composite parent) { 32 fSourceViewer= new SourceViewer(parent, null, SWT.H_SCROLL | SWT.V_SCROLL); 33 fSourceViewer.setEditable(false); 34 } 35 36 public Control getControl() { 37 return fSourceViewer.getTextWidget(); 38 } 39 40 public void setInput(Object input) { 41 if (input instanceof IStreamContentAccessor) { 42 fSourceViewer.setDocument(new Document(getString(input))); 43 } else if (input instanceof ICompareInput) { 44 fInput= (ICompareInput) input; 45 ITypedElement left= fInput.getLeft(); 46 fSourceViewer.setDocument(new Document(getString(left))); 47 } 48 } 49 50 public Object getInput() { 51 return fInput; 52 } 53 54 private String getString(Object input) { 55 56 if (input instanceof IStreamContentAccessor) { 57 try { 58 return Utilities.readString((IStreamContentAccessor) input); 59 } catch (CoreException ex) { 60 CompareUIPlugin.log(ex); 62 } 63 } 64 return ""; } 66 } 67 | Popular Tags |