1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import java.io.*; 14 15 import org.eclipse.jface.operation.*; 16 import org.eclipse.jface.text.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.jface.text.source.*; 19 import org.eclipse.ui.texteditor.*; 20 import org.eclipse.pde.internal.ui.PDEPlugin; 21 22 public abstract class StreamDocumentProvider extends AbstractDocumentProvider { 23 private IDocumentPartitioner partitioner; 24 25 private String enc; 26 27 public StreamDocumentProvider(IDocumentPartitioner partitioner, 28 String encoding) { 29 this.partitioner = partitioner; 30 this.enc = encoding; 31 } 32 33 protected IDocumentPartitioner getPartitioner() { 34 return partitioner; 35 } 36 37 protected String getEncoding() { 38 return enc; 39 } 40 41 protected IAnnotationModel createAnnotationModel(Object element) 42 throws CoreException { 43 return new SystemFileMarkerAnnotationModel(); 44 } 45 46 protected void doSaveDocument(IProgressMonitor monitor, Object element, 47 IDocument document, boolean force) throws CoreException { 48 } 49 50 protected void setDocumentContent(IDocument document, 51 InputStream contentStream) { 52 try { 53 Reader in; 54 if (enc == null) 55 in = new InputStreamReader(contentStream); 56 else 57 in = new InputStreamReader(contentStream, enc); 58 int chunkSize = contentStream.available(); 59 StringBuffer buffer = new StringBuffer (chunkSize); 60 char[] readBuffer = new char[chunkSize]; 61 int n = in.read(readBuffer); 62 while (n > 0) { 63 buffer.append(readBuffer); 64 n = in.read(readBuffer); 65 } 66 in.close(); 67 document.set(buffer.toString()); 68 69 } catch (IOException e) { 70 PDEPlugin.logException(e); 71 } 72 } 73 74 public long getSynchronizationStamp(Object element) { 75 return 0; 76 } 77 78 public long getModificationStamp(Object element) { 79 return 0; 80 } 81 82 public boolean isDeleted(Object element) { 83 return false; 84 } 85 86 protected IDocument createEmptyDocument() { 87 return new Document(); 88 } 89 90 95 protected IRunnableContext getOperationRunner(IProgressMonitor monitor) { 96 return null; 98 } 99 } 100 | Popular Tags |