Class 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.

    • 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
    • Constructor Detail

      • ContextManager

        public ContextManager()
    • 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.
      • 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
      • 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 interface InterviewParameters.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()
      • 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)
      • 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()
      • 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)
      • 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)
      • 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 class
        renderer - Custom question renderer fot this question
      • 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 interface BasicSession.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