Package org.eclipse.ui.editors.text
Class StorageDocumentProvider
java.lang.Object
org.eclipse.ui.texteditor.AbstractDocumentProvider
org.eclipse.ui.editors.text.StorageDocumentProvider
- All Implemented Interfaces:
IStorageDocumentProvider,IDocumentProvider,IDocumentProviderExtension,IDocumentProviderExtension2,IDocumentProviderExtension3,IDocumentProviderExtension4,IDocumentProviderExtension5
- Direct Known Subclasses:
FileDocumentProvider
public class StorageDocumentProvider
extends AbstractDocumentProvider
implements IStorageDocumentProvider
Shared document provider specialized for
IStorages.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classBundle of all required information to allowIStorageas underlying document resources.Nested classes/interfaces inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
AbstractDocumentProvider.DocumentProviderOperation, AbstractDocumentProvider.ElementInfo -
Field Summary
FieldsFields inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
PR10806_UC5_ENABLED, PR14469_ENABLED, STATUS_ERROR, STATUS_OK -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected IAnnotationModelcreateAnnotationModel(Object element) Creates an annotation model for the given element.protected IDocumentcreateDocument(Object element) Creates the document for the given element.protected AbstractDocumentProvider.ElementInfocreateElementInfo(Object element) Creates a new element info object for the given element.protected IDocumentFactory method for creating empty documents.protected voiddoSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) Performs the actual work of saving the given document provided for the given element.protected voiddoUpdateStateCache(Object element) Hook method for updating the state of the given element.getContentType(Object element) Returns the content type of for the given element ornullif none could be determined.Returns the default character encoding used by this provider.getEncoding(Object element) Returns the character encoding for the given element, ornullif the element is not managed by this provider.protected IRunnableContextgetOperationRunner(IProgressMonitor monitor) Returns the runnable context for this document provider.protected StringgetPersistedEncoding(Object element) Returns the persisted encoding for the given element.protected voidhandleCoreException(CoreException exception, String message) Defines the standard procedure to handleCoreExceptions.booleanisModifiable(Object element) Returns whether the document provider thinks that the given element can persistently be modified.booleanisNotSynchronizedException(Object element, CoreException ex) Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element.booleanisReadOnly(Object element) Returns whether the document provider thinks that the given element is read-only.protected voidpersistEncoding(Object element, String encoding) Persists the given encoding for the given element.protected voidsetDocumentContent(IDocument document, InputStream contentStream) Deprecated.use encoding based version insteadprotected voidsetDocumentContent(IDocument document, InputStream contentStream, String encoding) Initializes the given document with the given stream using the given encoding.protected booleansetDocumentContent(IDocument document, IEditorInput editorInput) Deprecated.use the encoding based version insteadprotected booleansetDocumentContent(IDocument document, IEditorInput editorInput, String encoding) Initializes the given document from the given editor input using the given character encoding.voidsetEncoding(Object element, String encoding) Sets the encoding for the given element.protected voidsetupDocument(Object element, IDocument document) Sets up the given document as it would be provided for the given element.protected voidupdateCache(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, doResetDocument, doSynchronize, doValidateState, executeOperation, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getElementInfo, getModificationStamp, getProgressMonitor, getResetRule, getSaveRule, getStatus, getSynchronizationStamp, getSynchronizeRule, getValidateStateRule, invalidatesState, isDeleted, isStateValidated, isSynchronized, mustSaveDocument, removeElementStateListener, removeUnchangedElementListeners, resetDocument, saveDocument, setCanSaveDocument, setProgressMonitor, synchronize, updateStateCache, validateState
-
Field Details
-
DEFAULT_FILE_SIZE
protected static final int DEFAULT_FILE_SIZEDefault file size.- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
StorageDocumentProvider
public StorageDocumentProvider()Creates a new document provider.- Since:
- 2.0
-
-
Method Details
-
setDocumentContent
@Deprecated protected void setDocumentContent(IDocument document, InputStream contentStream) throws CoreException Deprecated.use encoding based version insteadInitializes the given document with the given stream.- Parameters:
document- the document to be initializedcontentStream- 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 Initializes the given document with the given stream using the given encoding.- Parameters:
document- the document to be initializedcontentStream- the stream which delivers the document contentencoding- the character encoding for reading the given stream- Throws:
CoreException- if the given stream can not be read- Since:
- 2.0
-
setDocumentContent
@Deprecated protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException Deprecated.use the encoding based version insteadInitializes the given document from the given editor input using the default character encoding.- Parameters:
document- the document to be initializededitorInput- the input from which to derive the content of the document- Returns:
trueif the document content could be set,falseotherwise- 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 Initializes the given document from the given editor input using the given character encoding.- Parameters:
document- the document to be initializededitorInput- the input from which to derive the content of the documentencoding- the character encoding used to read the editor input- Returns:
trueif the document content could be set,falseotherwise- Throws:
CoreException- if the given editor input cannot be accessed- Since:
- 2.0
-
createAnnotationModel
Description copied from class:AbstractDocumentProviderCreates an annotation model for the given element.Subclasses must implement this method.
- Specified by:
createAnnotationModelin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the annotation model or
nullif none - Throws:
CoreException- if the annotation model could not be created
-
createEmptyDocument
Factory method for creating empty documents.- Returns:
- the newly created document
- Since:
- 2.1
-
createDocument
Description copied from class:AbstractDocumentProviderCreates the document for the given element.Subclasses must implement this method.
- Specified by:
createDocumentin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the document
- Throws:
CoreException- if the document could not be created
-
setupDocument
Sets up the given document as it would be provided for the given element. The content of the document is not changed. This default implementation is empty. Subclasses may reimplement.- Parameters:
element- the blue-print elementdocument- the document to set up- Since:
- 3.0
-
createElementInfo
protected AbstractDocumentProvider.ElementInfo createElementInfo(Object element) throws CoreException Description copied from class:AbstractDocumentProviderCreates a new element info object for the given element.This method is called from
connectwhen an element info needs to be created. TheAbstractDocumentProviderimplementation of this method returns a new element info object whose document and annotation model are the values ofcreateDocument(element)andcreateAnnotationModel(element), respectively. Subclasses may override.- Overrides:
createElementInfoin classAbstractDocumentProvider- 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:AbstractDocumentProviderPerforms the actual work of saving the given document provided for the given element.Subclasses must implement this method.
- Specified by:
doSaveDocumentin classAbstractDocumentProvider- Parameters:
monitor- a progress monitor to report progress and request cancelationelement- the elementdocument- the documentoverwrite- indicates whether an overwrite should happen if necessary- Throws:
CoreException- if document could not be stored to the given element
-
handleCoreException
Defines the standard procedure to handleCoreExceptions. Exceptions are written to the plug-in log.- Parameters:
exception- the exception to be loggedmessage- the message to be logged- Since:
- 2.0
-
updateCache
Updates the internal cache for the given input.- Parameters:
input- the input whose cache will be updated- Throws:
CoreException- if the storage cannot be retrieved from the input- Since:
- 2.0
-
isReadOnly
Description copied from interface:IDocumentProviderExtensionReturns whether the document provider thinks that the given element is read-only. If this method returnstrue,saveDocumentcould 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:
isReadOnlyin interfaceIDocumentProviderExtension- Overrides:
isReadOnlyin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
trueif the given element is read-only,falseotherwise
-
isNotSynchronizedException
Description copied from interface:IDocumentProviderExtension5Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element.- Specified by:
isNotSynchronizedExceptionin interfaceIDocumentProviderExtension5- Overrides:
isNotSynchronizedExceptionin classAbstractDocumentProvider- Parameters:
element- the elementex- the core exception- Returns:
trueiff the given core exception is exactly the exception which is thrown for a non-synchronized element
-
isModifiable
Description copied from interface:IDocumentProviderExtensionReturns whether the document provider thinks that the given element can persistently be modified. This is orthogonal toisReadOnlyas 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:
isModifiablein interfaceIDocumentProviderExtension- Overrides:
isModifiablein classAbstractDocumentProvider- Parameters:
element- the element- Returns:
trueif the given element is modifiable,falseotherwise
-
doUpdateStateCache
Description copied from class:AbstractDocumentProviderHook method for updating the state of the given element. Default implementation is empty.- Overrides:
doUpdateStateCachein classAbstractDocumentProvider- Parameters:
element- the element- Throws:
CoreException- in case state cache updating fails
-
getDefaultEncoding
Description copied from interface:IStorageDocumentProviderReturns the default character encoding used by this provider.- Specified by:
getDefaultEncodingin interfaceIStorageDocumentProvider- Returns:
- the default character encoding used by this provider
-
getEncoding
Description copied from interface:IStorageDocumentProviderReturns the character encoding for the given element, ornullif the element is not managed by this provider.- Specified by:
getEncodingin interfaceIStorageDocumentProvider- Parameters:
element- the element- Returns:
- the encoding for the given element
-
setEncoding
Description copied from interface:IStorageDocumentProviderSets the encoding for the given element. Ifencodingisnullthe workbench's character encoding should be used.- Specified by:
setEncodingin interfaceIStorageDocumentProvider- Parameters:
element- the elementencoding- the encoding to be used
-
getContentType
Description copied from interface:IDocumentProviderExtension4Returns the content type of for the given element ornullif none could be determined. If the element's document can be saved, the returned content type is determined by the document's current content.- Specified by:
getContentTypein interfaceIDocumentProviderExtension4- Overrides:
getContentTypein classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the content type or
null - Throws:
CoreException- if reading or accessing the underlying store fails
-
getPersistedEncoding
Returns the persisted encoding for the given element.- Parameters:
element- the element for which to get the persisted encoding- Returns:
- the persisted encoding
- Since:
- 2.1
-
persistEncoding
Persists the given encoding for the given element.- Parameters:
element- the element for which to store the persisted encodingencoding- the encoding- Throws:
CoreException- if the operation fails- Since:
- 2.1
-
getOperationRunner
Description copied from class:AbstractDocumentProviderReturns the runnable context for this document provider.- Specified by:
getOperationRunnerin classAbstractDocumentProvider- Parameters:
monitor- a progress monitor to track the operation- Returns:
- the runnable context for this document provider
-