Class 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 (see hasBufferedContents()). In order to avoid a leak, the buffer must either be saved (see saveDocument(IEditorInput, boolean, IProgressMonitor)) or released (see releaseBuffer()).

    This adapter must have a one-to-one correspondence to a typed element.

    • 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 interface org.eclipse.compare.ISharedDocumentAdapter
        Overrides:
        connect in class org.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 interface org.eclipse.compare.ISharedDocumentAdapter
        Overrides:
        disconnect in class org.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 necessary
        monitor - a progress monitor
        Returns:
        whether the save succeeded or not
        Throws:
        org.eclipse.core.runtime.CoreException
      • 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 interface org.eclipse.compare.ISharedDocumentAdapter
        Throws:
        org.eclipse.core.runtime.CoreException
      • elementContentAboutToBeReplaced

        public void elementContentAboutToBeReplaced​(java.lang.Object element)
        Specified by:
        elementContentAboutToBeReplaced in interface org.eclipse.ui.texteditor.IElementStateListener
      • elementContentReplaced

        public void elementContentReplaced​(java.lang.Object element)
        Specified by:
        elementContentReplaced in interface org.eclipse.ui.texteditor.IElementStateListener
      • elementDeleted

        public void elementDeleted​(java.lang.Object element)
        Specified by:
        elementDeleted in interface org.eclipse.ui.texteditor.IElementStateListener
      • elementDirtyStateChanged

        public void elementDirtyStateChanged​(java.lang.Object element,
                                             boolean isDirty)
        Specified by:
        elementDirtyStateChanged in interface org.eclipse.ui.texteditor.IElementStateListener
      • elementMoved

        public void elementMoved​(java.lang.Object originalElement,
                                 java.lang.Object movedElement)
        Specified by:
        elementMoved in interface org.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