Package org.eclipse.handly.xtext.ui.editor

# Class HandlyXtextEditorCallback

java.lang.Object
org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl
org.eclipse.handly.xtext.ui.editor.HandlyXtextEditorCallback

All Implemented Interfaces:
  `org.eclipse.xtext.ui.editor.IXtextEditorCallback`

public class HandlyXtextEditorCallback extends org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl
Integrates Xtext editor with Handly working copy management facility.

Multiple Xtext editor instances may simultaneously be open for a given source file, each with its own underlying document, but only one of them (the most recently used one) is connected to the source file's working copy.

Note that this class relies on the language-specific implementation of `IInputElementProvider` being available through injection. Also, `HandlyXtextDocument` and other classes pertaining to Handly/Xtext integration should be bound if this callback is configured. For example:

     public Class<? extends IInputElementProvider> bindIInputElementProvider() {
         return FooInputElementProvider.class;
     }

     public void configureXtextEditorCallback(Binder binder) {
         binder.bind(IXtextEditorCallback.class).annotatedWith(Names.named(
             HandlyXtextEditorCallback.class.getName())).to(
                 HandlyXtextEditorCallback.class);
     }

     public Class<? extends XtextDocument> bindXtextDocument() {
         return HandlyXtextDocument.class;
     }

     public Class<? extends IReconciler> bindIReconciler() {
         return HandlyXtextReconciler.class;
     }

     public Class<? extends DirtyStateEditorSupport> bindDirtyStateEditorSupport() {
         return HandlyDirtyStateEditorSupport.class; // or its subclass
     }

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.eclipse.xtext.ui.editor.IXtextEditorCallback

  `org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HandlyXtextEditorCallback()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected ISourceFile`
  `acquireWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  Attempts to acquire a working copy for the corresponding source file of the editor.
  `void`
  `afterCreatePartControl(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  `protected void`
  `afterSelectionChange(org.eclipse.xtext.ui.editor.XtextEditor editor, org.eclipse.jface.viewers.ISelection selection)`
  Notifies that the selection has changed in the editor.
  `void`
  `afterSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  `void`
  `beforeDispose(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  `void`
  `beforeSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  `protected ISourceFile`
  `getSourceFile(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  Returns the corresponding source file for the editor.
  `protected final ISourceFile`
  `getWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor)`
  Returns the working copy that the editor is connected to, or `null` if the editor is not currently connected to a working copy.
  `protected void`
  `releaseWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor, ISourceFile workingCopy)`
  Releases the given working copy that was acquired via a call to `acquireWorkingCopy`.
  `protected void`
  `setHighlightRange(org.eclipse.xtext.ui.editor.XtextEditor editor, org.eclipse.jface.viewers.ISelection selection)`
  Sets the highlighted range of the editor according to the selection.
  `void`
  `setInputElementProvider(IInputElementProvider provider)`

  ### Methods inherited from class org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl

  `afterSave, onValidateEditorInputState`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### HandlyXtextEditorCallback

    public HandlyXtextEditorCallback()

- ## Method Details

  - ### setInputElementProvider

    @Inject public void setInputElementProvider(IInputElementProvider provider)

  - ### afterCreatePartControl

    public void afterCreatePartControl(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Specified by:
      `afterCreatePartControl` in interface `org.eclipse.xtext.ui.editor.IXtextEditorCallback`
    Overrides:
      `afterCreatePartControl` in class `org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl`

  - ### beforeDispose

    public void beforeDispose(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Specified by:
      `beforeDispose` in interface `org.eclipse.xtext.ui.editor.IXtextEditorCallback`
    Overrides:
      `beforeDispose` in class `org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl`

  - ### beforeSetInput

    public void beforeSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Specified by:
      `beforeSetInput` in interface `org.eclipse.xtext.ui.editor.IXtextEditorCallback`
    Overrides:
      `beforeSetInput` in class `org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl`

  - ### afterSetInput

    public void afterSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Specified by:
      `afterSetInput` in interface `org.eclipse.xtext.ui.editor.IXtextEditorCallback`
    Overrides:
      `afterSetInput` in class `org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl`

  - ### afterSelectionChange

    protected void afterSelectionChange(org.eclipse.xtext.ui.editor.XtextEditor editor, org.eclipse.jface.viewers.ISelection selection)
    Notifies that the selection has changed in the editor.

    This implementation invokes `setHighlightRange(editor, selection)` if the selection is not `null`.

    Parameters:
      `editor` - never `null`
      `selection` - may be `null` or empty

  - ### setHighlightRange

    protected void setHighlightRange(org.eclipse.xtext.ui.editor.XtextEditor editor, org.eclipse.jface.viewers.ISelection selection)
    Sets the highlighted range of the editor according to the selection.

    This implementation schedules a background job to set the highlight range asynchronously.

    Parameters:
      `editor` - never `null`
      `selection` - never `null`

  - ### getSourceFile

    protected ISourceFile getSourceFile(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Returns the corresponding source file for the editor.

    This implementation uses the injected `IInputElementProvider` to obtain an `IElement` corresponding to the editor input and returns the `IElement` if it is an `ISourceFile`.

    Parameters:
      `editor` - never `null`
    Returns:
      the corresponding source file, or `null` if none

  - ### getWorkingCopy

    protected final ISourceFile getWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor)
    Returns the working copy that the editor is connected to, or `null` if the editor is not currently connected to a working copy.

    Note that multiple Xtext editor instances may simultaneously be open for a given source file, each with its own underlying document, but only one of them (the most recently used one) is connected to the source file's working copy.

    Parameters:
      `editor` - never `null`
    Returns:
      the working copy that the editor is connected to, or `null` if the editor is not currently connected to a working copy

  - ### acquireWorkingCopy

    protected ISourceFile acquireWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor) throws org.eclipse.core.runtime.CoreException
    Attempts to acquire a working copy for the corresponding source file of the editor. A working copy acquired by this method must be released eventually via a call to `releaseWorkingCopy`.

    This implementation obtains the corresponding source file for the editor via `getSourceFile(XtextEditor)` and, if the source file implements `ISourceFileImplExtension`, invokes `becomeWorkingCopy_` on it providing a working copy buffer backed by the editor and an Xtext-specific working copy callback, and returns the acquired working copy. Otherwise, `null` is returned.

    Parameters:
      `editor` - never `null`
    Returns:
      the acquired working copy, or `null` if no working copy can be acquired
    Throws:
      `org.eclipse.core.runtime.CoreException` - if the working copy could not be acquired successfully

  - ### releaseWorkingCopy

    protected void releaseWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor, ISourceFile workingCopy)
    Releases the given working copy that was acquired via a call to `acquireWorkingCopy`.

    This implementation invokes `((ISourceFileImplExtension)workingCopy).`releaseWorkingCopy_()``.

    Parameters:
      `editor` - never `null`
      `workingCopy` - never `null`