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.IElementStateListenerA 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 classEditableSharedDocumentAdapter.SharedDocumentAdapterListenerInterface 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.IEditorInputbufferedKeyprivate intconnectionCountprivate EditableSharedDocumentAdapter.SharedDocumentAdapterListenerlistener
-
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 voidconnect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey)voiddisconnect(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey)voidelementContentAboutToBeReplaced(java.lang.Object element)voidelementContentReplaced(java.lang.Object element)voidelementDeleted(java.lang.Object element)voidelementDirtyStateChanged(java.lang.Object element, boolean isDirty)voidelementMoved(java.lang.Object originalElement, java.lang.Object movedElement)voidflushDocument(org.eclipse.ui.texteditor.IDocumentProvider provider, org.eclipse.ui.IEditorInput documentKey, org.eclipse.jface.text.IDocument document, boolean overwrite)booleanhasBufferedContents()Return whether the adapter has buffered contents.booleanisConnected()Return whether the element is connected to a shared document.voidreleaseBuffer()Release the buffer if this adapter has buffered the contents in response to aflushDocument(IDocumentProvider, IEditorInput, IDocument, boolean).booleansaveDocument(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:
connectin interfaceorg.eclipse.compare.ISharedDocumentAdapter- Overrides:
connectin 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:
disconnectin interfaceorg.eclipse.compare.ISharedDocumentAdapter- Overrides:
disconnectin 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.CoreExceptionSave 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:
flushDocumentin interfaceorg.eclipse.compare.ISharedDocumentAdapter- Throws:
org.eclipse.core.runtime.CoreException
-
elementContentAboutToBeReplaced
public void elementContentAboutToBeReplaced(java.lang.Object element)
- Specified by:
elementContentAboutToBeReplacedin interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementContentReplaced
public void elementContentReplaced(java.lang.Object element)
- Specified by:
elementContentReplacedin interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementDeleted
public void elementDeleted(java.lang.Object element)
- Specified by:
elementDeletedin interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementDirtyStateChanged
public void elementDirtyStateChanged(java.lang.Object element, boolean isDirty)- Specified by:
elementDirtyStateChangedin interfaceorg.eclipse.ui.texteditor.IElementStateListener
-
elementMoved
public void elementMoved(java.lang.Object originalElement, java.lang.Object movedElement)- Specified by:
elementMovedin 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
-
-