1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import java.io.*; 14 import org.eclipse.jface.text.*; 15 import org.eclipse.jface.text.source.IAnnotationModel; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.pde.internal.ui.PDEPlugin; 18 19 public class SystemFileDocumentProvider extends StreamDocumentProvider { 20 21 public SystemFileDocumentProvider(IDocumentPartitioner partitioner) { 22 this(partitioner, null); 23 } 24 25 public SystemFileDocumentProvider( 26 IDocumentPartitioner partitioner, 27 String encoding) { 28 super(partitioner, encoding); 29 } 30 33 protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { 34 if (element instanceof SystemFileEditorInput) { 35 SystemFileEditorInput input= (SystemFileEditorInput) element; 36 File file = (File)input.getAdapter(File.class); 37 if (file!=null) { 38 return new SystemFileMarkerAnnotationModel(); 39 } 40 } 41 return super.createAnnotationModel(element); 42 } 43 44 protected IDocument createDocument(Object element) throws CoreException { 45 if (element instanceof SystemFileEditorInput) { 46 IDocument document = createEmptyDocument(); 47 IDocumentPartitioner part = getPartitioner(); 48 if (part != null) { 49 part.connect(document); 50 document.setDocumentPartitioner(part); 51 } 52 File file = 53 (File) ((SystemFileEditorInput) element).getAdapter(File.class); 54 setDocumentContent(document, file); 55 return document; 56 } 57 return null; 58 } 59 protected void doSaveDocument( 60 IProgressMonitor monitor, 61 Object element, 62 IDocument document, 63 boolean force) 64 throws CoreException { 65 } 66 protected void setDocumentContent(IDocument document, File file) { 67 try { 68 InputStream contentStream = new FileInputStream(file); 69 setDocumentContent(document, contentStream); 70 contentStream.close(); 71 } catch (IOException e) { 72 PDEPlugin.logException(e); 73 } 74 } 75 76 } 77 | Popular Tags |