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 }
-
-
Constructor Summary
Constructors Constructor Description HandlyXtextEditorCallback()
-
Method Summary
All Methods Instance Methods Concrete Methods 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 ISourceFile
getWorkingCopy(org.eclipse.xtext.ui.editor.XtextEditor editor)
Returns the working copy that the editor is connected to, ornull
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 toacquireWorkingCopy
.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)
-
-
-
Method Detail
-
setInputElementProvider
@Inject public void setInputElementProvider(IInputElementProvider provider)
-
afterCreatePartControl
public void afterCreatePartControl(org.eclipse.xtext.ui.editor.XtextEditor editor)
- Specified by:
afterCreatePartControl
in interfaceorg.eclipse.xtext.ui.editor.IXtextEditorCallback
- Overrides:
afterCreatePartControl
in classorg.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl
-
beforeDispose
public void beforeDispose(org.eclipse.xtext.ui.editor.XtextEditor editor)
- Specified by:
beforeDispose
in interfaceorg.eclipse.xtext.ui.editor.IXtextEditorCallback
- Overrides:
beforeDispose
in classorg.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl
-
beforeSetInput
public void beforeSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)
- Specified by:
beforeSetInput
in interfaceorg.eclipse.xtext.ui.editor.IXtextEditorCallback
- Overrides:
beforeSetInput
in classorg.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl
-
afterSetInput
public void afterSetInput(org.eclipse.xtext.ui.editor.XtextEditor editor)
- Specified by:
afterSetInput
in interfaceorg.eclipse.xtext.ui.editor.IXtextEditorCallback
- Overrides:
afterSetInput
in classorg.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 notnull
.- Parameters:
editor
- nevernull
selection
- may benull
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
- nevernull
selection
- nevernull
-
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 anIElement
corresponding to the editor input and returns theIElement
if it is anISourceFile
.- Parameters:
editor
- nevernull
- 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, ornull
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
- nevernull
- 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 toreleaseWorkingCopy
.This implementation obtains the corresponding source file for the editor via
getSourceFile(XtextEditor)
and, if the source file implementsISourceFileImplExtension
, invokesbecomeWorkingCopy_
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
- nevernull
- 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 toacquireWorkingCopy
.This implementation invokes
((ISourceFileImplExtension)workingCopy).
.releaseWorkingCopy_()
- Parameters:
editor
- nevernull
workingCopy
- nevernull
-
-