KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 JavaDoc enc;
26
27     public StreamDocumentProvider(IDocumentPartitioner partitioner,
28             String JavaDoc encoding) {
29         this.partitioner = partitioner;
30         this.enc = encoding;
31     }
32
33     protected IDocumentPartitioner getPartitioner() {
34         return partitioner;
35     }
36
37     protected String JavaDoc getEncoding() {
38         return enc;
39     }
40
41     protected IAnnotationModel createAnnotationModel(Object JavaDoc element)
42             throws CoreException {
43         return new SystemFileMarkerAnnotationModel();
44     }
45
46     protected void doSaveDocument(IProgressMonitor monitor, Object JavaDoc 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 JavaDoc buffer = new StringBuffer JavaDoc(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 JavaDoc element) {
75         return 0;
76     }
77
78     public long getModificationStamp(Object JavaDoc element) {
79         return 0;
80     }
81
82     public boolean isDeleted(Object JavaDoc element) {
83         return false;
84     }
85
86     protected IDocument createEmptyDocument() {
87         return new Document();
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#getOperationRunner(org.eclipse.core.runtime.IProgressMonitor)
94      */

95     protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
96         // TODO figure out what this method does
97
return null;
98     }
99 }
100
Popular Tags