Class TextEditorBuffer
- All Implemented Interfaces:
AutoCloseable,IBuffer,ISnapshotProvider,IReferenceCountable
IBuffer backed by a text editor document.
An instance of this class is safe for use by multiple threads, provided that the underlying text editor document is thread-safe. However, certain operations can only be executed by the UI thread:
saveisDirtyapplyChange- if save is requestedaddListenerremoveListener
-
Constructor Summary
ConstructorsConstructorDescriptionTextEditorBuffer(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput input) Creates a new buffer instance and connects it to the document provided for the given editor input via the given provider.TextEditorBuffer(org.eclipse.ui.texteditor.ITextEditor editor) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(IBufferListener listener) Adds the given listener to this buffer.voidaddRef()Spawns a new independent ownership of this object.applyChange(IBufferChange change, org.eclipse.core.runtime.IProgressMonitor monitor) Applies the given change to this buffer.org.eclipse.jface.text.source.IAnnotationModelReturns the annotation model of this buffer, if any.org.eclipse.jface.text.IDocumentReturns the underlying document of this buffer.Returns the current snapshot of this buffer.intReturns a bit-mask describing the listener methods supported by this buffer.booleanisDirty()Returns whether this buffer has been modified since the last time it was opened or saved.voidrelease()Relinquishes an independent ownership of this object.voidremoveListener(IBufferListener listener) Removes the given listener from this buffer.voidSaves this buffer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.handly.util.IReferenceCountable
close
-
Constructor Details
-
TextEditorBuffer
public TextEditorBuffer(org.eclipse.ui.texteditor.ITextEditor editor) throws org.eclipse.core.runtime.CoreException Deprecated.UseTextEditorBuffer(IDocumentProvider, IEditorInput)instead.Creates a new buffer instance and connects it to the current document of the given text editor.Note: The association between the buffer and the document will not change even if the association between the text editor and the document changes (e.g., when a new editor input is set).
It is the client responsibility to
releasethe created buffer after it is no longer needed.This constructor can only be executed by the UI thread.
- Parameters:
editor- notnull- Throws:
org.eclipse.core.runtime.CoreException- if the buffer could not be connected
-
TextEditorBuffer
public TextEditorBuffer(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput input) throws org.eclipse.core.runtime.CoreException Creates a new buffer instance and connects it to the document provided for the given editor input via the given provider.It is the client responsibility to
releasethe created buffer after it is no longer needed.This constructor can only be executed by the UI thread.
- Parameters:
provider- a document provider (notnull)input- an editor input (notnull)- Throws:
org.eclipse.core.runtime.CoreException- if the buffer could not be connected- Since:
- 1.5
-
-
Method Details
-
getDocument
public org.eclipse.jface.text.IDocument getDocument()Description copied from interface:IBufferReturns the underlying document of this buffer. The relationship between a buffer and its document does not change over the lifetime of the buffer.- Specified by:
getDocumentin interfaceIBuffer- Returns:
- the buffer's underlying document (never
null)
-
getAnnotationModel
public org.eclipse.jface.text.source.IAnnotationModel getAnnotationModel()Description copied from interface:IBufferReturns the annotation model of this buffer, if any.- Specified by:
getAnnotationModelin interfaceIBuffer- Returns:
- the buffer's annotation model, or
nullif none
-
getSnapshot
Description copied from interface:IBufferReturns the current snapshot of this buffer. The returned snapshot may immediately become stale or expire.Note that it is possible to obtain a
non-expiringsnapshot from the buffer, although protractedly holding on non-expiring snapshots is not recommended as they may potentially consume large amount of space.- Specified by:
getSnapshotin interfaceIBuffer- Specified by:
getSnapshotin interfaceISnapshotProvider- Returns:
- the buffer's current snapshot (never
null)
-
applyChange
public IBufferChange applyChange(IBufferChange change, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException Description copied from interface:IBufferApplies the given change to this buffer.Note that an update conflict may occur if the buffer's contents have changed since the inception of the snapshot on which the change is based. In that case, a
StaleSnapshotExceptionis thrown.- Specified by:
applyChangein interfaceIBuffer- Parameters:
change- a buffer change (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- undo change, if requested by the change. Otherwise,
null - Throws:
org.eclipse.core.runtime.CoreException- if the change's edit tree is not in a valid state, or if one of the edits in the tree could not be executed, or if save is requested by the change but the buffer could not be saved
-
save
public void save(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException Description copied from interface:IBufferSaves this buffer. It is up to the implementors of this method to decide what saving means. Typically, the contents of the underlying resource is changed to the contents of the buffer.- Specified by:
savein interfaceIBuffer- Parameters:
context- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Throws:
org.eclipse.core.runtime.CoreException- if the buffer could not be saved
-
isDirty
public boolean isDirty()Description copied from interface:IBufferReturns whether this buffer has been modified since the last time it was opened or saved. -
getSupportedListenerMethods
public int getSupportedListenerMethods()Description copied from interface:IBufferReturns a bit-mask describing the listener methods supported by this buffer. The buffer will never invoke a listener method it does not support.- Specified by:
getSupportedListenerMethodsin interfaceIBuffer- Returns:
- a bit-mask describing the supported listener methods
- See Also:
-
addListener
Description copied from interface:IBufferAdds the given listener to this buffer. Has no effect if the same listener is already registered.- Specified by:
addListenerin interfaceIBuffer- Parameters:
listener- notnull
-
removeListener
Description copied from interface:IBufferRemoves the given listener from this buffer. Has no effect if the same listener was not already registered.- Specified by:
removeListenerin interfaceIBuffer- Parameters:
listener- notnull
-
addRef
public void addRef()Description copied from interface:IReferenceCountableSpawns a new independent ownership of this object. Each successful call toaddRef()must ultimately be followed by exactly one call toIReferenceCountable.release().- Specified by:
addRefin interfaceIBuffer- Specified by:
addRefin interfaceIReferenceCountable- Specified by:
addRefin interfaceISnapshotProvider
-
release
public void release()Description copied from interface:IReferenceCountableRelinquishes an independent ownership of this object. Each independent ownership of the object must ultimately end with exactly one call to this method.- Specified by:
releasein interfaceIBuffer- Specified by:
releasein interfaceIReferenceCountable- Specified by:
releasein interfaceISnapshotProvider- See Also:
-
TextEditorBuffer(IDocumentProvider, IEditorInput)instead.