Eclipse Platform
2.0

org.eclipse.ui.editors.text
Class StorageDocumentProvider

java.lang.Object
  |
  +--org.eclipse.ui.texteditor.AbstractDocumentProvider
        |
        +--org.eclipse.ui.editors.text.StorageDocumentProvider
All Implemented Interfaces:
IDocumentProvider, IDocumentProviderExtension, IStorageDocumentProvider
Direct Known Subclasses:
FileDocumentProvider

public class StorageDocumentProvider
extends AbstractDocumentProvider
implements IStorageDocumentProvider

Shareable document provider specialized for IStorages.


Nested Class Summary
protected  class StorageDocumentProvider.StorageInfo
          Bundle of all required information to allow IStorage as underlying document resources.
 
Nested classes inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
 
Field Summary
 
Fields inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
PR10806_UC5_ENABLED, PR14469_ENABLED, STATUS_ERROR, STATUS_OK
 
Constructor Summary
StorageDocumentProvider()
          Creates a new document provider.
 
Method Summary
protected  IAnnotationModel createAnnotationModel(Object element)
          Creates an annotation model for the given element.
protected  IDocument createDocument(Object element)
          Creates the document for the given element.
protected  AbstractDocumentProvider.ElementInfo createElementInfo(Object element)
          Creates a new element info object for the given element.
protected  void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
          Performs the actual work of saving the given document provided for the given element.
protected  void doUpdateStateCache(Object element)
          Hook method for updating the state of the given element.
 String getDefaultEncoding()
          Returns the default character encoding used by this provider for reading.
 String getEncoding(Object element)
          Returns the character encoding for reading the given element, or null if the element is not managed by this provider.
protected  void handleCoreException(CoreException exception, String message)
          Defines the standard procedure to handle CoreExceptions.
 boolean isModifiable(Object element)
          Returns whether the document provider thinks that the given element can persistently be modified.
 boolean isReadOnly(Object element)
          Returns whether the document provider thinks that the given element is read-only.
protected  boolean setDocumentContent(IDocument document, IEditorInput editorInput)
          Deprecated. use the encoding based version instead
protected  boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding)
          Intitializes the given document from the given editor input using the given character encoding.
protected  void setDocumentContent(IDocument document, InputStream contentStream)
          Deprecated. use encoding based version instead
protected  void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
          Intitializes the given document with the given stream using the given encoding.
 void setEncoding(Object element, String encoding)
          Sets the encoding for reading the given element.
protected  void updateCache(IStorageEditorInput input)
          Updates the internal cache for the given input.
 
Methods inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
aboutToChange, addElementStateListener, addUnchangedElementListeners, canSaveDocument, changed, connect, connected, disconnect, disconnected, disposeElementInfo, doValidateState, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getElementInfo, getModificationStamp, getStatus, getSynchronizationStamp, invalidatesState, isDeleted, isStateValidated, mustSaveDocument, removeElementStateListener, removeUnchangedElementListeners, resetDocument, saveDocument, setCanSaveDocument, synchronize, updateStateCache, validateState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StorageDocumentProvider

public StorageDocumentProvider()
Creates a new document provider.

Since:
2.0
Method Detail

setDocumentContent

protected void setDocumentContent(IDocument document,
                                  InputStream contentStream)
                           throws CoreException
Deprecated. use encoding based version instead

Intitializes the given document with the given stream.

Parameters:
document - the document to be initialized
contentStream - the stream which delivers the document content
Throws:
CoreException - if the given stream can not be read

setDocumentContent

protected void setDocumentContent(IDocument document,
                                  InputStream contentStream,
                                  String encoding)
                           throws CoreException
Intitializes the given document with the given stream using the given encoding.

Parameters:
document - the document to be initialized
contentStream - the stream which delivers the document content
encoding - the character encoding for reading the given stream
Throws:
CoreException - if the given stream can not be read
Since:
2.0

setDocumentContent

protected boolean setDocumentContent(IDocument document,
                                     IEditorInput editorInput)
                              throws CoreException
Deprecated. use the encoding based version instead

Intitializes the given document from the given editor input using the default character encoding.

Parameters:
document - the document to be initialized
editorInput - the input from which to derive the content of the document
Returns:
true if the document content could be set, false otherwise
Throws:
CoreException - if the given editor input cannot be accessed
Since:
2.0

setDocumentContent

protected boolean setDocumentContent(IDocument document,
                                     IEditorInput editorInput,
                                     String encoding)
                              throws CoreException
Intitializes the given document from the given editor input using the given character encoding.

Parameters:
document - the document to be initialized
editorInput - the input from which to derive the content of the document
encoding - the character encoding used to read the editor input
Returns:
true if the document content could be set, false otherwise
Throws:
CoreException - if the given editor input cannot be accessed
Since:
2.0

