org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document
Class FileDocumentProvider
java.lang.Object
org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider
org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.StorageDocumentProvider
org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.FileDocumentProvider
-
All Implemented Interfaces:
-
IDocumentProvider
-
Direct Known Subclasses:
-
FileDiagramDocumentProvider
-
public abstract class FileDocumentProvider
- extends
StorageDocumentProvider
Shared document provider specialized for file resources (IFile
).
This class should be subclassed for different types of documents.
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
AbstractDocumentProvider.ElementInfo
|
createElementInfo
(java.lang.Object element)
Creates a new element info object for the given element. |
protected
FileDocumentProvider.FileInfo
|
createFileInfo
(
IDocument document,
FileDocumentProvider.FileSynchronizer synchronizer,
IFileEditorInput input)
Create a FileInfo for the given document. |
protected void
|
disposeElementInfo
(java.lang.Object element,
AbstractDocumentProvider.ElementInfo info)
Disposes of the given element info object. |
protected void
|
doResetDocument
(java.lang.Object element,
IProgressMonitor monitor)
Executes the actual work of reseting the given elements document. |
protected void
|
doSaveDocument
(
IProgressMonitor monitor,
java.lang.Object element,
IDocument document,
boolean overwrite)
Performs the actual work of saving the given document provided for the
given element. |
protected void
|
doSynchronize
(java.lang.Object element,
IProgressMonitor monitor)
Performs the actual work of synchronizing the given element. |
protected void
|
doValidateState
(java.lang.Object element,
java.lang.Object computationContext)
Hook method for validating the state of the given element. |
protected
AbstractDocumentProvider.ElementInfo
|
getElementInfo
(java.lang.Object element)
Returns the element info object for the given element. |
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
ISchedulingRule
|
getResetRule
(java.lang.Object element)
Returns the scheduling rule required for executing
reset on the given element. |
protected
ISchedulingRule
|
getSaveRule
(java.lang.Object element)
Returns the scheduling rule required for executing
save on 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
ISchedulingRule
|
getSynchronizeRule
(java.lang.Object element)
Returns the scheduling rule required for executing
synchronize on the given element. |
protected
ISchedulingRule
|
getValidateStateRule
(java.lang.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
(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
|
isSynchronized
(java.lang.Object element)
Returns whether the information provided for the given element is in sync with the element. |
protected void
|
refreshFile
(
IFile file)
Refreshes the given file resource. |
protected void
|
refreshFile
(
IFile file,
IProgressMonitor monitor)
Refreshes the given file resource. |
protected abstract void
|
saveDocumentToFile
(
IDocument document,
IFile file,
boolean overwrite,
IProgressMonitor monitor)
Initializes the given document with the given stream using the given encoding. |
protected void
|
setDocumentContent
(
IDocument document,
java.lang.Object content)
Initializes the given document with the given stream using the given encoding. |
Methods inherited from class org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.
AbstractDocumentProvider
|
aboutToChange,
addElementStateListener,
addUnchangedElementListeners,
canSaveDocument,
changed,
connect,
connected,
disconnect,
disconnected,
executeOperation,
fireElementContentAboutToBeReplaced,
fireElementContentReplaced,
fireElementDeleted,
fireElementDirtyStateChanged,
fireElementMoved,
fireElementStateChangeFailed,
fireElementStateChanging,
fireElementStateValidationChanged,
getConnectedElements,
getDocument,
getProgressMonitor,
getResetOperation,
getSaveOperation,
getStatus,
invalidatesState,
isStateValidated,
mustSaveDocument,
removeElementStateListener,
removeUnchangedElementListeners,
resetDocument,
saveDocument,
setCanSaveDocument,
setProgressMonitor,
synchronize,
updateStateCache,
validateState
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
|
fResourceRuleFactory
protected
IResourceRuleFactory fResourceRuleFactory
- The scheduling rule factory.
FileDocumentProvider
public FileDocumentProvider()
- Creates and returns a new document provider.
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 cached 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(java.lang.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(java.lang.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 synchronization stamp of the given element
doSynchronize
protected void doSynchronize(java.lang.Object element,
IProgressMonitor monitor)
throws
CoreException
-
Description copied from class:
AbstractDocumentProvider
- Performs the actual work of synchronizing the given element.
-
-
Overrides:
-
doSynchronize
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element -
monitor
- the progress monitor
-
Throws:
-
CoreException
- in the case that synchronization fails
isDeleted
public boolean isDeleted(java.lang.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
saveDocumentToFile
protected abstract void saveDocumentToFile(
IDocument document,
IFile file,
boolean overwrite,
IProgressMonitor monitor)
throws
CoreException
- Initializes 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
doSaveDocument
protected void doSaveDocument(
IProgressMonitor monitor,
java.lang.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 cancellation -
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(java.lang.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
createFileInfo
protected
FileDocumentProvider.FileInfo createFileInfo(
IDocument document,
FileDocumentProvider.FileSynchronizer synchronizer,
IFileEditorInput input)
- Create a FileInfo for the given document.
May also construct and start required listeners.
-
-
Parameters:
-
document
- to create a FileInfo for -
synchronizer
- FileSynchronizer which has been created for the
IFileEditorInput -
input
- IFileEditorInput corresponding to the document
-
Returns:
- FileInfo for the given document
disposeElementInfo
protected void disposeElementInfo(java.lang.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 a document editor
setDocumentContent
protected void setDocumentContent(
IDocument document,
java.lang.Object content)
throws
CoreException
- Initializes 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
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 document 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 document editor
getElementInfo
protected
AbstractDocumentProvider.ElementInfo getElementInfo(java.lang.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(java.lang.Object element,
java.lang.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(java.lang.Object element)
-
Description copied from interface:
IDocumentProvider
- 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
IDocumentProvider
-
Overrides:
-
isModifiable
in class
StorageDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
-
true
if the given element is modifiable, false
otherwise
doResetDocument
protected void doResetDocument(java.lang.Object element,
IProgressMonitor monitor)
throws
CoreException
-
Description copied from class:
AbstractDocumentProvider
- Executes the actual work of reseting the given elements document.
-
-
Overrides:
-
doResetDocument
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element -
monitor
- the progress monitor
-
Throws:
-
CoreException
refreshFile
protected void refreshFile(
IFile file)
throws
CoreException
- Refreshes the given file resource.
-
-
Parameters:
-
file
-
-
Throws:
-
CoreException
- if the refresh fails
refreshFile
protected void refreshFile(
IFile file,
IProgressMonitor monitor)
throws
CoreException
- Refreshes the given file resource.
-
-
Parameters:
-
file
- the file to be refreshed -
monitor
- the progress monitor
-
Throws:
-
CoreException
- if the refresh fails
isSynchronized
public boolean isSynchronized(java.lang.Object element)
-
Description copied from interface:
IDocumentProvider
- Returns whether the information provided for the given element is in sync with the element.
-
-
Specified by:
-
isSynchronized
in interface
IDocumentProvider
-
Overrides:
-
isSynchronized
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
-
true
if the information is in sync with the element, false
otherwise
getOperationRunner
protected
IRunnableContext getOperationRunner(
IProgressMonitor monitor)
-
Description copied from class:
AbstractDocumentProvider
- Returns the runnable context for this document provider.
-
-
Overrides:
-
getOperationRunner
in class
StorageDocumentProvider
-
-
Parameters:
-
monitor
- a progress monitor to track the operation
-
Returns:
- the runnable context for this document provider
getResetRule
protected
ISchedulingRule getResetRule(java.lang.Object element)
-
Description copied from class:
AbstractDocumentProvider
- Returns the scheduling rule required for executing
reset
on the given element. This default
implementation returns null
.
-
-
Overrides:
-
getResetRule
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
- the scheduling rule for
reset
getSaveRule
protected
ISchedulingRule getSaveRule(java.lang.Object element)
-
Description copied from class:
AbstractDocumentProvider
- Returns the scheduling rule required for executing
save
on the given element. This default
implementation returns null
.
-
-
Overrides:
-
getSaveRule
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
- the scheduling rule for
save
getSynchronizeRule
protected
ISchedulingRule getSynchronizeRule(java.lang.Object element)
-
Description copied from class:
AbstractDocumentProvider
- Returns the scheduling rule required for executing
synchronize
on the given element. This default
implementation returns null
.
-
-
Overrides:
-
getSynchronizeRule
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
- the scheduling rule for
synchronize
getValidateStateRule
protected
ISchedulingRule getValidateStateRule(java.lang.Object element)
-
Description copied from class:
AbstractDocumentProvider
- Returns the scheduling rule required for executing
validateState
on the given element. This default
implementation returns null
.
-
-
Overrides:
-
getValidateStateRule
in class
AbstractDocumentProvider
-
-
Parameters:
-
element
- the element
-
Returns:
- the scheduling rule for
validateState
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.