Class AbstractGotoEventHandlerHandler<T extends org.eclipse.emf.ecore.EObject>

  • Type Parameters:
    T - event owner class
    All Implemented Interfaces:
    org.eclipse.core.commands.IHandler, org.eclipse.core.commands.IHandler2
    Direct Known Subclasses:
    GotoCommandEventHandlerHandler, GotoEventHandlerHandler

    public abstract class AbstractGotoEventHandlerHandler<T extends org.eclipse.emf.ecore.EObject>
    extends org.eclipse.core.commands.AbstractHandler
    Abstract implementation of handler that checks existence of selected form element event handler and then selects and reveals it. If event handler does not exists, handler performs event handler creation.

    Subclasses must implement:

    1. How to extract event owner from selected form element.
    2. How to get and set event handler to it.
    3. How to generate handler name.

    Form model EObject element selection is expected for handler execution.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Object execute​(org.eclipse.core.commands.ExecutionEvent event)  
      protected abstract T extractEventOwner​(org.eclipse.emf.ecore.EObject element, Form form, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Extracts event owner from given form element.
      protected abstract String generateEventHandlerName​(T eventOwner, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Generates eventOwner event handler name.
      protected abstract Event getCreatingEvent​(org.eclipse.emf.ecore.EObject eventOwner, org.eclipse.core.commands.ExecutionEvent executionEvent, String handlerName)
      Gets event for handler creation.
      protected IBmEditingContext getEditingContext​(ISelection selection, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent event)
      Returns the BM editing context from the provided to handler selection and execution event.
      protected abstract String getEventHandlerName​(T eventOwner, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Returns eventOwner event handler name.
      protected Form getForm​(org.eclipse.emf.ecore.EObject element)
      Returns owner form of the provided form element.
      protected String getProcedureDirective​(org.eclipse.swt.widgets.Shell shell, boolean isRussian, T eventOwner, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Returns procedure directive for chosen event, or empty string if there is no procedure for creating event handler.
      protected boolean isAllowedServerCall​(T eventOwner, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Returns whether creating event handler server call is allowed.
      protected boolean isCommandHandler()
      Returns whether creating event handler is command handler.
      protected boolean isMainItem​(T eventOwner, org.eclipse.emf.ecore.EObject element)
      Returns whether creating event handler is for main item.
      protected String openOrCreateEventHandler​(org.eclipse.xtext.ui.editor.XtextEditor editor, T eventOwner, org.eclipse.emf.ecore.EObject element, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Navigates to event handler in form BSL module editor or create it before navigation.
      protected void selectAndReveal​(org.eclipse.jface.text.ITextSelection selection, org.eclipse.jface.text.ITextViewer viewer)
      Selects and reveals the provided text selection on the provided text viewer.
      protected abstract void setEventHandler​(T eventOwner, String eventHandlerName, org.eclipse.core.commands.ExecutionEvent executionEvent)
      Sets eventOwner event handler.
      protected boolean shouldCreateEvent​(org.eclipse.swt.widgets.Shell shell, String eventHandlerName)
      Returns whether need to create event.
      • Methods inherited from class org.eclipse.core.commands.AbstractHandler

        addHandlerListener, dispose, fireHandlerChanged, hasListeners, isEnabled, isHandled, removeHandlerListener, setBaseEnabled, setEnabled
      • Methods inherited from class org.eclipse.core.commands.common.EventManager

        addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
    • Constructor Detail

      • AbstractGotoEventHandlerHandler

        public AbstractGotoEventHandlerHandler()
    • Method Detail

      • execute

        public Object execute​(org.eclipse.core.commands.ExecutionEvent event)
                       throws org.eclipse.core.commands.ExecutionException
        Throws:
        org.eclipse.core.commands.ExecutionException
      • openOrCreateEventHandler

        protected String openOrCreateEventHandler​(org.eclipse.xtext.ui.editor.XtextEditor editor,
                                                  T eventOwner,
                                                  org.eclipse.emf.ecore.EObject element,
                                                  org.eclipse.core.commands.ExecutionEvent executionEvent)
        Navigates to event handler in form BSL module editor or create it before navigation. Returns handler name if handler was created during execution or null otherwise
        Parameters:
        editor - the target Xtext editor to use for navigation, cannot be null
        eventOwner - the owner of event, cannot be null
        element - the currently selected form element, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        a handler name if handler was created during execution or null otherwise
      • getEditingContext

        protected IBmEditingContext getEditingContext​(ISelection selection,
                                                      org.eclipse.emf.ecore.EObject element,
                                                      org.eclipse.core.commands.ExecutionEvent event)
        Returns the BM editing context from the provided to handler selection and execution event.
        Parameters:
        selection - the provided to handler selection, cannot be null
        element - the selected form element, cannot be null
        event - the provided to handler execution event, cannot be null
        Returns:
        the BM editing context or null if none
      • getForm

        protected Form getForm​(org.eclipse.emf.ecore.EObject element)
        Returns owner form of the provided form element.
        Parameters:
        element - the selection element to get form for, cannot be null
        Returns:
        the owner form, never null
      • getProcedureDirective

        protected String getProcedureDirective​(org.eclipse.swt.widgets.Shell shell,
                                               boolean isRussian,
                                               T eventOwner,
                                               org.eclipse.emf.ecore.EObject element,
                                               org.eclipse.core.commands.ExecutionEvent executionEvent)
        Returns procedure directive for chosen event, or empty string if there is no procedure for creating event handler.

        Can return null if user cancelled event handler creation.

        Parameters:
        shell - the parent shell to open question dialog on, cannot be null
        isRussian - true if actual script variant is russian, false otherwise
        eventOwner - the owner of event, cannot be null
        element - the currently selected form element, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        the procedure directive for chosen event, or empty string if there is no procedure for chosen event, or null if user cancelled event handler creation
      • shouldCreateEvent

        protected boolean shouldCreateEvent​(org.eclipse.swt.widgets.Shell shell,
                                            String eventHandlerName)
        Returns whether need to create event. Default impelementation returns true, subclass may customize.
        Parameters:
        shell - the parent shell to use for user interaction actions, cannot be null
        eventHandlerName - the event handler name, cannot be null
        Returns:
        whether need to create event
      • selectAndReveal

        protected void selectAndReveal​(org.eclipse.jface.text.ITextSelection selection,
                                       org.eclipse.jface.text.ITextViewer viewer)
        Selects and reveals the provided text selection on the provided text viewer.
        Parameters:
        selection - the text selection to reveal, cannot be null
        viewer - the target text viewer, cannot be null
      • isCommandHandler

        protected boolean isCommandHandler()
        Returns whether creating event handler is command handler.
        Returns:
        whether creating event handler is command handler
      • isMainItem

        protected boolean isMainItem​(T eventOwner,
                                     org.eclipse.emf.ecore.EObject element)
        Returns whether creating event handler is for main item.
        Parameters:
        eventOwner - the owner of event, cannot be null
        element - the form element to extract event owner from, cannot be null
        Returns:
        whether creating event handler is for main item
      • isAllowedServerCall

        protected boolean isAllowedServerCall​(T eventOwner,
                                              org.eclipse.emf.ecore.EObject element,
                                              org.eclipse.core.commands.ExecutionEvent executionEvent)
        Returns whether creating event handler server call is allowed.
        Parameters:
        eventOwner - the owner of event, cannot be null
        element - the currently selected form element, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        whether creating event handler server call is allowed
      • getCreatingEvent

        protected abstract Event getCreatingEvent​(org.eclipse.emf.ecore.EObject eventOwner,
                                                  org.eclipse.core.commands.ExecutionEvent executionEvent,
                                                  String handlerName)
        Gets event for handler creation.
        Parameters:
        eventOwner - the owner of event, cannot be null
        executionEvent - the current execution event, cannot be null
        handlerName - the event handler name to create event with, cannot be null
        Returns:
        creating event, never null
      • extractEventOwner

        protected abstract T extractEventOwner​(org.eclipse.emf.ecore.EObject element,
                                               Form form,
                                               org.eclipse.core.commands.ExecutionEvent executionEvent)
        Extracts event owner from given form element.
        Parameters:
        element - the form element to extract event owner from, cannot be null
        form - the owner form, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        the event owner, never null
      • getEventHandlerName

        protected abstract String getEventHandlerName​(T eventOwner,
                                                      org.eclipse.emf.ecore.EObject element,
                                                      org.eclipse.core.commands.ExecutionEvent executionEvent)
        Returns eventOwner event handler name. Can return null if not provided.
        Parameters:
        eventOwner - the owner of event, cannot be null
        element - the currently selected form element, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        the existing event handler name or null if none
      • generateEventHandlerName

        protected abstract String generateEventHandlerName​(T eventOwner,
                                                           org.eclipse.emf.ecore.EObject element,
                                                           org.eclipse.core.commands.ExecutionEvent executionEvent)
        Generates eventOwner event handler name.
        Parameters:
        eventOwner - the owner of event, cannot be null
        element - the currently selected form element, cannot be null
        executionEvent - the current execution event, cannot be null
        Returns:
        generated event handler name, never null
      • setEventHandler

        protected abstract void setEventHandler​(T eventOwner,
                                                String eventHandlerName,
                                                org.eclipse.core.commands.ExecutionEvent executionEvent)
        Sets eventOwner event handler.
        Parameters:
        eventOwner - the owner of event, cannot be null
        eventHandlerName - the event handler name to set, cannot be null
        executionEvent - the current execution event, cannot be null