Class WidgetBindingImpl<C extends Command,​I extends InteractionImpl<D,​?,​?>,​D extends InteractionData>

  • Type Parameters:
    C - The type of the command that will produce this widget binding.
    I - The type of the interaction that will use this widget binding.
    All Implemented Interfaces:
    WidgetBinding<C>, FSMHandler

    public abstract class WidgetBindingImpl<C extends Command,​I extends InteractionImpl<D,​?,​?>,​D extends InteractionData>
    extends Object
    implements WidgetBinding<C>
    The base class to do widget bindings, i.e. bindings between user interactions and (undoable) commands.
    Author:
    Arnaud BLOUIN
    • Field Detail

      • loggerBinding

        protected Logger loggerBinding
      • loggerCmd

        protected Logger loggerCmd
      • activated

        protected boolean activated
      • interaction

        protected final I extends InteractionImpl<D,​?,​?> interaction
        The source interaction.
      • cmd

        protected C extends Command cmd
        The current command in progress.
      • continuousCmdExec

        protected final boolean continuousCmdExec
        Specifies whether the command must be executed on each step of the interaction.
      • async

        protected boolean async
        Defines whether the command must be executed in a specific thread.
      • cmdsProduced

        protected final io.reactivex.subjects.PublishSubject<C extends Command> cmdsProduced
    • Constructor Detail

      • WidgetBindingImpl

        public WidgetBindingImpl​(boolean continuousExecution,
                                 Function<D,​C> cmdCreation,
                                 I interaction)
        Creates a widget binding.
        Parameters:
        continuousExecution - Specifies whether the command must be executed on each step of the interaction.
        cmdCreation - The type of the command that will be created. Used to instantiate the cmd by reflexivity. The class must be public and must have a constructor with no parameter.
        interaction - The user interaction of the binding.
        Throws:
        IllegalArgumentException - If the given interaction or instrument is null.
    • Method Detail

      • setLogger

        public static void setLogger​(Logger logger)
        Sets the logger to use. Cannot be null. Does not change the loggers of existing widget bindings. This also sets this logger as the default logger for user interactions.
        Parameters:
        logger - The new logger to use.
      • logBinding

        public void logBinding​(boolean log)
      • logCmd

        public void logCmd​(boolean log)
      • logInteraction

        public void logInteraction​(boolean log)
      • isAsync

        public boolean isAsync()
        Whether the command must be executed in a specific thread.
        Returns:
        True: the command will be executed asynchronously.
      • setAsync

        public void setAsync​(boolean asyncCmd)
        Sets whether the command must be executed in a specific thread.
        Parameters:
        asyncCmd - True: the command will be executed asynchronously.
      • clearEvents

        public void clearEvents()
        Description copied from interface: WidgetBinding
        Stops the interaction and clears all its events waiting for a process.
        Specified by:
        clearEvents in interface WidgetBinding<C extends Command>
      • createCommand

        protected C createCommand()
        creates the command of the widget binding. If the attribute 'cmd' is not null, nothing will be done.
        Returns:
        The created command or null if problems occurred.
      • first

        public void first()
        Description copied from interface: WidgetBinding
        After being created by createCommand, the command can be initialised by this method.
        Specified by:
        first in interface WidgetBinding<C extends Command>
      • when

        public abstract boolean when()
        Specified by:
        when in interface WidgetBinding<C extends Command>
        Returns:
        True if the condition of the widget binding is respected.
      • isActivated

        public boolean isActivated()
        Specified by:
        isActivated in interface WidgetBinding<C extends Command>
        Returns:
        True if the widget binding is activated.
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface WidgetBinding<C extends Command>
        Returns:
        True: if the widget binding is currently used.
      • isStrictStart

        public boolean isStrictStart()
        Description copied from interface: WidgetBinding
        States whether the interaction must continue to run while the condition of the binding is not fulfilled at the interaction start.
        Specified by:
        isStrictStart in interface WidgetBinding<C extends Command>
      • unbindCmdAttributes

        protected abstract void unbindCmdAttributes()
        Manages to automatically unbind commands' attributes tagged with AutoUnbind
      • fsmCancels

        public void fsmCancels()
        Description copied from interface: FSMHandler
        When the interaction enters a cancelling state.
        Specified by:
        fsmCancels in interface FSMHandler
      • fsmUpdates

        public void fsmUpdates()
        Description copied from interface: FSMHandler
        When the FSM runs to new state.
        Specified by:
        fsmUpdates in interface FSMHandler
      • fsmStops

        public void fsmStops()
        Description copied from interface: FSMHandler
        When the FSM enters a terminal state.
        Specified by:
        fsmStops in interface FSMHandler
      • createAndInitCommand

        protected boolean createAndInitCommand()
      • executeCmdAsync

        protected abstract void executeCmdAsync​(Command cmd)
      • afterCmdExecuted

        protected void afterCmdExecuted​(C cmd,
                                        boolean ok)
      • isContinuousCmdExec

        public boolean isContinuousCmdExec()
        Specified by:
        isContinuousCmdExec in interface WidgetBinding<C extends Command>
        Returns:
        True: the command must be executed on each step of the interaction.
      • setActivated

        public void setActivated​(boolean activated)
        Description copied from interface: WidgetBinding
        Activates the widget binding.
        Specified by:
        setActivated in interface WidgetBinding<C extends Command>
        Parameters:
        activated - True: the widget binding is activated. Otherwise, it is desactivated.
      • produces

        public io.reactivex.Observable<C> produces()
        Description copied from interface: WidgetBinding
        An RX observable objects that will provide the commands produced by the binding.
        Specified by:
        produces in interface WidgetBinding<C extends Command>