|
Eclipse Platform Release 3.6 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.ui.editors.text.TextFileDocumentProvider
public class TextFileDocumentProvider
Shared document provider specialized for IFile based domain elements.
A text file document provider can have a parent document provider to which
it may delegate calls i.e. instead of delegating work to a super class it
delegates to a parent document provider. The parent chain acts as chain
of command.
Text file document providers use text file buffers to access the file content. This allows to share it between various clients including headless ones. Text file document providers should be preferred over file document providers due to this advantage.
Use a forwarding document provider if you need to ensure that all documents provided to clients are appropriately set up.
Clients can directly instantiate and configure this class with a suitable parent document provider or provide their own subclass.
| Nested Class Summary | |
|---|---|
protected static class |
TextFileDocumentProvider.DocumentProviderOperation
Operation created by the document provider and to be executed by the providers runnable context. |
protected class |
TextFileDocumentProvider.FileBufferListener
|
protected static class |
TextFileDocumentProvider.FileInfo
|
protected static class |
TextFileDocumentProvider.NullProvider
Deprecated. since 3.3 - do not use |
| Constructor Summary | |
|---|---|
TextFileDocumentProvider()
Creates a new text file document provider with no parent. |
|
TextFileDocumentProvider(IDocumentProvider parentProvider)
Creates a new text file document provider which has the given parent provider. |
|
| Method Summary | |
|---|---|
void |
aboutToChange(java.lang.Object element)
Informs this document provider about upcoming changes of the given element. |
void |
addElementStateListener(IElementStateListener listener)
Adds the given element state listener to this document provider. |
boolean |
canSaveDocument(java.lang.Object element)
Returns whether the document provided for the given element differs from its original state which would required that it be saved. |
void |
changed(java.lang.Object element)
Informs this document provider that the given element has been changed. |
protected void |
commitFileBuffer(IProgressMonitor monitor,
TextFileDocumentProvider.FileInfo info,
boolean overwrite)
Commits the given file info's file buffer by changing the contents of the underlying file to the contents of this file buffer. |
protected ISchedulingRule |
computeSchedulingRule(IResource toCreateOrModify)
Computes the scheduling rule needed to create or modify a resource. |
void |
connect(java.lang.Object element)
Connects the given element to this document provider. |
protected IAnnotationModel |
createAnnotationModel(IFile file)
Creates and returns the annotation model for the given file. |
protected TextFileDocumentProvider.FileInfo |
createEmptyFileInfo()
Creates and returns a new and empty file info object. |
protected void |
createFileFromDocument(IProgressMonitor monitor,
IFile file,
IDocument document)
Creates the given file with the given document content. |
protected TextFileDocumentProvider.FileInfo |
createFileInfo(java.lang.Object element)
Creates and returns the file info object for the given element. |
protected TextFileDocumentProvider.DocumentProviderOperation |
createSaveOperation(java.lang.Object element,
IDocument document,
boolean overwrite)
|
void |
disconnect(java.lang.Object element)
Disconnects the given element from this document provider. |
protected void |
disposeFileInfo(java.lang.Object element,
TextFileDocumentProvider.FileInfo info)
Releases all resources described by given element's info object. |
protected void |
executeOperation(TextFileDocumentProvider.DocumentProviderOperation operation,
IProgressMonitor monitor)
Executes the given operation in the providers runnable context. |
protected void |
fireElementStateChangeFailed(java.lang.Object element)
Informs all registered element state listeners about the failed state change of the element. |
protected void |
fireElementStateChanging(java.lang.Object element)
Informs all registered element state listeners about the current state change of the element. |
IAnnotationModel |
getAnnotationModel(java.lang.Object element)
Returns the annotation model for the given element. |
protected java.util.Iterator |
getConnectedElementsIterator()
Returns an iterator over the elements connected via this document provider. |
IContentType |
getContentType(java.lang.Object element)
Returns the content type of for the given element or null if none could be determined. |
java.lang.String |
getDefaultEncoding()
Returns the default character encoding used by this provider. |
IDocument |
getDocument(java.lang.Object element)
Returns the document for the given element. |
protected java.util.Iterator |
getElements(IFileBuffer file)
Returns an iterator for all the elements that are connected to this file buffer. |
java.lang.String |
getEncoding(java.lang.Object element)
Returns the character encoding for the given element, or null if the element is not managed by this provider. |
protected TextFileDocumentProvider.FileInfo |
getFileInfo(java.lang.Object element)
Returns the file info object for the given element. |
protected java.util.Iterator |
getFileInfosIterator()
Returns an iterator over this document provider's file info objects. |
protected IFileStore |
getFileStore(TextFileDocumentProvider.FileInfo info)
Returns the file store denoted by the given info. |
long |
getModificationStamp(java.lang.Object element)
Returns the modification stamp of the given element. |
protected IRunnableContext |
getOperationRunner(IProgressMonitor monitor)
Returns the runnable context for this document provider. |
protected IDocumentProvider |
getParentProvider()
Returns the parent document provider. |
IProgressMonitor |
getProgressMonitor()
Returns this providers progress monitor. |
IStatus |
getStatus(java.lang.Object element)
Returns the status of the given element. |
long |
getSynchronizationStamp(java.lang.Object element)
Returns the time stamp of the last synchronization of the given element and it's provided document. |
protected java.io.File |
getSystemFile(TextFileDocumentProvider.FileInfo info)
Deprecated. As of 3.2, replaced by getFileStore(org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo) |
protected void |
handleCoreException(CoreException exception,
java.lang.String message)
Defines the standard procedure to handle CoreExceptions. |
boolean |
isDeleted(java.lang.Object element)
Returns whether the given element has been deleted. |
boolean |
isModifiable(java.lang.Object element)
Returns whether the document provider thinks that the given element can persistently be modified. |
boolean |
isNotSynchronizedException(java.lang.Object element,
CoreException ex)
Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element. |
boolean |
isReadOnly(java.lang.Object element)
Returns whether the document provider thinks that the given element is read-only. |
boolean |
isStateValidated(java.lang.Object element)
Returns whether the state of the given element has been validated. |
boolean |
isSynchronized(java.lang.Object element)
Returns whether the information provided for the given element is in sync with the element. |
protected boolean |
isSystemFileReadOnly(TextFileDocumentProvider.FileInfo info)
Returns whether the system file denoted by the given info is read-only. |
boolean |
mustSaveDocument(java.lang.Object element)
Returns whether the document provided for the given element must be saved. |
void |
removeElementStateListener(IElementStateListener listener)
Removes the given element state listener from this document provider. |
void |
resetDocument(java.lang.Object element)
Resets the given element's document to its last saved state. |
void |
saveDocument(IProgressMonitor monitor,
java.lang.Object element,
IDocument document,
boolean overwrite)
Saves the given document provided for the given element. |
void |
setCanSaveDocument(java.lang.Object element)
Marks the document managed for the given element as savable. |
void |
setEncoding(java.lang.Object element,
java.lang.String encoding)
Sets the encoding for the given element. |
void |
setParentDocumentProvider(IDocumentProvider parentProvider)
Sets the given parent provider as this document provider's parent document provider. |
void |
setProgressMonitor(IProgressMonitor progressMonitor)
Sets this providers progress monitor. |
protected void |
setUpSynchronization(TextFileDocumentProvider.FileInfo info)
Sets up the synchronization for the document and the annotation mode. |
void |
synchronize(java.lang.Object element)
Synchronizes the document provided for the given element with the given element. |
void |
updateStateCache(java.lang.Object element)
Updates the state cache for the given element. |
void |
validateState(java.lang.Object element,
java.lang.Object computationContext)
Validates the state of the given element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TextFileDocumentProvider()
public TextFileDocumentProvider(IDocumentProvider parentProvider)
parentProvider - the parent document provider| Method Detail |
|---|
public final void setParentDocumentProvider(IDocumentProvider parentProvider)
parentProvider - the parent document providerprotected final IDocumentProvider getParentProvider()
protected IRunnableContext getOperationRunner(IProgressMonitor monitor)
monitor - the progress monitor
protected void executeOperation(TextFileDocumentProvider.DocumentProviderOperation operation,
IProgressMonitor monitor)
throws CoreException
operation - the operation to be executesmonitor - the progress monitor
CoreException - the operation's core exception
public void connect(java.lang.Object element)
throws CoreException
IDocumentProviderdisconnect(Object) this provider can assume to know the
correct number of clients working with the document provided for that
domain model element.
The given element must not be null.
connect in interface IDocumentProviderelement - the element
CoreException - if the textual representation or the annotation model
of the element could not be createdprotected TextFileDocumentProvider.FileInfo createEmptyFileInfo()
Subclasses which extend TextFileDocumentProvider.FileInfo
should override this method.
FileInfo
protected TextFileDocumentProvider.FileInfo createFileInfo(java.lang.Object element)
throws CoreException
Subclasses which extend TextFileDocumentProvider.FileInfo
will probably have to extend this method as well.
element - the element
FileInfo
or null if none can be created
CoreException - if the file info object could not successfully be createdprotected void setUpSynchronization(TextFileDocumentProvider.FileInfo info)
info - the file infoprotected IAnnotationModel createAnnotationModel(IFile file)
file - the file
null if nonepublic void disconnect(java.lang.Object element)
IDocumentProviderconnect(Object) and of this method this provider can assume to
know the correct number of clients working with the document provided for that
domain model element.
The given element must not be null.
disconnect in interface IDocumentProviderelement - the element
protected void disposeFileInfo(java.lang.Object element,
TextFileDocumentProvider.FileInfo info)
Subclasses which extend TextFileDocumentProvider.FileInfo
will probably have to extend this method as well.
element - the elementinfo - the element's file info objectprotected java.util.Iterator getElements(IFileBuffer file)
file - the file buffer
public IDocument getDocument(java.lang.Object element)
IDocumentProvider
getDocument in interface IDocumentProviderelement - the element, or null
null if none
public void resetDocument(java.lang.Object element)
throws CoreException
IDocumentProviderelementContentAboutToBeReplaced)
and after (elementContentReplaced) the content is changed.
resetDocument in interface IDocumentProviderelement - the element, or null
CoreException - if document could not be reset for the given element
public final void saveDocument(IProgressMonitor monitor,
java.lang.Object element,
IDocument document,
boolean overwrite)
throws CoreException
IDocumentProvider
saveDocument in interface IDocumentProvidermonitor - a progress monitor to report progress and request cancelationelement - the element, or nulldocument - the documentoverwrite - indicates whether overwrite should be performed
while saving the given element if necessary
CoreException - if document could not be stored to the given element
protected TextFileDocumentProvider.DocumentProviderOperation createSaveOperation(java.lang.Object element,
IDocument document,
boolean overwrite)
throws CoreException
CoreException
protected void commitFileBuffer(IProgressMonitor monitor,
TextFileDocumentProvider.FileInfo info,
boolean overwrite)
throws CoreException
isDirty returns false and isSynchronized
returns true.
monitor - the progress monitorinfo - the element's file info objectoverwrite - indicates whether the underlying file should be overwritten if it is not synchronized with the file system
CoreException - if writing or accessing the underlying file fails
protected void createFileFromDocument(IProgressMonitor monitor,
IFile file,
IDocument document)
throws CoreException
monitor - the progress monitorfile - the file to be createddocument - the document to be written to the file
CoreException - if the creation of the file failspublic long getModificationStamp(java.lang.Object element)
IDocumentProvider
getModificationStamp in interface IDocumentProviderelement - the element
public long getSynchronizationStamp(java.lang.Object element)
IDocumentProvider
getSynchronizationStamp in interface IDocumentProviderelement - the element
public boolean isDeleted(java.lang.Object element)
IDocumentProvider
isDeleted in interface IDocumentProviderelement - the element
true if the element has been deletedpublic boolean mustSaveDocument(java.lang.Object element)
IDocumentProvider
mustSaveDocument in interface IDocumentProviderelement - the element, or null
true if the document must be saved, and
false otherwise (including the element is null)public boolean canSaveDocument(java.lang.Object element)
IDocumentProvider
canSaveDocument in interface IDocumentProviderelement - the element, or null
true if the document can be saved, and
false otherwise (including the element is null)public IAnnotationModel getAnnotationModel(java.lang.Object element)
IDocumentProvider
getAnnotationModel in interface IDocumentProviderelement - the element, or null
null if nonepublic void aboutToChange(java.lang.Object element)
IDocumentProvider
aboutToChange has been and before changed is called. In this case,
it is assumed that the document is already up to date, e.g., a save operation is a
typical case.
The concrete nature of the change notification depends on the concrete type of the
given element. If the element is, e.g., an IResource the notification
is a resource delta.
aboutToChange in interface IDocumentProviderelement - the element, or nullpublic void changed(java.lang.Object element)
IDocumentProviderIResource the notification is a resource delta.
changed in interface IDocumentProviderelement - the element, or nullpublic void addElementStateListener(IElementStateListener listener)
IDocumentProvider
addElementStateListener in interface IDocumentProviderlistener - the listenerpublic void removeElementStateListener(IElementStateListener listener)
IDocumentProvider
removeElementStateListener in interface IDocumentProviderlistener - the listenerpublic boolean isReadOnly(java.lang.Object element)
IDocumentProviderExtensiontrue, 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.
isReadOnly in interface IDocumentProviderExtensionelement - the element
true if the given element is read-only, false otherwisepublic boolean isModifiable(java.lang.Object element)
IDocumentProviderExtensionisReadOnly 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 IDocumentProviderExtensionelement - the element
true if the given element is modifiable, false otherwise
public void validateState(java.lang.Object element,
java.lang.Object computationContext)
throws CoreException
IDocumentProviderExtensionisReadOnly and isModifiable. If the
given element is not connected to this document provider, the effect is undefined.
validateState in interface IDocumentProviderExtensionelement - the elementcomputationContext - the context in which the computation is performed, e.g., a SWT shell
CoreException - if validating failspublic boolean isStateValidated(java.lang.Object element)
IDocumentProviderExtension
isStateValidated in interface IDocumentProviderExtensionelement - the element
true if the state has been validated
public void updateStateCache(java.lang.Object element)
throws CoreException
IDocumentProviderExtensionisReadOnly and isModifiable. If the given element is not
connected to this document provider, the effect is undefined.
updateStateCache in interface IDocumentProviderExtensionelement - the element
CoreException - if validating failspublic void setCanSaveDocument(java.lang.Object element)
IDocumentProviderExtensioncanBeSaved(element) will return true
afterwards.
setCanSaveDocument in interface IDocumentProviderExtensionelement - the elementpublic IStatus getStatus(java.lang.Object element)
IDocumentProviderExtension
getStatus in interface IDocumentProviderExtensionelement - the element
public void synchronize(java.lang.Object element)
throws CoreException
IDocumentProviderExtensiongetSynchronizationTimeStamp
and getModificationTimeStamp return the same value.
synchronize in interface IDocumentProviderExtensionelement - the element
CoreException - if the synchronization could not be performedpublic void setProgressMonitor(IProgressMonitor progressMonitor)
IDocumentProviderExtension2
setProgressMonitor in interface IDocumentProviderExtension2progressMonitor - the progress monitorpublic IProgressMonitor getProgressMonitor()
IDocumentProviderExtension2
getProgressMonitor in interface IDocumentProviderExtension2public boolean isSynchronized(java.lang.Object element)
IDocumentProviderExtension3
isSynchronized in interface IDocumentProviderExtension3element - the element
true if the information is in sync with the element, false otherwise
public boolean isNotSynchronizedException(java.lang.Object element,
CoreException ex)
IDocumentProviderExtension5
isNotSynchronizedException in interface IDocumentProviderExtension5element - the elementex - the core exception
true iff the given core exception is exactly the
exception which is thrown for a non-synchronized elementpublic java.lang.String getDefaultEncoding()
IStorageDocumentProvider
getDefaultEncoding in interface IStorageDocumentProviderpublic java.lang.String getEncoding(java.lang.Object element)
IStorageDocumentProvidernull if the element is not managed by this provider.
getEncoding in interface IStorageDocumentProviderelement - the element
public void setEncoding(java.lang.Object element,
java.lang.String encoding)
IStorageDocumentProviderencoding
is null the workbench's character encoding should be used.
setEncoding in interface IStorageDocumentProviderelement - the elementencoding - the encoding to be used
public IContentType getContentType(java.lang.Object element)
throws CoreException
IDocumentProviderExtension4null 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 IDocumentProviderExtension4element - the element
null
CoreException - if reading or accessing the underlying store
fails
protected void handleCoreException(CoreException exception,
java.lang.String message)
CoreExceptions. Exceptions
are written to the plug-in log.
exception - the exception to be loggedmessage - the message to be loggedprotected IFileStore getFileStore(TextFileDocumentProvider.FileInfo info)
info - the element's file info object
IFileStore for the given file infoprotected java.io.File getSystemFile(TextFileDocumentProvider.FileInfo info)
getFileStore(org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
info - the element's file info object
protected boolean isSystemFileReadOnly(TextFileDocumentProvider.FileInfo info)
info - the element's file info object
true iff read-onlyprotected TextFileDocumentProvider.FileInfo getFileInfo(java.lang.Object element)
element - the element
null if noneprotected java.util.Iterator getConnectedElementsIterator()
Objectprotected java.util.Iterator getFileInfosIterator()
TextFileDocumentProvider.FileInfoprotected void fireElementStateChanging(java.lang.Object element)
element - the elementIElementStateListenerExtension.elementStateChanging(Object)protected void fireElementStateChangeFailed(java.lang.Object element)
element - the elementIElementStateListenerExtension.elementStateChangeFailed(Object)protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify)
toCreateOrModify that exists. Then the
'create' rule for the last non-existing resource is returned.
toCreateOrModify - the resource to create or modify
|
Eclipse Platform Release 3.6 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2010. All rights reserved.