public class FileDocumentProvider extends StorageDocumentProvider
IFile
).
This class may be instantiated or be subclassed.
Modifier and Type | Class and Description |
---|---|
protected class |
FileDocumentProvider.FileInfo
Bundle of all required information to allow files as underlying document resources.
|
protected class |
FileDocumentProvider.FileSynchronizer
Synchronizes the document with external resource changes.
|
protected class |
FileDocumentProvider.SafeChange
Runnable encapsulating an element state change.
|
StorageDocumentProvider.StorageInfo
AbstractDocumentProvider.DocumentProviderOperation, AbstractDocumentProvider.ElementInfo
DEFAULT_FILE_SIZE
PR10806_UC5_ENABLED, PR14469_ENABLED, STATUS_ERROR, STATUS_OK
Constructor and Description |
---|
FileDocumentProvider()
Creates and returns a new document provider.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cacheEncodingState(Object element)
Internally caches the file's encoding data.
|
protected void |
checkSynchronizationState(long cachedModificationStamp,
IResource resource)
Checks whether the given resource has been changed on the
local file system by comparing the actual time stamp with the
cached one.
|
protected long |
computeModificationStamp(IResource resource)
Computes the initial modification stamp for the given resource.
|
protected IAnnotationModel |
createAnnotationModel(Object element)
Creates an annotation model for the given element.
|
protected AbstractDocumentProvider.ElementInfo |
createElementInfo(Object element)
Creates a new element info object for the given element.
|
protected void |
disposeElementInfo(Object element,
AbstractDocumentProvider.ElementInfo info)
Disposes of the given element info object.
|
protected void |
doResetDocument(Object element,
IProgressMonitor monitor)
Executes the actual work of reseting the given elements document.
|
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 |
doSynchronize(Object element,
IProgressMonitor monitor)
Performs the actual work of synchronizing the given element.
|
protected void |
doValidateState(Object element,
Object computationContext)
Hook method for validating the state of the given element.
|
IContentType |
getContentType(Object element)
Returns the content type of for the given element or
null if none could be determined. |
protected AbstractDocumentProvider.ElementInfo |
getElementInfo(Object element)
Returns the element info object for the given element.
|
long |
getModificationStamp(Object element)
Returns the modification stamp of the given element.
|
protected IRunnableContext |
getOperationRunner(IProgressMonitor monitor)
Returns the runnable context for this document provider.
|
protected String |
getPersistedEncoding(Object element)
Returns the persisted encoding for the given element.
|
protected ISchedulingRule |
getResetRule(Object element)
Returns the scheduling rule required for executing
reset on the given element. |
protected ISchedulingRule |
getSaveRule(Object element)
Returns the scheduling rule required for executing
save on the given element. |
long |
getSynchronizationStamp(Object element)
Returns the time stamp of the last synchronization of the given element and its provided
document.
|
protected ISchedulingRule |
getSynchronizeRule(Object element)
Returns the scheduling rule required for executing
synchronize on the given element. |
protected ISchedulingRule |
getValidateStateRule(Object element)
Returns the scheduling rule required for executing
validateState on the given element. |
protected void |
handleElementContentChanged(IFileEditorInput fileEditorInput)
Updates the element info to a change of the file content and sends out
appropriate notifications.
|
protected void |
handleElementDeleted(IFileEditorInput fileEditorInput)
Sends out the notification that the file serving as document input has been deleted.
|
protected void |
handleElementMoved(IFileEditorInput fileEditorInput,
IPath path)
Sends out the notification that the file serving as document input has been moved.
|
boolean |
isDeleted(Object element)
Returns whether the given element has been deleted.
|
boolean |
isModifiable(Object element)
Returns whether the document provider thinks that the given element can persistently be modified.
|
boolean |
isSynchronized(Object element)
Returns whether the information provided for the given element is in sync with the element.
|
protected void |
persistEncoding(Object element,
String encoding)
Persists the given encoding for the given element.
|
protected void |
readUTF8BOM(IFile file,
String encoding,
Object element)
Deprecated.
as of 3.0 this method is no longer in use and does nothing
|
protected void |
refreshFile(IFile file)
Refreshes the given file resource.
|
protected void |
refreshFile(IFile file,
IProgressMonitor monitor)
Refreshes the given file resource.
|
protected boolean |
setDocumentContent(IDocument document,
IEditorInput editorInput)
Deprecated.
use file encoding based version
|
protected boolean |
setDocumentContent(IDocument document,
IEditorInput editorInput,
String encoding)
Initializes the given document from the given editor input using the given character encoding.
|
createDocument, createEmptyDocument, doUpdateStateCache, getDefaultEncoding, getEncoding, handleCoreException, isNotSynchronizedException, isReadOnly, setDocumentContent, setDocumentContent, setEncoding, setupDocument, updateCache
aboutToChange, addElementStateListener, addUnchangedElementListeners, canSaveDocument, changed, connect, connected, disconnect, disconnected, executeOperation, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getProgressMonitor, getStatus, invalidatesState, isStateValidated, mustSaveDocument, removeElementStateListener, removeUnchangedElementListeners, resetDocument, saveDocument, setCanSaveDocument, setProgressMonitor, synchronize, updateStateCache, validateState
public FileDocumentProvider()
protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException
StorageDocumentProvider#setDocumentContent(IDocument, IEditorInput)
.setDocumentContent
in class StorageDocumentProvider
document
- the document to be initializededitorInput
- the input from which to derive the content of the documenttrue
if the document content could be set, false
otherwiseCoreException
- if the given editor input cannot be accessedStorageDocumentProvider.setDocumentContent(IDocument, IEditorInput)
protected boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding) throws CoreException
StorageDocumentProvider
setDocumentContent
in class StorageDocumentProvider
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 inputtrue
if the document content could be set, false
otherwiseCoreException
- if the given editor input cannot be accessedprotected IAnnotationModel createAnnotationModel(Object element) throws CoreException
AbstractDocumentProvider
Subclasses must implement this method.
createAnnotationModel
in class StorageDocumentProvider
element
- the elementnull
if noneCoreException
- if the annotation model could not be createdprotected void checkSynchronizationState(long cachedModificationStamp, IResource resource) throws CoreException
CoreException
is thrown.cachedModificationStamp
- the cached modification stampresource
- the resource to checkCoreException
- if resource has been changed on the file systemprotected long computeModificationStamp(IResource resource)
resource
- the resourcepublic long getModificationStamp(Object element)
IDocumentProvider
getModificationStamp
in interface IDocumentProvider
getModificationStamp
in class AbstractDocumentProvider
element
- the elementpublic long getSynchronizationStamp(Object element)
IDocumentProvider
getSynchronizationStamp
in interface IDocumentProvider
getSynchronizationStamp
in class AbstractDocumentProvider
element
- the elementprotected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException
AbstractDocumentProvider
doSynchronize
in class AbstractDocumentProvider
element
- the elementmonitor
- the progress monitorCoreException
- in the case that synchronization failspublic boolean isDeleted(Object element)
IDocumentProvider
isDeleted
in interface IDocumentProvider
isDeleted
in class AbstractDocumentProvider
element
- the elementtrue
if the element has been deletedprotected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException
AbstractDocumentProvider
Subclasses must implement this method.
doSaveDocument
in class StorageDocumentProvider
monitor
- a progress monitor to report progress and request cancelationelement
- the elementdocument
- the documentoverwrite
- indicates whether an overwrite should happen if necessaryCoreException
- if document could not be stored to the given elementprotected AbstractDocumentProvider.ElementInfo createElementInfo(Object element) throws CoreException
AbstractDocumentProvider
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.
createElementInfo
in class StorageDocumentProvider
element
- the elementCoreException
- if the document or annotation model could not be createdprotected void disposeElementInfo(Object element, AbstractDocumentProvider.ElementInfo info)
AbstractDocumentProvider
This method is called when an element info is disposed. The
AbstractDocumentProvider
implementation of this
method does nothing. Subclasses may reimplement.
disposeElementInfo
in class AbstractDocumentProvider
element
- the elementinfo
- the element info objectprotected void handleElementContentChanged(IFileEditorInput fileEditorInput)
fileEditorInput
- the input of an text editorprotected void handleElementMoved(IFileEditorInput fileEditorInput, IPath path)
fileEditorInput
- the input of an text editorpath
- the path of the new location of the fileprotected void handleElementDeleted(IFileEditorInput fileEditorInput)
fileEditorInput
- the input of an text editorprotected AbstractDocumentProvider.ElementInfo getElementInfo(Object element)
AbstractDocumentProvider
getElementInfo
in class AbstractDocumentProvider
element
- the elementnull
if noneprotected void doValidateState(Object element, Object computationContext) throws CoreException
AbstractDocumentProvider
doValidateState
in class AbstractDocumentProvider
element
- the elementcomputationContext
- the context in which validation happensCoreException
- in case validation failspublic boolean isModifiable(Object element)
IDocumentProviderExtension
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.isModifiable
in interface IDocumentProviderExtension
isModifiable
in class StorageDocumentProvider
element
- the elementtrue
if the given element is modifiable, false
otherwiseprotected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException
AbstractDocumentProvider
doResetDocument
in class AbstractDocumentProvider
element
- the elementmonitor
- the progress monitorCoreException
- if resetting failsprotected void refreshFile(IFile file) throws CoreException
file
- the fileCoreException
- if the refresh failsprotected void refreshFile(IFile file, IProgressMonitor monitor) throws CoreException
file
- the file to be refreshedmonitor
- the progress monitorCoreException
- if the refresh failspublic boolean isSynchronized(Object element)
IDocumentProviderExtension3
isSynchronized
in interface IDocumentProviderExtension3
isSynchronized
in class AbstractDocumentProvider
element
- the elementtrue
if the information is in sync with the element, false
otherwisepublic IContentType getContentType(Object element) throws CoreException
IDocumentProviderExtension4
null
if none could be determined. If the element's
document can be saved, the returned content type is determined by the
document's current content.getContentType
in interface IDocumentProviderExtension4
getContentType
in class StorageDocumentProvider
element
- the elementnull
CoreException
- if reading or accessing the underlying store
failsprotected String getPersistedEncoding(Object element)
getPersistedEncoding
in class StorageDocumentProvider
element
- the element for which to get the persisted encodingprotected void persistEncoding(Object element, String encoding) throws CoreException
persistEncoding
in class StorageDocumentProvider
element
- the element for which to store the persisted encodingencoding
- the encodingCoreException
- if persisting the encoding failsprotected IRunnableContext getOperationRunner(IProgressMonitor monitor)
AbstractDocumentProvider
getOperationRunner
in class StorageDocumentProvider
monitor
- a progress monitor to track the operationprotected ISchedulingRule getResetRule(Object element)
AbstractDocumentProvider
reset
on the given element. This default
implementation returns null
.getResetRule
in class AbstractDocumentProvider
element
- the elementreset
protected ISchedulingRule getSaveRule(Object element)
AbstractDocumentProvider
save
on the given element. This default
implementation returns null
.getSaveRule
in class AbstractDocumentProvider
element
- the elementsave
protected ISchedulingRule getSynchronizeRule(Object element)
AbstractDocumentProvider
synchronize
on the given element. This default
implementation returns null
.getSynchronizeRule
in class AbstractDocumentProvider
element
- the elementsynchronize
protected ISchedulingRule getValidateStateRule(Object element)
AbstractDocumentProvider
validateState
on the given element. This default
implementation returns null
.getValidateStateRule
in class AbstractDocumentProvider
element
- the elementvalidateState
protected void readUTF8BOM(IFile file, String encoding, Object element) throws CoreException
XXX: This is a workaround for a corresponding bug in Java readers and writer, see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
file
- the fileencoding
- the encodingelement
- the element, or null
CoreException
- if reading the BOM failsprotected void cacheEncodingState(Object element) throws CoreException
element
- the element, or null
CoreException
- if the encoding cannot be retrieved
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.