Package org.eclipse.handly.ui

# Interface IWorkingCopyManager

All Known Implementing Classes:
  `SourceFileDocumentProvider`

public interface IWorkingCopyManager

Manages the life-cycle of and provides access to working copies of source files. A typical usage pattern is as follows:

      final IWorkingCopyManager manager = ...;
      final IEditorInput input = ...;

      manager.connect(input);
      try {
          ISourceFile workingCopy = manager.getWorkingCopy(input);
          // workingCopy must not be null at this point
          ...
      }
      finally {
          manager.disconnect(input);
      }

Implementations are generally not expected to be thread-safe and, if not mentioned otherwise, may only be called from the user-interface thread.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `connect(Object element)`
  Connects the given element to this manager.
  `void`
  `disconnect(Object element)`
  Disconnects the given element from this manager.
  `ISourceFile[]`
  `getWorkingCopies()`
  Returns all working copies that are currently managed by this manager.
  `ISourceFile`
  `getWorkingCopy(Object element)`
  Returns the working copy managed for the given element, or `null` if this manager does not currently manage a working copy for the element.
  `ISourceFile`
  `getWorkingCopy(org.eclipse.jface.text.IDocument document)`
  Returns the working copy managed for the given document, or `null` if this manager does not currently manage a working copy for the document.

- ## Method Details

  - ### connect

    void connect(Object element) throws org.eclipse.core.runtime.CoreException
    Connects the given element to this manager. Attempts to acquire a working copy for the given element. Each successful call to this method must ultimately be followed by exactly one matching call to `disconnect(Object)`.
    Parameters:
      `element` - not `null`
    Throws:
      `org.eclipse.core.runtime.CoreException` - if the working copy could not be acquired

  - ### disconnect

    void disconnect(Object element)
    Disconnects the given element from this manager. Releases the working copy acquired on `connect(Object)`.
    Parameters:
      `element` - not `null`

  - ### getWorkingCopy

    ISourceFile getWorkingCopy(Object element)
    Returns the working copy managed for the given element, or `null` if this manager does not currently manage a working copy for the element.
    Parameters:
      `element` - the element for which to find the working copy, or `null`
    Returns:
      the working copy managed for the given element, or `null` if none

  - ### getWorkingCopy

    ISourceFile getWorkingCopy(org.eclipse.jface.text.IDocument document)
    Returns the working copy managed for the given document, or `null` if this manager does not currently manage a working copy for the document.

    Note: An implementation of this method may go through the list of working copies and test whether the working copy buffer's document equals the given document. Therefore, this method should not be used in performance critical code.

    Parameters:
      `document` - the document for which to find the working copy, or `null`
    Returns:
      the working copy managed for the given document, or `null` if none

  - ### getWorkingCopies

    ISourceFile[] getWorkingCopies()
    Returns all working copies that are currently managed by this manager.
    Returns:
      the working copies currently managed by this manager (never `null`)