Eclipse Platform
2.0

org.eclipse.ui.editors.text
Class FileDocumentProvider

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

public class FileDocumentProvider
extends StorageDocumentProvider

Shareable document provider specialized for file resources (IFile).

This class may be instantiated or be subclassed.


Nested Class Summary
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.
 
Nested classes inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
 
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
FileDocumentProvider()
          Creates a new document provider.
 
Method Summary
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 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 doValidateState(Object element, Object computationContext)
          Hook method for validating the state of the given element.
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.
 long getSynchronizationStamp(Object element)
          Returns the time stamp of the last synchronization of the given element and it's provided document.
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.
 void resetDocument(Object element)
          Resets the given element's document to its last saved state.
protected  boolean setDocumentContent(IDocument document, IEditorInput editorInput)
          Deprecated. use file encoding based version
protected  boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding)
          Intitializes the given document from the given editor input using the given character encoding.
 void synchronize(Object element)
          Synchronizes the document provided for the given element with the given element.
 
Methods inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
createDocument, doUpdateStateCache, getDefaultEncoding, getEncoding, handleCoreException, isReadOnly, setDocumentContent, setDocumentContent, setEncoding, updateCache
 
Methods inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
aboutToChange, addElementStateListener, addUnchangedElementListeners, canSaveDocument, changed, connect, connected, disconnect, disconnected, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getStatus, invalidatesState, isStateValidated, mustSaveDocument, removeElementStateListener, removeUnchangedElementListeners, saveDocument, setCanSaveDocument, updateStateCache, validateState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDocumentProvider

public FileDocumentProvider()
Creates a new document provider.

Method Detail

setDocumentContent

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

Overrides StorageDocumentProvider#setDocumentContent(IDocument, IEditorInput).

Overrides:
setDocumentContent in class StorageDocumentProvider
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
Description copied from class: StorageDocumentProvider
Intitializes the given document from the given editor input using the given character encoding.

Overrides:
setDocumentContent in class StorageDocumentProvider
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

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.

Overrides:
createAnnotationModel in class StorageDocumentProvider
Parameters:
element - the element
Returns:
the annotation model
Throws:
CoreException - if the annotation model could not be created

checkSynchronizationState

protected void checkSynchronizationState(long cachedModificationStamp,
                                         IResource resource)
                                  throws CoreException
Checks whether the given resource has been changed on the local file system by comparing the actual time stamp with the cached one. If the resource has been changed, a CoreException is thrown.

Parameters:
cachedModificationStamp - the chached modification stamp
resource - the resource to check
Throws:
CoreException - if resource has been changed on the file system

computeModificationStamp

protected long computeModificationStamp(IResource resource)
Computes the initial modification stamp for the given resource.

Parameters:
resource - the resource
Returns:
the modification stamp

getModificationStamp

public long getModificationStamp(Object element)
Description copied from interface: IDocumentProvider
Returns the modification stamp of the given element.

Specified by:
getModificationStamp in interface IDocumentProvider
Overrides:
getModificationStamp in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
the modification stamp of the given element

getSynchronizationStamp

public long getSynchronizationStamp(Object element)
Description copied from interface: IDocumentProvider
Returns the time stamp of the last synchronization of the given element and it's provided document.

Specified by:
getSynchronizationStamp in interface IDocumentProvider
Overrides:
getSynchronizationStamp in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
the sysnchronization stamp of the given element

synchronize

public void synchronize(Object element)
                 throws CoreException
Description copied from interface: IDocumentProviderExtension
Synchronizes the document provided for the given element with the given element. After that call getSynchronizationTimeStamp and getModificationTimeStamp return the same value.

Specified by:
synchronize in interface IDocumentProviderExtension
Overrides:
synchronize in class AbstractDocumentProvider
Parameters:
element - the element
Throws:
CoreException - if the synchronization could not be performed

isDeleted

public boolean isDeleted(Object element)
Description copied from interface: IDocumentProvider
Returns whether the given element has been deleted.

Specified by:
isDeleted in interface IDocumentProvider
Overrides:
isDeleted in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
true if the element has been deleted

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.

Overrides:
doSaveDocument in class StorageDocumentProvider
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

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 StorageDocumentProvider
Parameters:
element - the element
Returns:
a new element info object
Throws:
CoreException - if the document or annotation model could not be created

disposeElementInfo

protected void disposeElementInfo(Object element,
                                  AbstractDocumentProvider.ElementInfo info)
Description copied from class: AbstractDocumentProvider
Disposes of the given element info object.

This method is called when an element info is disposed. The AbstractDocumentProvider implementation of this method does nothing. Subclasses may reimplement.

Overrides:
disposeElementInfo in class AbstractDocumentProvider
Parameters:
element - the element
info - the element info object

handleElementContentChanged

protected void handleElementContentChanged(IFileEditorInput fileEditorInput)
Updates the element info to a change of the file content and sends out appropriate notifications.

Parameters:
fileEditorInput - the input of an text editor

handleElementMoved

protected void handleElementMoved(IFileEditorInput fileEditorInput,
                                  IPath path)
Sends out the notification that the file serving as document input has been moved.

Parameters:
fileEditorInput - the input of an text editor
path - the path of the new location of the file

handleElementDeleted

protected void handleElementDeleted(IFileEditorInput fileEditorInput)
Sends out the notification that the file serving as document input has been deleted.

Parameters:
fileEditorInput - the input of an text editor

getElementInfo

protected AbstractDocumentProvider.ElementInfo getElementInfo(Object element)
Description copied from class: AbstractDocumentProvider
Returns the element info object for the given element.

Overrides:
getElementInfo in class AbstractDocumentProvider
Parameters:
element - the element
Returns:
the element info object, or null if none

doValidateState

protected void doValidateState(Object element,
                               Object computationContext)
                        throws CoreException
Description copied from class: AbstractDocumentProvider
Hook method for validating the state of the given element. Must not take care of cache updating etc. Default implementation is empty.

Overrides:
doValidateState in class AbstractDocumentProvider
Parameters:
element - the element
computationContext - the context in which validation happens
Throws:
CoreException - in case validation fails

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 StorageDocumentProvider
Parameters:
element - the element
Returns:
true if the given element is modifiable, false otherwise

resetDocument

public void resetDocument(Object element)
                   throws CoreException
Description copied from interface: IDocumentProvider
Resets the given element's document to its last saved state. Element state listeners are notified both before (elementContentAboutToBeReplaced) and after (elementContentReplaced) the content is changed.

Specified by:
resetDocument in interface IDocumentProvider
Overrides:
resetDocument in class AbstractDocumentProvider
Parameters:
element - the element, or null
CoreException

Eclipse Platform
2.0

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