public final class TextEditorBuffer extends java.lang.Object implements IBuffer
IBuffer
backed by an ITextEditor
.
An instance of this class is safe for use by multiple threads, provided that the underlying text editor's document is thread-safe. However, certain operations can only be executed by the UI thread:
save
isDirty
applyChange
-
if save is requestedConstructor and Description |
---|
TextEditorBuffer(org.eclipse.ui.texteditor.ITextEditor editor)
Creates a new buffer instance and connects it to the given text editor.
|
Modifier and Type | Method and Description |
---|---|
void |
addRef()
Spawns a new independent ownership of this object.
|
IBufferChange |
applyChange(IBufferChange change,
org.eclipse.core.runtime.IProgressMonitor monitor)
Applies the given change to this buffer.
|
org.eclipse.jface.text.IDocument |
getDocument()
Returns the underlying document of this buffer.
|
ISnapshot |
getSnapshot()
Returns the current snapshot of this buffer.
|
boolean |
isDirty()
Returns whether this buffer has been modified since the last time
it was opened or saved.
|
void |
release()
Relinquishes an independent ownership of this object.
|
void |
save(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Saves this buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public TextEditorBuffer(org.eclipse.ui.texteditor.ITextEditor editor) throws org.eclipse.core.runtime.CoreException
It is the client responsibility to release
the created buffer after it is no longer needed.
This constructor can only be executed by the UI thread.
editor
- not null
org.eclipse.core.runtime.CoreException
- if the buffer could not be connectedpublic org.eclipse.jface.text.IDocument getDocument()
IBuffer
getDocument
in interface IBuffer
null
)public ISnapshot getSnapshot()
IBuffer
Note that it is possible to obtain a non-expiring
snapshot from the buffer, although protractedly holding on non-expiring
snapshots is not recommended as they may potentially consume large amount
of space.
getSnapshot
in interface IBuffer
getSnapshot
in interface ISnapshotProvider
null
)public IBufferChange applyChange(IBufferChange change, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
IBuffer
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 StaleSnapshotException
is thrown.
applyChange
in interface IBuffer
change
- a buffer change (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
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 savedpublic void save(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
IBuffer
save
in interface IBuffer
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if the buffer could not be savedpublic boolean isDirty()
IBuffer
public void addRef()
IReferenceCountable
addRef()
must ultimately be
followed by exactly one call to IReferenceCountable.release()
.addRef
in interface IBuffer
addRef
in interface ISnapshotProvider
addRef
in interface IReferenceCountable
public void release()
IReferenceCountable
release
in interface IBuffer
release
in interface ISnapshotProvider
release
in interface IReferenceCountable
IReferenceCountable.close()
Copyright (c) 2014, 2018 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0