KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > SystemFileDocumentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc encoding) {
28         super(partitioner, encoding);
29     }
30     /*
31      * @see AbstractDocumentProvider#createAnnotationModel(Object)
32      */

33     protected IAnnotationModel createAnnotationModel(Object JavaDoc 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 JavaDoc 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 JavaDoc 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