1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import java.io.*; 14 15 import org.eclipse.core.resources.IStorage; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.jface.text.*; 18 import org.eclipse.pde.internal.ui.PDEPlugin; 19 import org.eclipse.ui.IStorageEditorInput; 20 21 public class StorageDocumentProvider extends StreamDocumentProvider { 22 23 public StorageDocumentProvider(IDocumentPartitioner partitioner) { 24 this(partitioner, null); 25 } 26 27 public StorageDocumentProvider( 28 IDocumentPartitioner partitioner, 29 String encoding) { 30 super(partitioner, encoding); 31 } 32 33 protected IDocument createDocument(Object element) throws CoreException { 34 if (element instanceof IStorageEditorInput) { 35 IDocument document = createEmptyDocument(); 36 IDocumentPartitioner part = getPartitioner(); 37 if (part != null) { 38 part.connect(document); 39 document.setDocumentPartitioner(part); 40 } 41 IStorage storage = ((IStorageEditorInput)element).getStorage(); 42 setDocumentContent(document, storage); 43 return document; 44 } 45 return null; 46 } 47 protected void setDocumentContent(IDocument document, IStorage storage) { 48 try { 49 InputStream contentStream = storage.getContents(); 50 setDocumentContent(document, contentStream); 51 contentStream.close(); 52 } catch (Exception e) { 53 PDEPlugin.logException(e); 54 } 55 } 56 57 } 58 | Popular Tags |