Class CustomXtextEditorCallback
- java.lang.Object
-
- org.eclipse.xtext.ui.editor.CompoundXtextEditorCallback
-
- net.ssehub.easy.dslCore.ui.editors.CustomXtextEditorCallback
-
- All Implemented Interfaces:
org.eclipse.xtext.ui.editor.IXtextEditorCallback
public class CustomXtextEditorCallback extends org.eclipse.xtext.ui.editor.CompoundXtextEditorCallbackImplements a custom CompoundXtextEditorCallback which can be registered to a XtextEditor in oder to react on key events. In particular, this class is designed to enable the "Jump-to-definition" feature if the key F3 is pressed. However, other custom key bindings can be defined here as wells.- Author:
- kroeher
-
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.xtext.ui.editor.model.IXtextDocumenteditorDocumentprivate CommonXtextEditorxtextEditor
-
Constructor Summary
Constructors Constructor Description CustomXtextEditorCallback(com.google.inject.Injector injector)The constructor of a custom CompoundXtextEditorCallback.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddKeyListener(org.eclipse.xtext.ui.editor.XtextEditor editor)Sets up this CompoundXtextEditorCallback by creating a new KeyListener which will be add to the text widget of the given XtextEditor.voidafterCreatePartControl(org.eclipse.xtext.ui.editor.XtextEditor editor)private java.lang.StringgetSelectedElement()Returns the name of the selected element in the editor as String by calling getSelectedElementBySelection.private java.lang.StringgetSelectedElementByOffset()Returns the name of the element around the current position of the cursor in the document (defined by the offset of the current text-selection) of the XtextEditor.private java.lang.StringgetSelectedElementBySelection()Returns the name of the selected element in the editor as String.private voidgotoElementDefinition()This method is called if F3-key is released.private booleanisValidElementCharacter(char elementNameChar)Checks whether a given character is a valid character in the sense of its usage as part of a name of an IVML/VIL/VTL element.private booleanselectionAvailable()Checks whether an ISelection-instance is available.private booleansetCursorToDefinition(java.lang.String selectedElement, org.eclipse.xtext.ui.editor.model.IXtextDocument xtextDocument, org.eclipse.xtext.ui.editor.XtextEditor documentEditor)Sets the focus of the cursor in the given editor to the definition of the selected element in the given document.
-
-
-
Field Detail
-
xtextEditor
private CommonXtextEditor xtextEditor
-
editorDocument
private org.eclipse.xtext.ui.editor.model.IXtextDocument editorDocument
-
-
Method Detail
-
afterCreatePartControl
public void afterCreatePartControl(org.eclipse.xtext.ui.editor.XtextEditor editor)
- Specified by:
afterCreatePartControlin interfaceorg.eclipse.xtext.ui.editor.IXtextEditorCallback- Overrides:
afterCreatePartControlin classorg.eclipse.xtext.ui.editor.CompoundXtextEditorCallback
-
addKeyListener
private void addKeyListener(org.eclipse.xtext.ui.editor.XtextEditor editor)
Sets up this CompoundXtextEditorCallback by creating a new KeyListener which will be add to the text widget of the given XtextEditor.- Parameters:
editor- the XtextEditor to which the KeyListener should be added
-
gotoElementDefinition
private void gotoElementDefinition()
This method is called if F3-key is released. It identifies the selected language element, tries to find the corresponding definition of this element and, if found, sets the focus of the cursor to that definition.
-
setCursorToDefinition
private boolean setCursorToDefinition(java.lang.String selectedElement, org.eclipse.xtext.ui.editor.model.IXtextDocument xtextDocument, org.eclipse.xtext.ui.editor.XtextEditor documentEditor)Sets the focus of the cursor in the given editor to the definition of the selected element in the given document.- Parameters:
selectedElement- the selected element for which the definition has to be found in order to set the focus of the cursor to that definitionxtextDocument- the document in which the definition has to be founddocumentEditor- the editor in which the focus of the editor has to be set- Returns:
trueif setting the focus of the editor was successful.Falseotherwise.
-
getSelectedElement
private java.lang.String getSelectedElement()
Returns the name of the selected element in the editor as String by calling getSelectedElementBySelection. If no element is selected, the name of the element around the current position of the cursor will be returned by calling getSelectedElementByOffset.- Returns:
- the name of the selected element in the editor or the element around the
current position of the cursor. May be
null.
-
getSelectedElementBySelection
private java.lang.String getSelectedElementBySelection()
Returns the name of the selected element in the editor as String.- Returns:
- the name of the selected element in the editor. May be
null.
-
getSelectedElementByOffset
private java.lang.String getSelectedElementByOffset()
Returns the name of the element around the current position of the cursor in the document (defined by the offset of the current text-selection) of the XtextEditor.- Returns:
- the name of the element around the current position of the cursor or
nullif no element could be found.
-
isValidElementCharacter
private boolean isValidElementCharacter(char elementNameChar)
Checks whether a given character is a valid character in the sense of its usage as part of a name of an IVML/VIL/VTL element.- Parameters:
elementNameChar- the character that has the be checked for validity- Returns:
trueif the character is alphabetic, a digit, or an underscore.Falseotherwise.
-
selectionAvailable
private boolean selectionAvailable()
Checks whether an ISelection-instance is available. However, the availability of such an instance does not mean that a specific part of the text in the editor is selected. It just ensures that an instance for checking such a selection is available and, thus, should prevent from producing NPEs.- Returns:
trueif an ISelection-instance is available.Falseotherwise.
-
-