createAnnotationModel

protected IAnnotationModel createAnnotationModel(Object element)
                                          throws CoreException
Description copied from class: AbstractDocumentProvider
Creates an annotation model for the given element.

Subclasses must implement this method.

Specified by:
createAnnotationModel in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
the annotation model
Throws:
CoreException - if the annotation model could not be created

createDocument

protected IDocument createDocument(Object element)
                            throws CoreException
Description copied from class: AbstractDocumentProvider
Creates the document for the given element.

Subclasses must implement this method.

Specified by:
createDocument in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
the document
Throws:
CoreException - if the document could not be created

createElementInfo

protected AbstractDocumentProvider.ElementInfo createElementInfo(Object element)
                                                          throws CoreException
Description copied from class: AbstractDocumentProvider
Creates a new element info object for the given element.

This method is called from connect when an element info needs to be created. The AbstractDocumentProvider implementation of this method returns a new element info object whose document and annotation model are the values of createDocument(element) and createAnnotationModel(element), respectively. Subclasses may override.

Overrides:
createElementInfo in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
a new element info object
Throws:
CoreException - if the document or annotation model could not be created

doSaveDocument

protected void doSaveDocument(IProgressMonitor monitor,
                              Object element,
                              IDocument document,
                              boolean overwrite)
                       throws CoreException
Description copied from class: AbstractDocumentProvider
Performs the actual work of saving the given document provided for the given element.

Subclasses must implement this method.

Specified by:
doSaveDocument in class AbstractDocumentProvider
Parameters:
monitor - a progress monitor to report progress and request cancelation
element - the element
document - the document
overwrite - indicates whether an overwrite should happen if necessary
Throws:
CoreException - if document could not be stored to the given element

handleCoreException

protected void handleCoreException(CoreException exception,
                                   String message)
Defines the standard procedure to handle CoreExceptions. Exceptions are written to the plugin log.

Parameters:
exception - the exception to be logged
message - the message to be logged
Since:
2.0

updateCache

protected void updateCache(IStorageEditorInput input)
                    throws CoreException
Updates the internal cache for the given input.

Parameters:
input - the input whose cache will be updated
CoreException
Since:
2.0

isReadOnly

public boolean isReadOnly(Object element)
Description copied from interface: IDocumentProviderExtension
Returns whether the document provider thinks that the given element is read-only. If this method returns true, saveDocument could fail. This method does not say anything about the document constructed from the given element. If the given element is not connected to this document provider, the return value is undefined. Document providers are allowed to use a cache to answer this question, i.e. there can be a difference between the "real" state of the element and the return value.

Specified by:
isReadOnly in interface IDocumentProviderExtension
Overrides:
isReadOnly in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
true if the given element is read-only, false otherwise

isModifiable

public boolean isModifiable(Object element)
Description copied from interface: IDocumentProviderExtension
Returns whether the document provider thinks that the given element can persistently be modified. This is orthogonal to isReadOnly as read-only elements may be modifiable and writable elements may not be modifiable. If the given element is not connected to this document provider, the result is undefined. Document providers are allowed to use a cache to answer this question, i.e. there can be a difference between the "real" state of the element and the return value.

Specified by:
isModifiable in interface IDocumentProviderExtension
Overrides:
isModifiable in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
true if the given element is modifiable, false otherwise

doUpdateStateCache

protected void doUpdateStateCache(Object element)
                           throws CoreException
Description copied from class: AbstractDocumentProvider
Hook method for updating the state of the given element. Default implementation is empty.

Overrides:
doUpdateStateCache in class AbstractDocumentProvider
Parameters:
element - the element
Throws:
CoreException - in case state cache updating fails

getDefaultEncoding

public String getDefaultEncoding()
Description copied from interface: IStorageDocumentProvider
Returns the default character encoding used by this provider for reading.

Specified by:
getDefaultEncoding in interface IStorageDocumentProvider
Returns:
the default character encoding used by this provider for reading

getEncoding

public String getEncoding(Object element)
Description copied from interface: IStorageDocumentProvider
Returns the character encoding for reading the given element, or null if the element is not managed by this provider.

Specified by:
getEncoding in interface IStorageDocumentProvider
Parameters:
element - the element
Returns:
the encoding for reading the given element

setEncoding

public void setEncoding(Object element,
                        String encoding)
Description copied from interface: IStorageDocumentProvider
Sets the encoding for reading the given element. If encoding is null the workbench's character encoding should be used.

Specified by:
setEncoding in interface IStorageDocumentProvider
Parameters:
element - the element
encoding - the encoding to be used

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.