Package adams.gui.scripting
Class AbstractScriptlet
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.scripting.AbstractScriptlet
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,Serializable
,Comparable
- Direct Known Subclasses:
AbstractDatabaseScriptlet
,AbstractUndoScriptlet
,DeleteData
,RunTool
public abstract class AbstractScriptlet extends LoggingObject implements Comparable, StoppableWithFeedback
Abstract superclass for action scriplets. An action scriplet processes a single command in the command processor.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
AbstractCommandProcessor
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DataProvider
m_DataProvider
the data provider to use.protected AbstractCommandProcessor
m_Owner
the owner.protected Hashtable<String,Object>
m_Parameters
additional parameters.protected boolean
m_Stopped
whether the scriptlet has been stopped.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractScriptlet()
Initializes the action.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(Object o)
Compares this object with the specified object for order.protected abstract String
doProcess(String options)
Processes the options.boolean
equals(Object o)
Returns whether the two objects are the same.static AbstractScriptlet
forName(String classname)
Instantiates the scriptlet.abstract String
getAction()
Returns the action string used in the command processor.BasePanel
getBasePanel()
Returns the underlying BasePanel if available.DataProvider
getDataProvider()
Returns the current data provider.abstract String
getDescription()
Returns the full description of the action.protected String
getOptionsDescription()
Returns a one-line listing of the options of the action.AbstractCommandProcessor
getOwner()
Returns the owning command processor.Object
getParameter(String key, Object defValue)
Returns the associated value of the parameter.String
getParameterDescription()
Returns a one-line listing of the parameters.Class[]
getRequirements()
Returns the class(es) of an object that must be present for this action to be executed.static String[]
getScriptlets()
Returns a list with classnames of filters.int
hashCode()
Hashcode so can be used as hashtable key.boolean
hasOwner()
Checks whether an owner is set.boolean
hasParameter(String key)
Checks whether a parameter is present.protected void
initialize()
For initializing the member variables.boolean
isStopped()
Whether the execution has been stopped.String
process(String options)
Processes the options.void
setDataProvider(DataProvider value)
Sets the data provider to use for accessing the database.void
setOwner(AbstractCommandProcessor value)
Sets the owning command processor.void
setParameter(String key, Object value)
Sets the parameter and the associated value.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.String
toString()
Returns a string representation of the action.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Owner
protected AbstractCommandProcessor m_Owner
the owner.
-
m_DataProvider
protected DataProvider m_DataProvider
the data provider to use.
-
m_Stopped
protected boolean m_Stopped
whether the scriptlet has been stopped.
-
-
Method Detail
-
setOwner
public void setOwner(AbstractCommandProcessor value)
Sets the owning command processor.- Parameters:
value
- the command processor
-
initialize
protected void initialize()
For initializing the member variables.
-
getOwner
public AbstractCommandProcessor getOwner()
Returns the owning command processor.- Returns:
- the command processor, null if none set
-
hasOwner
public boolean hasOwner()
Checks whether an owner is set.- Returns:
- true if owner available
- See Also:
getOwner()
-
setParameter
public void setParameter(String key, Object value)
Sets the parameter and the associated value.- Parameters:
key
- the name of the parametervalue
- the value of the parameter
-
hasParameter
public boolean hasParameter(String key)
Checks whether a parameter is present.- Parameters:
key
- the name of the parameter to check- Returns:
- true if present
-
getParameter
public Object getParameter(String key, Object defValue)
Returns the associated value of the parameter.- Parameters:
key
- the name of the parameter to retrievedefValue
- the default value- Returns:
- the stored value or, if parameter not found, the default value
-
setDataProvider
public void setDataProvider(DataProvider value)
Sets the data provider to use for accessing the database.- Parameters:
value
- the data provider
-
getDataProvider
public DataProvider getDataProvider()
Returns the current data provider.- Returns:
- the data provider, can be null if not set
-
getBasePanel
public BasePanel getBasePanel()
Returns the underlying BasePanel if available.- Returns:
- the current BasePanel, if any
-
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:
AbstractCommandProcessor.showStatus(String)
-
getAction
public abstract String getAction()
Returns the action string used in the command processor.- Returns:
- the action string
-
getParameterDescription
public String getParameterDescription()
Returns a one-line listing of the parameters.- Returns:
- the command format
-
getOptionsDescription
protected String getOptionsDescription()
Returns a one-line listing of the options of the action.
Default implementation returns null.- Returns:
- the options or null if none
-
getDescription
public abstract String getDescription()
Returns the full description of the action.- Returns:
- the full description
-
getRequirements
public Class[] getRequirements()
Returns the class(es) of an object that must be present for this action to be executed.
The default implementation returns null.- Returns:
- the class(es) of which an instance must be present for execution, null if none necessary
-
doProcess
protected abstract String doProcess(String options) throws Exception
Processes the options.- Parameters:
options
- additional/optional options for the action- Returns:
- null if no error, otherwise error message
- Throws:
Exception
- if something goes wrong
-
process
public String process(String options) throws Exception
Processes the options.- Parameters:
options
- additional/optional options for the action- Returns:
- null if no error, otherwise error message
- Throws:
Exception
- if something goes wrong
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecution
in interfaceStoppable
-
isStopped
public boolean isStopped()
Whether the execution has been stopped.- Specified by:
isStopped
in interfaceStoppableWithFeedback
- Returns:
- true if stopped
-
compareTo
public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Only compares the action name of the two objects.- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object o)
Returns whether the two objects are the same.
Only compares the action name of the two objects.
-
hashCode
public int hashCode()
Hashcode so can be used as hashtable key. Returns the hashcode of thegetAction()
string.
-
toString
public String toString()
Returns a string representation of the action.
-
getScriptlets
public static String[] getScriptlets()
Returns a list with classnames of filters.- Returns:
- the filter classnames
-
forName
public static AbstractScriptlet forName(String classname)
Instantiates the scriptlet.- Parameters:
classname
- the classname of the scriptlet to instantiate- Returns:
- the instantiated scriptlet or null if an error occurred
-
-