KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc encoding) {
30         super(partitioner, encoding);
31     }
32
33     protected IDocument createDocument(Object JavaDoc 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 JavaDoc e) {
53             PDEPlugin.logException(e);
54         }
55     }
56
57 }
58
Popular Tags