Class ContextManager

java.lang.Object
com.sun.javatest.exec.ContextManager
All Implemented Interfaces:
BasicSession.OrderedObserver, Session.Observer, InterviewParameters.TemplateManager, Report.CustomReportManager

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 Details

    • configLoadPath

      protected File configLoadPath
    • configSavePath

      protected File configSavePath
    • configLoadOutside

      protected boolean configLoadOutside
    • configSaveOutside

      protected boolean configSaveOutside
    • templateLoadPath

      protected File templateLoadPath
    • templateSavePath

      protected File templateSavePath
    • templateLoadOutside

      protected boolean templateLoadOutside
    • templateSaveOutside

      protected boolean templateSaveOutside
    • wdPath

      protected File wdPath
    • featureManager

      protected FeatureManager featureManager
    • currentConfig

      protected InterviewParameters currentConfig
    • currentTemplate

      protected InterviewParameters currentTemplate
  • Constructor Details

    • ContextManager

      public ContextManager()
  • Method Details

    • 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:
    • getCustomReports

      public CustomReport[] getCustomReports()
      Get custom report types.
      Specified by:
      getCustomReports in interface Report.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:
    • 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 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:
      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:
      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(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 File getDefaultWorkDirPath()
      Get the default path for work directory.
      Returns:
      The initial directory to load and create work directories.
      See Also:
    • setDefaultWorkDirPath

      public void setDefaultWorkDirPath(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:
      NullPointerException - if the parameter given is null.
      See Also:
    • getDefaultTemplateLoadPath

      public 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

      public void setDefaultTemplateLoadPath(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:
      NullPointerException - if the parameter given is null.
      See Also:
    • getDefaultTemplateSavePath

      public 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

      public void setDefaultTemplateSavePath(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:
      NullPointerException - if the parameter given is null.
      See Also:
    • 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

      public void setAllowTemplateLoadOutsideDefault(boolean state)
      Set ability to load templates outside default directory.
      Parameters:
      state - new state
      See Also:
    • 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

      public void setAllowTemplateSaveOutsideDefault(boolean state)
      Set ability to save templates outside default directory.
      Parameters:
      state - new state
      See Also:
    • getDefaultConfigLoadPath

      public 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

      public void setDefaultConfigLoadPath(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:
      NullPointerException - if the parameter given is null.
      See Also:
    • getDefaultConfigSavePath

      public 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

      public void setDefaultConfigSavePath(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:
      NullPointerException - if the parameter given is null.
      See Also:
    • 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

      public void setAllowConfigLoadOutsideDefault(boolean state)
      Set ability to load config outside default directory.
      Parameters:
      state - new state
      See Also:
    • 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:
    • setAllowConfigSaveOutsideDefault

      public void setAllowConfigSaveOutsideDefault(boolean state)
      Set ability to save config outside default directory.
      Parameters:
      state - new state
      See Also:
    • loadConfiguration

      public void loadConfiguration(File file)
    • setWorkDir

      @Deprecated protected void setWorkDir(WorkDirectory w)
      Deprecated.
      use #setWorkDirectory(WorkDirectory) instead
      See Also:
    • openTree

      protected void openTree(WorkDirectory wd)
    • getCustomRenderersMap

      public Map<Class<? extends Question>,com.sun.interview.wizard.QuestionRenderer> getCustomRenderersMap()
    • registerCustomQuestionRenderer

      protected void registerCustomQuestionRenderer(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
    • 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 interface Session.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 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