Module interacto.java.api
Package io.github.interacto.binding
Class WidgetBindingImpl<C extends Command,I extends InteractionImpl<D,?,?>,D extends InteractionData>
- java.lang.Object
-
- io.github.interacto.binding.WidgetBindingImpl<C,I,D>
-
- 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 Summary
Fields Modifier and Type Field Description protected booleanactivatedprotected booleanasyncDefines whether the command must be executed in a specific thread.protected CcmdThe current command in progress.protected Function<D,C>cmdProducerA function that produces commands.protected io.reactivex.subjects.PublishSubject<C>cmdsProducedprotected booleancontinuousCmdExecSpecifies whether the command must be executed on each step of the interaction.protected IinteractionThe source interaction.protected LoggerloggerBindingprotected LoggerloggerCmdprotected longtimeCancelledprotected longtimeEnded
-
Constructor Summary
Constructors Constructor Description WidgetBindingImpl(boolean continuousExecution, Function<D,C> cmdCreation, I interaction)Creates a widget binding.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterCmdExecuted(C cmd, boolean ok)voidcancel()On cancellationvoidclearEvents()Stops the interaction and clears all its events waiting for a process.protected booleancreateAndInitCommand()protected CcreateCommand()creates the command of the widget binding.voidend()On endvoidendOrCancel()On end or cancellationprotected abstract voidexecuteCmdAsync(Command cmd)voidfirst()After being created by createCommand, the command can be initialised by this method.voidfsmCancels()When the interaction enters a cancelling state.voidfsmStarts()When the FSM starts.voidfsmStops()When the FSM enters a terminal state.voidfsmUpdates()When the FSM runs to new state.CgetCommand()IgetInteraction()static LoggergetLogger()longgetTimesCancelled()Information method.longgetTimesEnded()Information method.voidifCannotExecuteCmd()Called when an ongoing command cannot be executedvoidifCmdHadEffects()Called when an executed command had effectsvoidifCmdHadNoEffect()Called when an executed command did not had effectbooleanisActivated()booleanisAsync()Whether the command must be executed in a specific thread.booleanisContinuousCmdExec()booleanisRunning()booleanisStrictStart()voidlogBinding(boolean log)Logs information related to the binding.voidlogCmd(boolean log)Logs information related to the command creation.voidlogInteraction(boolean log)Logs information related to the user interaction.io.reactivex.Observable<C>produces()voidsetActivated(boolean activated)Activates the widget binding.voidsetAsync(boolean asyncCmd)Sets whether the command must be executed in a specific thread.static voidsetLogger(Logger logger)Sets the logger to use.voidthen()Updates the current command.protected abstract voidunbindCmdAttributes()Manages to automatically unbind commands' attributes tagged with AutoUnbindvoiduninstallBinding()Uninstall the binding.abstract booleanwhen()
-
-
-
Field Detail
-
timeEnded
protected long timeEnded
-
timeCancelled
protected long timeCancelled
-
loggerBinding
protected Logger loggerBinding
-
loggerCmd
protected Logger loggerCmd
-
activated
protected boolean activated
-
interaction
protected final I extends InteractionImpl<D,?,?> interaction
The source interaction.
-
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.
-
cmdProducer
protected final Function<D extends InteractionData,C extends Command> cmdProducer
A function that produces commands.
-
-
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.
-
getLogger
public static Logger getLogger()
- Returns:
- The global logger. Cannot be null.
-
logBinding
public void logBinding(boolean log)
Logs information related to the binding.- Parameters:
log- True: information will be logged
-
logCmd
public void logCmd(boolean log)
Logs information related to the command creation.- Parameters:
log- True: information related to the command creation will be logged
-
logInteraction
public void logInteraction(boolean log)
Logs information related to the user interaction.- Parameters:
log- True: information related to the user interaction will be logged
-
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:WidgetBindingStops the interaction and clears all its events waiting for a process.- Specified by:
clearEventsin interfaceWidgetBinding<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:WidgetBindingAfter being created by createCommand, the command can be initialised by this method.- Specified by:
firstin interfaceWidgetBinding<C extends Command>
-
then
public void then()
Description copied from interface:WidgetBindingUpdates the current command. To override.- Specified by:
thenin interfaceWidgetBinding<C extends Command>
-
end
public void end()
Description copied from interface:WidgetBindingOn end- Specified by:
endin interfaceWidgetBinding<C extends Command>
-
cancel
public void cancel()
Description copied from interface:WidgetBindingOn cancellation- Specified by:
cancelin interfaceWidgetBinding<C extends Command>
-
endOrCancel
public void endOrCancel()
Description copied from interface:WidgetBindingOn end or cancellation- Specified by:
endOrCancelin interfaceWidgetBinding<C extends Command>
-
ifCmdHadNoEffect
public void ifCmdHadNoEffect()
Description copied from interface:WidgetBindingCalled when an executed command did not had effect- Specified by:
ifCmdHadNoEffectin interfaceWidgetBinding<C extends Command>
-
ifCmdHadEffects
public void ifCmdHadEffects()
Description copied from interface:WidgetBindingCalled when an executed command had effects- Specified by:
ifCmdHadEffectsin interfaceWidgetBinding<C extends Command>
-
ifCannotExecuteCmd
public void ifCannotExecuteCmd()
Description copied from interface:WidgetBindingCalled when an ongoing command cannot be executed- Specified by:
ifCannotExecuteCmdin interfaceWidgetBinding<C extends Command>
-
when
public abstract boolean when()
- Specified by:
whenin interfaceWidgetBinding<C extends Command>- Returns:
- True if the condition of the widget binding is respected.
-
getInteraction
public I getInteraction()
- Specified by:
getInteractionin interfaceWidgetBinding<C extends Command>- Returns:
- The interaction.
-
getCommand
public C getCommand()
- Specified by:
getCommandin interfaceWidgetBinding<C extends Command>- Returns:
- The command in progress or null.
-
isActivated
public boolean isActivated()
- Specified by:
isActivatedin interfaceWidgetBinding<C extends Command>- Returns:
- True if the widget binding is activated.
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceWidgetBinding<C extends Command>- Returns:
- True: if the widget binding is currently used.
-
isStrictStart
public boolean isStrictStart()
- Specified by:
isStrictStartin interfaceWidgetBinding<C extends Command>- Returns:
- States whether the interaction must continue to run while the condition of the binding is not fulfilled at the interaction start.
-
unbindCmdAttributes
protected abstract void unbindCmdAttributes()
Manages to automatically unbind commands' attributes tagged with AutoUnbind
-
fsmCancels
public void fsmCancels()
Description copied from interface:FSMHandlerWhen the interaction enters a cancelling state.- Specified by:
fsmCancelsin interfaceFSMHandler
-
fsmStarts
public void fsmStarts() throws CancelFSMExceptionDescription copied from interface:FSMHandlerWhen the FSM starts.- Specified by:
fsmStartsin interfaceFSMHandler- Throws:
CancelFSMException- If the FSM must be cancelled.
-
fsmUpdates
public void fsmUpdates()
Description copied from interface:FSMHandlerWhen the FSM runs to new state.- Specified by:
fsmUpdatesin interfaceFSMHandler
-
fsmStops
public void fsmStops()
Description copied from interface:FSMHandlerWhen the FSM enters a terminal state.- Specified by:
fsmStopsin interfaceFSMHandler
-
createAndInitCommand
protected boolean createAndInitCommand()
-
executeCmdAsync
protected abstract void executeCmdAsync(Command cmd)
-
afterCmdExecuted
protected void afterCmdExecuted(C cmd, boolean ok)
-
uninstallBinding
public void uninstallBinding()
Description copied from interface:WidgetBindingUninstall the binding. The binding cannot be used after that.- Specified by:
uninstallBindingin interfaceWidgetBinding<C extends Command>
-
isContinuousCmdExec
public boolean isContinuousCmdExec()
- Specified by:
isContinuousCmdExecin interfaceWidgetBinding<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:WidgetBindingActivates the widget binding.- Specified by:
setActivatedin interfaceWidgetBinding<C extends Command>- Parameters:
activated- True: the widget binding is activated. Otherwise, it is desactivated.
-
produces
public io.reactivex.Observable<C> produces()
- Specified by:
producesin interfaceWidgetBinding<C extends Command>- Returns:
- An RX observable objects that will provide the commands produced by the binding.
-
getTimesEnded
public long getTimesEnded()
Description copied from interface:WidgetBindingInformation method.- Specified by:
getTimesEndedin interfaceWidgetBinding<C extends Command>- Returns:
- The number of times the widget binding successfully ended (nevermind a command was created or not).
-
getTimesCancelled
public long getTimesCancelled()
Description copied from interface:WidgetBindingInformation method.- Specified by:
getTimesCancelledin interfaceWidgetBinding<C extends Command>- Returns:
- The number of times the widget binding was cancelled (nevermind a command was created or not).
-
-