Package adams.gui.scripting
Class AbstractCommandProcessor
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.scripting.AbstractCommandProcessor
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Stoppable
,UndoHandler
,Serializable
- Direct Known Subclasses:
CommandProcessor
public abstract class AbstractCommandProcessor extends LoggingObject implements UndoHandler, Stoppable
Abstract command processor for the scripting engine.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<String,AbstractScriptlet>
m_Actions
the action <-> scriptlet relation.protected BasePanel
m_BasePanel
the base panel to use.protected AbstractScriptlet
m_CurrentScriptlet
the scriptlet currently being executed.protected AbstractScriptingEngine
m_Owner
the scripting engine this processor belongs to.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractCommandProcessor()
Initializes the processor.AbstractCommandProcessor(AbstractScriptingEngine owner)
Initializes the processor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addUndoPoint(String statusMsg, String undoComment)
Adds an undo point, if possible.protected String
checkRequirement(Class requirement)
Checks the following requirement.protected String
checkRequirements(AbstractScriptlet scriplet)
Checks whether all the requirements for the scriptlet have been met.protected String
createRequirementError(Class requirement)
Creates a default error message for the given requirement class.protected AbstractScriptlet
findScriptlet(String action)
Returns the scriptlet associated with the action.BasePanel
getBasePanel()
Returns the base panel.abstract AbstractDatabaseConnection
getDatabaseConnection()
Returns the currently used database connection object, can be null.DataContainerPanel
getDataContainerPanel()
Returns the DataContainer panel.AbstractDataContainerUpdatingPostProcessor
getDataContainerUpdatingPostProcessor()
Returns the post-processor to use.AbstractScriptingEngine
getOwner()
Returns the owner of this processor.protected Class
getRequiredFlowClass()
Returns the class that is required in the flow.StatusMessageHandler
getStatusMessageHandler()
Returns the status message handler, if available.Undo
getUndo()
Returns the current undo manager, can be null.protected abstract Object
getUndoObject()
Returns the object that is to be used for the undo point.String
globalInfo()
Returns a string describing the object.protected void
initScriptlets()
Initializes all the available scriptlets.boolean
isUndoSupported()
Returns whether an Undo manager is currently available.String
process(ScriptingCommand command)
processes the given command.void
setBasePanel(BasePanel value)
Sets the base panel.void
setOwner(AbstractScriptingEngine value)
Sets the owner of this processor.void
setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.protected void
setupScriptlet(AbstractScriptlet scriptlet)
Performs further setups of the scriptlet.protected void
showStatus(String msg)
Displays the status, if the owner is a StatusMessageHandler, otherwise it just prints the status on the commandline.void
stopExecution()
Stops the execution.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Owner
protected AbstractScriptingEngine m_Owner
the scripting engine this processor belongs to.
-
m_BasePanel
protected BasePanel m_BasePanel
the base panel to use.
-
m_Actions
protected Hashtable<String,AbstractScriptlet> m_Actions
the action <-> scriptlet relation.
-
m_CurrentScriptlet
protected transient AbstractScriptlet m_CurrentScriptlet
the scriptlet currently being executed.
-
-
Constructor Detail
-
AbstractCommandProcessor
public AbstractCommandProcessor()
Initializes the processor. Still needs to set the owner.- See Also:
setOwner(AbstractScriptingEngine)
-
AbstractCommandProcessor
public AbstractCommandProcessor(AbstractScriptingEngine owner)
Initializes the processor.- Parameters:
owner
- the owning scripting engine
-
-
Method Detail
-
initScriptlets
protected void initScriptlets()
Initializes all the available scriptlets.
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Returns:
- a description suitable for displaying in the gui
-
setOwner
public void setOwner(AbstractScriptingEngine value)
Sets the owner of this processor.- Parameters:
value
- the owner
-
getOwner
public AbstractScriptingEngine getOwner()
Returns the owner of this processor.- Returns:
- the owner
-
getDatabaseConnection
public abstract AbstractDatabaseConnection getDatabaseConnection()
Returns the currently used database connection object, can be null.- Returns:
- the current object
-
setBasePanel
public void setBasePanel(BasePanel value)
Sets the base panel.- Parameters:
value
- the panel to use
-
getBasePanel
public BasePanel getBasePanel()
Returns the base panel.- Returns:
- the base panel
-
getDataContainerPanel
public DataContainerPanel getDataContainerPanel()
Returns the DataContainer panel.- Returns:
- the panel or null
-
getDataContainerUpdatingPostProcessor
public AbstractDataContainerUpdatingPostProcessor getDataContainerUpdatingPostProcessor()
Returns the post-processor to use.- Returns:
- the post-processor
-
getRequiredFlowClass
protected Class getRequiredFlowClass()
Returns the class that is required in the flow.- Returns:
- the required class
-
setUndo
public void setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.- Specified by:
setUndo
in interfaceUndoHandler
- Parameters:
value
- the undo manager to use
-
getUndo
public Undo getUndo()
Returns the current undo manager, can be null.- Specified by:
getUndo
in interfaceUndoHandler
- Returns:
- the undo manager, if any
-
isUndoSupported
public boolean isUndoSupported()
Returns whether an Undo manager is currently available.- Specified by:
isUndoSupported
in interfaceUndoHandler
- Returns:
- true if an undo manager is set
-
getStatusMessageHandler
public StatusMessageHandler getStatusMessageHandler()
Returns the status message handler, if available.- Returns:
- the handler
-
getUndoObject
protected abstract Object getUndoObject()
Returns the object that is to be used for the undo point.- Returns:
- the object to store as undo point
- See Also:
addUndoPoint(String, String)
-
addUndoPoint
protected void addUndoPoint(String statusMsg, String undoComment)
Adds an undo point, if possible.- Parameters:
statusMsg
- the status message to display while adding the undo pointundoComment
- the comment for the undo point
-
showStatus
protected void showStatus(String msg)
Displays the status, if the owner is a StatusMessageHandler, otherwise it just prints the status on the commandline.- Parameters:
msg
- the message to display- See Also:
StatusMessageHandler
-
findScriptlet
protected AbstractScriptlet findScriptlet(String action)
Returns the scriptlet associated with the action.- Parameters:
action
- the action to get the scriptlet for- Returns:
- the scriptlet or null if none found
-
createRequirementError
protected String createRequirementError(Class requirement)
Creates a default error message for the given requirement class.- Parameters:
requirement
- the class to create the error message for- Returns:
- the error message
-
checkRequirement
protected String checkRequirement(Class requirement)
Checks the following requirement.
Needs to be extended in derived classes.- Parameters:
requirement
- the requirement class that needs to be present- Returns:
- "" if met, error message if not met, null if not processed
-
checkRequirements
protected String checkRequirements(AbstractScriptlet scriplet)
Checks whether all the requirements for the scriptlet have been met.
Needs to be extended in derived classes.- Parameters:
scriplet
- the scriplet to check- Returns:
- "" if all requirements met, error message if not met, null if at least one requirement not processed
-
setupScriptlet
protected void setupScriptlet(AbstractScriptlet scriptlet)
Performs further setups of the scriptlet.
Default implementation does nothing.- Parameters:
scriptlet
- the scriptlet to work on
-
process
public String process(ScriptingCommand command) throws Exception
processes the given command.- Parameters:
command
- the command to execute- Returns:
- null if no error generated, otherwise the error output
- Throws:
Exception
- if something goes wrong
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecution
in interfaceStoppable
-
-