Class ContextManager
- java.lang.Object
-
- com.sun.javatest.exec.ContextManager
-
- All Implemented Interfaces:
BasicSession.OrderedObserver
,Session.Observer
,InterviewParameters.TemplateManager
,Report.CustomReportManager
public class ContextManager extends java.lang.Object implements InterviewParameters.TemplateManager, Report.CustomReportManager, BasicSession.OrderedObserver
The context manager provides an interface for customization of the user interface and control over certain parameters of harness operation. It only needs to be customized if the test suite wishes to override default behaviors. All methods will have an implementation, allowing for easy subclassing to make only what change the test suite architect wishes.The test manager (exec tool) will create an instance of the test suite's context manager near the beginning of initialization. Throughout the lifecycle of that tool instance, the context manager instance will be reused when appropriate. For proper operation the context manager must be changed if the test suite changes, in which case the current manager will be disposed, although this is not a typical case, since a new tool is normally created in this circumstance (in current implementation). After a test suite is loaded into a exec tool instance, the associate context manager object will be reused. The implementation of that manager can learn of changes in workdir association by monitoring the
setWorkDirectory()
method (be sure to call the superclass implementation if overriding.When the exec tool is itself disposed, the
dispose()
method of the associated context manager object will be invoked. If the exec tool were to diassociate a context manager object from itself (not usually done),dispose()
would be invoked.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ContextManager.TestManagerDialog
Special class for creating dialogs which should be attached to the context of this test manager.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
configLoadOutside
protected java.io.File
configLoadPath
protected boolean
configSaveOutside
protected java.io.File
configSavePath
protected InterviewParameters
currentConfig
protected InterviewParameters
currentTemplate
protected FeatureManager
featureManager
protected boolean
templateLoadOutside
protected java.io.File
templateLoadPath
protected boolean
templateSaveOutside
protected java.io.File
templateSavePath
protected java.io.File
wdPath
-
Constructor Summary
Constructors Constructor Description ContextManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
canSaveTemplate(java.io.File file)
This method is invoked each time before saving template.void
dispose()
Called when the associated ExecTool instance is being destroyed.boolean
getAllowConfigLoadOutsideDefault()
Get ability to load config outside default directoryboolean
getAllowConfigSaveOutsideDefault()
Get ability to load config outside default directoryboolean
getAllowTemplateLoadOutsideDefault()
Get ability to load templates outside default directoryboolean
getAllowTemplateSaveOutsideDefault()
Get ability to save templates outside default directoryJavaTestContextMenu[]
getContextMenus()
Get the context (popup) custom menus to be added in the GUI.InterviewParameters
getCurrentInterview()
Returns an InterviewParameters instance filled with the current interview values, or null if the interview is not loaded.InterviewParameters
getCurrentTemplate()
Returns an InterviewParameters instance filled with the current template values, or null if the template is not loaded.java.util.Map<java.lang.Class<? extends Question>,com.sun.interview.wizard.QuestionRenderer>
getCustomRenderersMap()
CustomReport[]
getCustomReports()
Get custom report types.CustomTestResultViewer[]
getCustomResultViewers()
Get the context custom test result viewers to be added in the GUI.java.io.File
getDefaultConfigLoadPath()
Get the default path from which configuration files are loaded.java.io.File
getDefaultConfigSavePath()
Get the default path from which configuration files are loaded.java.io.File
getDefaultTemplateLoadPath()
Get the default path from which template files are loaded.java.io.File
getDefaultTemplateSavePath()
Get the default path to which template files are saved.java.io.File
getDefaultWorkDirPath()
Get the default path for work directory.ET_ControlFactory
getExecToolControlFactory(ExecTool et, UIFactory uif)
FeatureManager
getFeatureManager()
Get feature manager from this ContextManager instance.InterviewParameters
getInterview()
Get the permanent instance of the interview object used as a holder for both the configuration and the template.JavaTestMenuManager
getMenuManager()
Get the custom menu manager for this Test Manager instance.InterviewParameters
getTemplate()
Get the active template.TestSuite
getTestSuite()
Get the active test suite.ToolBarManager
getToolBarManager()
WorkDirectory
getWorkDirectory()
Get the active work directory.void
loadConfiguration(java.io.File file)
protected void
openTree(WorkDirectory wd)
int
order()
BasicSession.OrderedObserver interface method.void
refreshTests()
Request that the harness reload the test suite structure from the test suite.protected void
registerCustomQuestionRenderer(java.lang.Class<? extends Question> question, com.sun.interview.wizard.QuestionRenderer renderer)
Register custom config editor's question renderer for specified question class.void
setAllowConfigLoadOutsideDefault(boolean state)
Set ability to load config outside default directory.void
setAllowConfigSaveOutsideDefault(boolean state)
Set ability to save config outside default directory.void
setAllowTemplateLoadOutsideDefault(boolean state)
Set ability to load templates outside default directory.void
setAllowTemplateSaveOutsideDefault(boolean state)
Set ability to save templates outside default directory.void
setDefaultConfigLoadPath(java.io.File dir)
Set the default path from which configuration files are loaded.void
setDefaultConfigSavePath(java.io.File dir)
Set the default path to which configuration files are saved.void
setDefaultTemplateLoadPath(java.io.File dir)
Set the default path from which template files are loaded.void
setDefaultTemplateSavePath(java.io.File dir)
Set the default path to which template files are saved.void
setDefaultWorkDirPath(java.io.File dir)
Default path presented to user when they are prompted to create a work directory.void
setFeatureManager(FeatureManager featureManager)
Set given feature manager for this ContextManager instance.protected void
setTestSuite(TestSuite ts)
protected void
setWorkDir(WorkDirectory w)
Deprecated.use #setWorkDirectory(WorkDirectory) insteadprotected void
setWorkDirectory(WorkDirectory w)
void
syncInterview()
Write the active interview to disk if possible.void
updated(Session.Event ev)
Invoked when session has been changed.protected void
updatedCurrentConfig(InterviewParameters ip)
Invoked when the value of the current configuration has been modified.protected void
updatedCurrentTemplate(InterviewParameters ip)
Invoked when the value of the current template has been modified.protected void
updatedWorkDirectory(WorkDirectory wd)
Invoked when the value of the work directory has been modified.
-
-
-
Field Detail
-
configLoadPath
protected java.io.File configLoadPath
-
configSavePath
protected java.io.File configSavePath
-
configLoadOutside
protected boolean configLoadOutside
-
configSaveOutside
protected boolean configSaveOutside
-
templateLoadPath
protected java.io.File templateLoadPath
-
templateSavePath
protected java.io.File templateSavePath
-
templateLoadOutside
protected boolean templateLoadOutside
-
templateSaveOutside
protected boolean templateSaveOutside
-
wdPath
protected java.io.File wdPath
-
featureManager
protected FeatureManager featureManager
-
currentConfig
protected InterviewParameters currentConfig
-
currentTemplate
protected InterviewParameters currentTemplate
-
-
Method Detail
-
getMenuManager
public JavaTestMenuManager getMenuManager()
Get the custom menu manager for this Test Manager instance.- Returns:
- The custom menu manager. If null, it can be assumed that there are no custom menus.
-
getToolBarManager
public ToolBarManager getToolBarManager()
-
dispose
public void dispose()
Called when the associated ExecTool instance is being destroyed. Great care should be taken in using references to objects, as they maybe already be disposed - especially GUI components. The exact order in which the exec tool disposes it's associated objects is not currently defined, although exec tool is primarily responsible for GUI objects, so itself will not dispose of core objects (TestSuite objects, work directories, etc).
-
getContextMenus
public JavaTestContextMenu[] getContextMenus()
Get the context (popup) custom menus to be added in the GUI. This method is only called when the GUI is initialized, so the value should not change after its first invocation. Any state changes (enable, disable, hide, text changes) with the menu items should occur inside the JavaTestContextMenu instances, not be adding and removing them from the array returned by this method.- Returns:
- The menus to be added. Null if there are no custom menus (the default).
- See Also:
JavaTestContextMenu
-
getCustomReports
public CustomReport[] getCustomReports()
Get custom report types.- Specified by:
getCustomReports
in interfaceReport.CustomReportManager
- Returns:
- Null if no custom types are requested.
-
getCustomResultViewers
public CustomTestResultViewer[] getCustomResultViewers()
Get the context custom test result viewers to be added in the GUI. This method is only called when the GUI is initialized, so the value should not change after its first invocation.- Returns:
- The menus to be added. Null if there are no custom viewers (the default).
- See Also:
CustomTestResultViewer
-
getTestSuite
public TestSuite getTestSuite()
Get the active test suite.- Returns:
- The current test suite.
-
setTestSuite
protected void setTestSuite(TestSuite ts)
-
getWorkDirectory
public WorkDirectory getWorkDirectory()
Get the active work directory.- Returns:
- The current work directory, null if it has not been set.
-
setWorkDirectory
protected void setWorkDirectory(WorkDirectory w)
-
getInterview
public InterviewParameters getInterview()
Get the permanent instance of the interview object used as a holder for both the configuration and the template. This instance is filled with the current values when the user finishes editing values and commits changes. Depending on what has been committed later, it will be filled either with the current configuration or the current template values.
Note that there is currently no API support for "locking" the interview, which means that multiple parts of the system could work against each other.- Returns:
- The active interview instance.
-
getTemplate
public InterviewParameters getTemplate() throws java.io.IOException, Interview.Fault
Get the active template.- Returns:
- null, if there is no interview or template in context yet; current interview in case it actually represents template; new instance of InterviewParameters, representing template, in case there exist template, associated with interview
- Throws:
java.io.IOException
Interview.Fault
-
getCurrentInterview
public InterviewParameters getCurrentInterview()
Returns an InterviewParameters instance filled with the current interview values, or null if the interview is not loaded.
-
getCurrentTemplate
public InterviewParameters getCurrentTemplate()
Returns an InterviewParameters instance filled with the current template values, or null if the template is not loaded.
-
refreshTests
public void refreshTests()
Request that the harness reload the test suite structure from the test suite. If called on the GUI event thread, it will start a new thread before executing the operation, to avoid blocking the GUI. It is recommended that the caller use a different thread and probably show the user a "Please wait" message until this method returns.
-
syncInterview
public void syncInterview()
Write the active interview to disk if possible. For this to work, getInterview() must be non-null. This also implies that there is a test suite and work directory selected already.- Throws:
java.lang.IllegalStateException
- if there is no interview available.
-
getFeatureManager
public FeatureManager getFeatureManager()
Get feature manager from this ContextManager instance.- Returns:
- current feature manager
-
setFeatureManager
public void setFeatureManager(FeatureManager featureManager)
Set given feature manager for this ContextManager instance.- Parameters:
featureManager
- new feature manager
-
canSaveTemplate
public boolean canSaveTemplate(java.io.File file)
This method is invoked each time before saving template. The template will be saved only if this method returns true. The default implementation always returns true.- Specified by:
canSaveTemplate
in interfaceInterviewParameters.TemplateManager
- Parameters:
file
- template file- Returns:
- true if this operation is allowed, false otherwise
-
getDefaultWorkDirPath
public java.io.File getDefaultWorkDirPath()
Get the default path for work directory.- Returns:
- The initial directory to load and create work directories.
- See Also:
setDefaultWorkDirPath(File)
-
setDefaultWorkDirPath
public void setDefaultWorkDirPath(java.io.File dir)
Default path presented to user when they are prompted to create a work directory. This method does not imply any requirement that the user actually load/save the workdir in the given location.- Parameters:
dir
- The initial directory where workdirs should be loaded/saved to.- Throws:
java.lang.NullPointerException
- if the parameter given is null.- See Also:
getDefaultWorkDirPath()
-
getDefaultTemplateLoadPath
public java.io.File getDefaultTemplateLoadPath()
Get the default path from which template files are loaded.- Returns:
- The initial directory where template files should be loaded from. Null if not set.
- See Also:
setDefaultTemplateLoadPath(java.io.File)
,setAllowTemplateLoadOutsideDefault(boolean)
-
setDefaultTemplateLoadPath
public void setDefaultTemplateLoadPath(java.io.File dir)
Set the default path from which template files are loaded. Does not imply a requirement that the template be loaded from that location.- Parameters:
dir
- The initial directory where template files should be loaded from.- Throws:
java.lang.NullPointerException
- if the parameter given is null.- See Also:
getDefaultTemplateLoadPath()
,setAllowTemplateLoadOutsideDefault(boolean)
-
getDefaultTemplateSavePath
public java.io.File getDefaultTemplateSavePath()
Get the default path to which template files are saved.- Returns:
- The initial directory where template files should be saved to. Null if not set.
- See Also:
setDefaultTemplateSavePath(File)
,setAllowTemplateSaveOutsideDefault(boolean)
-
setDefaultTemplateSavePath
public void setDefaultTemplateSavePath(java.io.File dir)
Set the default path to which template files are saved. Does not imply a requirement that the template must be saved to that location.- Parameters:
dir
- The initial directory where template should be saved to.- Throws:
java.lang.NullPointerException
- if the parameter given is null.- See Also:
getDefaultTemplateLoadPath()
,setAllowTemplateLoadOutsideDefault(boolean)
-
getAllowTemplateLoadOutsideDefault
public boolean getAllowTemplateLoadOutsideDefault()
Get ability to load templates outside default directory- Returns:
- true if the loading outside default directory is allowed or false otherwise
- See Also:
setAllowTemplateLoadOutsideDefault(boolean)
-
setAllowTemplateLoadOutsideDefault
public void setAllowTemplateLoadOutsideDefault(boolean state)
Set ability to load templates outside default directory.- Parameters:
state
- new state- See Also:
getAllowTemplateLoadOutsideDefault()
-
getAllowTemplateSaveOutsideDefault
public boolean getAllowTemplateSaveOutsideDefault()
Get ability to save templates outside default directory- Returns:
- true if the saving outside default directory is allowed or false otherwise
- See Also:
setAllowTemplateSaveOutsideDefault(boolean)
-
setAllowTemplateSaveOutsideDefault
public void setAllowTemplateSaveOutsideDefault(boolean state)
Set ability to save templates outside default directory.- Parameters:
state
- new state- See Also:
getAllowTemplateSaveOutsideDefault()
-
getDefaultConfigLoadPath
public java.io.File getDefaultConfigLoadPath()
Get the default path from which configuration files are loaded.- Returns:
- The initial directory where configuration files should be loaded from. Null if not set.
- See Also:
setDefaultConfigLoadPath(java.io.File)
,setAllowConfigLoadOutsideDefault(boolean)
-
setDefaultConfigLoadPath
public void setDefaultConfigLoadPath(java.io.File dir)
Set the default path from which configuration files are loaded. Does not imply a requirement that the config be loaded from that location.- Parameters:
dir
- The initial directory where configuration files should be loaded from.- Throws:
java.lang.NullPointerException
- if the parameter given is null.- See Also:
getDefaultConfigLoadPath()
,setAllowConfigLoadOutsideDefault(boolean)
-
getDefaultConfigSavePath
public java.io.File getDefaultConfigSavePath()
Get the default path from which configuration files are loaded.- Returns:
- The initial directory where configuration files should be loaded from. Null if not set.
- See Also:
setDefaultConfigSavePath(File)
,setAllowConfigSaveOutsideDefault(boolean)
-
setDefaultConfigSavePath
public void setDefaultConfigSavePath(java.io.File dir)
Set the default path to which configuration files are saved. Does not imply a requirement that the config must be saved to that location.- Parameters:
dir
- The initial directory where workdirs should be saved to.- Throws:
java.lang.NullPointerException
- if the parameter given is null.- See Also:
getDefaultConfigLoadPath()
,setAllowConfigLoadOutsideDefault(boolean)
-
getAllowConfigLoadOutsideDefault
public boolean getAllowConfigLoadOutsideDefault()
Get ability to load config outside default directory- Returns:
- true if the loading outside default directory is allowed or false otherwise
- See Also:
setAllowConfigLoadOutsideDefault(boolean)
-
setAllowConfigLoadOutsideDefault
public void setAllowConfigLoadOutsideDefault(boolean state)
Set ability to load config outside default directory.- Parameters:
state
- new state- See Also:
getAllowConfigLoadOutsideDefault()
-
getAllowConfigSaveOutsideDefault
public boolean getAllowConfigSaveOutsideDefault()
Get ability to load config outside default directory- Returns:
- true if the saving outside default directory is allowed or false otherwise
- See Also:
setAllowConfigLoadOutsideDefault(boolean)
-
setAllowConfigSaveOutsideDefault
public void setAllowConfigSaveOutsideDefault(boolean state)
Set ability to save config outside default directory.- Parameters:
state
- new state- See Also:
getAllowConfigSaveOutsideDefault()
-
loadConfiguration
public void loadConfiguration(java.io.File file)
-
setWorkDir
@Deprecated protected void setWorkDir(WorkDirectory w)
Deprecated.use #setWorkDirectory(WorkDirectory) instead- See Also:
setWorkDirectory(WorkDirectory)
-
openTree
protected void openTree(WorkDirectory wd)
-
getCustomRenderersMap
public java.util.Map<java.lang.Class<? extends Question>,com.sun.interview.wizard.QuestionRenderer> getCustomRenderersMap()
-
registerCustomQuestionRenderer
protected void registerCustomQuestionRenderer(java.lang.Class<? extends Question> question, com.sun.interview.wizard.QuestionRenderer renderer)
Register custom config editor's question renderer for specified question class. It is better to register custom renderer BEFORE Configuration Editor is constructed, for example in ContextManager's constructor.- Parameters:
question
- Question's classrenderer
- Custom question renderer fot this question
-
getExecToolControlFactory
public ET_ControlFactory getExecToolControlFactory(ExecTool et, UIFactory uif)
-
updated
public void updated(Session.Event ev)
Invoked when session has been changed.- Specified by:
updated
in interfaceSession.Observer
- Parameters:
ev
-
-
order
public int order()
BasicSession.OrderedObserver interface method. Returns Integer.MAX_VALUE - 100 to be notified after controls, but before ExecTool.- Specified by:
order
in interfaceBasicSession.OrderedObserver
-
updatedWorkDirectory
protected void updatedWorkDirectory(WorkDirectory wd)
Invoked when the value of the work directory has been modified. This implementation just invokes setWorkDirectory(). Subclasses might implement alternative reaction on configuration change.- Parameters:
wd
-
-
updatedCurrentConfig
protected void updatedCurrentConfig(InterviewParameters ip)
Invoked when the value of the current configuration has been modified. This implementation does nothing. Subclasses might implement some reaction on configuration change.- Parameters:
ip
- - InterviewParameters object with new values
-
updatedCurrentTemplate
protected void updatedCurrentTemplate(InterviewParameters ip)
Invoked when the value of the current template has been modified. This implementation does nothing. Subclasses might implement some reaction on configuration change.- Parameters:
ip
- - InterviewParameters object with new values
-
-