org.eclipse.xtext.ui.editor.model
Class XtextDocumentProvider

java.lang.Object
  extended by org.eclipse.ui.texteditor.AbstractDocumentProvider
      extended by org.eclipse.ui.editors.text.StorageDocumentProvider
          extended by org.eclipse.ui.editors.text.FileDocumentProvider
              extended by org.eclipse.xtext.ui.editor.model.XtextDocumentProvider
All Implemented Interfaces:
org.eclipse.ui.editors.text.IStorageDocumentProvider, org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.texteditor.IDocumentProviderExtension, org.eclipse.ui.texteditor.IDocumentProviderExtension2, org.eclipse.ui.texteditor.IDocumentProviderExtension3, org.eclipse.ui.texteditor.IDocumentProviderExtension4, org.eclipse.ui.texteditor.IDocumentProviderExtension5
Direct Known Subclasses:
ResourceAwareXtextDocumentProvider

public class XtextDocumentProvider
extends org.eclipse.ui.editors.text.FileDocumentProvider

Author:
Peter Friese - Initial contribution and API, Sven Efftinge, Michael Clay, Heiko Behrens

Nested Class Summary
 class XtextDocumentProvider.UnchangedElementListener
           
 
Nested classes/interfaces inherited from class org.eclipse.ui.editors.text.FileDocumentProvider
org.eclipse.ui.editors.text.FileDocumentProvider.FileInfo, org.eclipse.ui.editors.text.FileDocumentProvider.FileSynchronizer, org.eclipse.ui.editors.text.FileDocumentProvider.SafeChange
 
Nested classes/interfaces inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
org.eclipse.ui.editors.text.StorageDocumentProvider.StorageInfo
 
Nested classes/interfaces inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
org.eclipse.ui.texteditor.AbstractDocumentProvider.DocumentProviderOperation, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo
 
Field Summary
 
Fields inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
DEFAULT_FILE_SIZE
 
Fields inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
PR10806_UC5_ENABLED, PR14469_ENABLED, STATUS_ERROR, STATUS_OK
 
