Package de.loskutov.anyedit.compare
Class EditableSharedDocumentAdapter
- java.lang.Object
-
- org.eclipse.compare.SharedDocumentAdapter
-
- de.loskutov.anyedit.compare.EditableSharedDocumentAdapter
-
- All Implemented Interfaces:
org.eclipse.compare.ISharedDocumentAdapter
,org.eclipse.ui.texteditor.IElementStateListener
public class EditableSharedDocumentAdapter extends org.eclipse.compare.SharedDocumentAdapter implements org.eclipse.ui.texteditor.IElementStateListener
A shared document adapter that tracks whether the element is connected to a shared document and whether the contents have been flushed from a compare viewer. When contents are flushed, this adapter will connect to the document provider to ensure that the changes are not lost (seehasBufferedContents()
). In order to avoid a leak, the buffer must either be saved (seesaveDocument(IEditorInput, boolean, IProgressMonitor)
) or released (seereleaseBuffer()
).This adapter must have a one-to-one correspondence to a typed element.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EditableSharedDocumentAdapter.SharedDocumentAdapterListener
Interface that provides this adapter with the state of the typed element and supports call backs to the element when the adapter state changes.
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.ui.IEditorInput
bufferedKey
private int
connectionCount
private EditableSharedDocumentAdapter.SharedDocumentAdapterListener
listener
-
Constructor Summary
Constructors Constructor Description EditableSharedDocumentAdapter(StreamContent content)
Create the shared document adapter for the given element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey)
void
disconnect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey)
void
elementContentAboutToBeReplaced(java.lang.Object element)
void
elementContentReplaced(java.lang.Object element)
void
elementDeleted(java.lang.Object element)
void
elementDirtyStateChanged(java.lang.Object element, boolean isDirty)
void
elementMoved(java.lang.Object originalElement, java.lang.Object movedElement)
void
flushDocument(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey, org.eclipse.jface.text.IDocument document, boolean overwrite)
boolean
hasBufferedContents()
Return whether the adapter has buffered contents.boolean
isConnected()
Return whether the element is connected to a shared document.void
releaseBuffer()
Release the buffer if this adapter has buffered the contents in response to aflushDocument(IDocumentProvider, IEditorInput, IDocument, boolean)
.boolean
saveDocument(org.eclipse.ui.IEditorInput input, boolean overwrite, org.eclipse.core.runtime.IProgressMonitor monitor)
Save the shared document of the element of this adapter.
-
-
-
Field Detail
-
connectionCount
private int connectionCount
-
listener
private final EditableSharedDocumentAdapter.SharedDocumentAdapterListener listener
-
bufferedKey
private org.eclipse.ui.IEditorInput bufferedKey
-
-
Constructor Detail
-
EditableSharedDocumentAdapter
public EditableSharedDocumentAdapter(StreamContent content)
Create the shared document adapter for the given element.- Parameters:
listener
- access to element internals
-
-
Method Detail
-
connect
public void connect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey) throws org.eclipse.core.runtime.CoreException
- Specified by:
connect
in interfaceorg.eclipse.compare.ISharedDocumentAdapter
- Overrides:
connect
in classorg.eclipse.compare.SharedDocumentAdapter
- Throws:
org.eclipse.core.runtime.CoreException
-
disconnect
public void disconnect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey)
- Specified by:
disconnect
in interfaceorg.eclipse.compare.ISharedDocumentAdapter
- Overrides:
disconnect
in classorg.eclipse.compare.SharedDocumentAdapter
-
isConnected
public boolean isConnected()
Return whether the element is connected to a shared document.- Returns:
- whether the element is connected to a shared document
-
saveDocument
public boolean saveDocument(org.eclipse.ui.IEditorInput input, boolean overwrite, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Save the shared document of the element of this adapter.- Parameters:
input
- the document key of the element.overwrite
- indicates whether overwrite should be performed while saving the given element if necessarymonitor
- a progress monitor- Returns:
- whether the save succeeded or not
- Throws:
org.eclipse.core.runtime.CoreException
-
releaseBuffer
public void releaseBuffer()
Release the buffer if this adapter has buffered the contents in response to aflushDocument(IDocumentProvider, IEditorInput, IDocument, boolean)
.
-
flushDocument
public void flushDocument(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey, org.eclipse.jface.text.IDocument document, boolean overwrite) throws org.eclipse.core.runtime.CoreException
- Specified by:
flushDocument
in interfaceorg.eclipse.compare.ISharedDocumentAdapter
- Throws:
org.eclipse.core.runtime.CoreException
-
elementContentAboutToBeReplaced
public void elementContentAboutToBeReplaced(java.lang.Object element)
- Specified by:
elementContentAboutToBeReplaced
in interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementContentReplaced
public void elementContentReplaced(java.lang.Object element)
- Specified by:
elementContentReplaced
in interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementDeleted
public void elementDeleted(java.lang.Object element)
- Specified by:
elementDeleted
in interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementDirtyStateChanged
public void elementDirtyStateChanged(java.lang.Object element, boolean isDirty)
- Specified by:
elementDirtyStateChanged
in interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementMoved
public void elementMoved(java.lang.Object originalElement, java.lang.Object movedElement)
- Specified by:
elementMoved
in interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
hasBufferedContents
public boolean hasBufferedContents()
Return whether the adapter has buffered contents. The adapter buffers contents by connecting to the document through the document provider. This means that the adapter must be disconnected either by saving or discarding the buffer.- Returns:
- whether the adapter has buffered contents
-
-