Class JavaTestContextMenu


  • public abstract class JavaTestContextMenu
    extends java.lang.Object
    Class to encapsulate a custom context menu item to be added to the GUI by a test suite. The method getMenuApplication determines which type of situations the menu should be presented in. Processing the actual selection action event for the menu item(s) should be processed as you normally would with the Swing-provided Action mechanisms.

    All methods in this API will be invoked on the GUI event thread.

    • Constructor Detail

      • JavaTestContextMenu

        public JavaTestContextMenu()
    • Method Detail

      • newInstance

        public abstract JavaTestContextMenu newInstance()
        Create a new instance, based on this instance. The purpose of this is to allow this menu item to appear in multiple places in the interface.
      • getMenu

        public abstract javax.swing.JMenuItem getMenu()
        Get the actual component for this menu. A single menu item is recommended, but a it may also be a submenu. The reference returned should not change after this method has been invoked the first time. This allows for lazy initialization, but then permits caching by the client of the API.
        Returns:
        A menu to be displayed to the user. Must never be null.
      • getMenuApplication

        public abstract int getMenuApplication()
        Determine the contexts in which this menu is applicable. Unless the value is set to CUSTOM, the system managing the menus assumes that it is allowed to control the enabled/disabled state of the menu item.
        See Also:
        TESTS_AND_FOLDERS, TESTS_ONLY, FOLDERS_ONLY, CUSTOM
      • isMultiSelectAllowed

        public boolean isMultiSelectAllowed()
        May multiple nodes be selected at one time for this menu item to be enabled. If not allowed and multiple items are currently selected, updateState() methods will not be called. The default state of this setting is false, override this method to change.

        If you need to enable/disabled based on the composition of the selection, you should return true, then override updateState(String[], TestResult[]) and disable if needed.

        Returns:
        True if multiselect is permitted for this menu action. False otherwise.
      • updateState

        public void updateState​(TestResult tr)
        Called upon when a test is selected by the user. This callback allows the implementation to dynamically adjust it's state. It is recommended that this method remain unimplemented unless really needed, since it is processed synchronously on the event thread. It is critical that the implementation of this method be reasonably fast and non-blocking because it will may be invoked each time the user requests a popup to be displayed.

        Implementations which return CUSTOM from getMenuApplication will generally override this. This method is called regardless of what application type the object indicates.

        The controlling class will first enable/disable the menu based on the application type (unless CUSTOM).

        This method will be invoked on the GUI event thread.

        Parameters:
        tr - The test result object which the users is acting upon.
      • updateState

        public void updateState​(java.lang.String path)
        Called upon when a folder is selected by the user. It is in canonical internal form - forward slash separated.

        This method will be invoked on the GUI event thread.

        Parameters:
        path -
      • updateState

        public void updateState​(java.lang.String[] folders,
                                TestResult... trs)
        Called upon when multiple items have been selected by the user. The union of the two parameters represents the leafs selected by the user to act upon. The intersection of those two parameters is empty.

        This method will be invoked on the GUI event thread.

        Parameters:
        folders - The test paths which the user is acting upon, only the folders. The strings are forward slash separated locations within the test suite, a substring of that which would be returned by TestDescription.getRootRelativeURL(). Null if none.
        trs - The tests which the user is acting upon. Null if none.
        See Also:
        TestDescription.getRootRelativeURL()