Constructor Summary
XtextDocumentProvider()
           
 
Method Summary
protected  void addUnchangedElementListeners(java.lang.Object element, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
          Called on initial creation and when the dirty state of the element changes to false.
protected  org.eclipse.jface.text.source.IAnnotationModel createAnnotationModel(java.lang.Object element)
          Creates an annotation model for the given element.
protected  org.eclipse.jface.text.IDocument createDocument(java.lang.Object element)
          Creates the document for the given element.
protected  org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo createElementInfo(java.lang.Object element)
          Creates a new element info object for the given element.
protected  XtextDocument createEmptyDocument()
          Factory method for creating empty documents.
protected  void disposeElementInfo(java.lang.Object element, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
          Disposes of the given element info object.
 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.
 IResourceForEditorInputFactory getResourceForEditorInputFactory()
           
 boolean isDeleted(java.lang.Object element)
          Returns whether the given element has been deleted.
 boolean isSynchronized(java.lang.Object element)
          Returns whether the information provided for the given element is in sync with the element.
protected  void loadResource(XtextResource resource, java.lang.String document, java.lang.String encoding)
           
protected  void removeUnchangedElementListeners(java.lang.Object element, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
          Called when the given element gets dirty.
protected  boolean setDocumentContent(org.eclipse.jface.text.IDocument document, org.eclipse.ui.IEditorInput editorInput, java.lang.String encoding)
          Initializes the given document from the given editor input using the given character encoding.
 void setResourceForEditorInputFactory(IResourceForEditorInputFactory resourceForEditorInputFactory)
           
 
Methods inherited from class org.eclipse.ui.editors.text.FileDocumentProvider
cacheEncodingState, checkSynchronizationState, computeModificationStamp, doResetDocument, doSaveDocument, doSynchronize, doValidateState, getContentType, getElementInfo, getModificationStamp, getOperationRunner, getPersistedEncoding, getResetRule, getSaveRule, getSynchronizationStamp, getSynchronizeRule, getValidateStateRule, handleElementContentChanged, handleElementDeleted, handleElementMoved, isModifiable, persistEncoding, readUTF8BOM, refreshFile, refreshFile, setDocumentContent
 
Methods inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
doUpdateStateCache, getDefaultEncoding, handleCoreException, isNotSynchronizedException, isReadOnly, setDocumentContent, setDocumentContent, setEncoding, setupDocument, updateCache
 
Methods inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
aboutToChange, addElementStateListener, canSaveDocument, changed, connect, connected, disconnect, disconnected, executeOperation, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getProgressMonitor, getStatus, invalidatesState, isStateValidated, mustSaveDocument, removeElementStateListener, 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
 

Constructor Detail

XtextDocumentProvider

public XtextDocumentProvider()
Method Detail

createEmptyDocument

protected XtextDocument createEmptyDocument()
Description copied from class: org.eclipse.ui.editors.text.StorageDocumentProvider
Factory method for creating empty documents.

Overrides:
createEmptyDocument in class org.eclipse.ui.editors.text.StorageDocumentProvider
Returns:
the newly created document

createDocument

protected org.eclipse.jface.text.IDocument createDocument(java.lang.Object element)
                                                   throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ui.texteditor.AbstractDocumentProvider
Creates the document for the given element.

Subclasses must implement this method.

Overrides:
createDocument in class org.eclipse.ui.editors.text.StorageDocumentProvider
Parameters:
element - the element
Returns:
the document
Throws:
org.eclipse.core.runtime.CoreException - if the document could not be created

isDeleted

public boolean isDeleted(java.lang.Object element)
Description copied from interface: org.eclipse.ui.texteditor.IDocumentProvider
Returns whether the given element has been deleted.

Specified by:
isDeleted in interface org.eclipse.ui.texteditor.IDocumentProvider
Overrides:
isDeleted in class org.eclipse.ui.editors.text.FileDocumentProvider
Parameters:
element - the element
Returns:
true if the element has been deleted

setDocumentContent

protected boolean setDocumentContent(org.eclipse.jface.text.IDocument document,
                                     org.eclipse.ui.IEditorInput editorInput,
                                     java.lang.String encoding)
                              throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ui.editors.text.StorageDocumentProvider
Initializes the given document from the given editor input using the given character encoding.

Overrides:
setDocumentContent in class org.eclipse.ui.editors.text.FileDocumentProvider
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:
org.eclipse.core.runtime.CoreException - if the given editor input cannot be accessed

disposeElementInfo

protected void disposeElementInfo(java.lang.Object element,
                                  org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
Description copied from class: org.eclipse.ui.texteditor.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 org.eclipse.ui.editors.text.FileDocumentProvider
Parameters:
element - the element
info - the element info object

loadResource

protected void loadResource(XtextResource resource,
                            java.lang.String document,
                            java.lang.String encoding)
                     throws org.eclipse.core.runtime.CoreException
Throws:
org.eclipse.core.runtime.CoreException

createElementInfo

protected org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo createElementInfo(java.lang.Object element)
                                                                                    throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ui.texteditor.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 org.eclipse.ui.editors.text.FileDocumentProvider
Parameters:
element - the element
Returns:
a new element info object
Throws:
org.eclipse.core.runtime.CoreException - if the document or annotation model could not be created

addUnchangedElementListeners

protected void addUnchangedElementListeners(java.lang.Object element,
                                            org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
Description copied from class: org.eclipse.ui.texteditor.AbstractDocumentProvider
Called on initial creation and when the dirty state of the element changes to false. Adds all listeners which must be active as long as the element is not dirty. This method is called before fireElementDirtyStateChanged or fireElementContentReplaced is called. Subclasses may extend.

Overrides:
addUnchangedElementListeners in class org.eclipse.ui.texteditor.AbstractDocumentProvider
Parameters:
element - the element
info - the element info object

removeUnchangedElementListeners

protected void removeUnchangedElementListeners(java.lang.Object element,
                                               org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo info)
Description copied from class: org.eclipse.ui.texteditor.AbstractDocumentProvider
Called when the given element gets dirty. Removes all listeners which must be active only when the element is not dirty. This method is called before fireElementDirtyStateChanged or fireElementContentReplaced is called. Subclasses may extend.

Overrides:
removeUnchangedElementListeners in class org.eclipse.ui.texteditor.AbstractDocumentProvider
Parameters:
element - the element
info - the element info object

createAnnotationModel

protected org.eclipse.jface.text.source.IAnnotationModel createAnnotationModel(java.lang.Object element)
                                                                        throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ui.texteditor.AbstractDocumentProvider
Creates an annotation model for the given element.

Subclasses must implement this method.

Overrides:
createAnnotationModel in class org.eclipse.ui.editors.text.FileDocumentProvider
Parameters:
element - the element
Returns:
the annotation model or null if none
Throws:
org.eclipse.core.runtime.CoreException - if the annotation model could not be created

setResourceForEditorInputFactory

public void setResourceForEditorInputFactory(IResourceForEditorInputFactory resourceForEditorInputFactory)

getResourceForEditorInputFactory

public IResourceForEditorInputFactory getResourceForEditorInputFactory()

getEncoding

public java.lang.String getEncoding(java.lang.Object element)
Description copied from interface: org.eclipse.ui.editors.text.IStorageDocumentProvider
Returns the character encoding for the given element, or null if the element is not managed by this provider.

Specified by:
getEncoding in interface org.eclipse.ui.editors.text.IStorageDocumentProvider
Overrides:
getEncoding in class org.eclipse.ui.editors.text.StorageDocumentProvider
Parameters:
element - the element
Returns:
the encoding for the given element

isSynchronized

public boolean isSynchronized(java.lang.Object element)
Description copied from interface: org.eclipse.ui.texteditor.IDocumentProviderExtension3
Returns whether the information provided for the given element is in sync with the element.

Specified by:
isSynchronized in interface org.eclipse.ui.texteditor.IDocumentProviderExtension3
Overrides:
isSynchronized in class org.eclipse.ui.editors.text.FileDocumentProvider
Parameters:
element - the element
Returns:
true if the information is in sync with the element, false otherwise