Package org.apache.jmeter.gui

# Class GuiPackage

java.lang.Object
org.apache.jmeter.gui.GuiPackage

All Implemented Interfaces:
  `UndoHistory.HistoryListener`, `LocaleChangeListener`

public final class GuiPackage extends Object implements LocaleChangeListener, UndoHistory.HistoryListener
GuiPackage is a static class that provides convenient access to information about the current state of JMeter's GUI. Any GUI class can grab a handle to GuiPackage by calling the static method `getInstance()` and then use it to query the GUI about it's state. When actions, for instance, need to affect the GUI, they typically use GuiPackage to get access to different parts of the GUI.

## Method Summary

Modifier and Type
Method
Description
`HashTree`
`addSubTree(HashTree subTree)`
Add a subtree to the currently selected node.
`void`
`addTestPlanListener(TestPlanListener listener)`
Adds a test plan listener.
`void`
`beginUndoTransaction()`
Begin a group of actions modeled as 1 undo
`boolean`
`canRedo()`
`boolean`
`canUndo()`
`void`
`clearTestPlan()`
Clears the test plan and associated objects.
`void`
`clearTestPlan(org.apache.jmeter.testelement.TestElement element)`
Clears the test plan element and associated object
`org.apache.jmeter.testelement.TestElement`
`createTestElement(Class<?> guiClass, Class<?> testClass)`
Create a TestElement corresponding to the specified GUI class.
`org.apache.jmeter.testelement.TestElement`
`createTestElement(String objClass)`
Create a TestElement for a GUI or TestBean class.
`void`
`displayPopUp(Component invoker, MouseEvent e, JPopupMenu popup)`
Display the specified popup menu at the location specified by a mouse event with the specified source component.
`void`
`displayPopUp(MouseEvent e, JPopupMenu popup)`
Display the specified popup menu with the source component and location from the specified mouse event.
`void`
`endUndoTransaction()`
End a group of actions modeled as 1 undo
`org.apache.jmeter.testelement.TestElement`
`getCurrentElement()`
`JMeterGUIComponent`
`getCurrentGui()`
Convenience method for grabbing the gui for the current node.
`JMeterTreeNode`
`getCurrentNode()`
`HashTree`
`getCurrentSubTree()`
Get the currently selected subtree.
`JMeterGUIComponent`
`getGui(org.apache.jmeter.testelement.TestElement node)`
Get a JMeterGUIComponent for the specified test element.
`JMeterGUIComponent`
`getGui(org.apache.jmeter.testelement.TestElement node, Class<?> guiClass, Class<?> testClass)`
Get a JMeterGUIComponent for the specified test element.
`static GuiPackage`
`getInstance()`
Retrieve the singleton GuiPackage instance.
`GuiLogEventBus`
`getLogEventBus()`
Return `GuiLogEventBus`.
`LoggerPanel`
`getLoggerPanel()`
`MainFrame`
`getMainFrame()`
Get the main JMeter frame.
`JToolBar`
`getMainToolbar()`
Get the main JMeter toolbar.
`JCheckBoxMenuItem`
`getMenuItemLoggerPanel()`
Get the menu item LoggerPanel.
`JCheckBoxMenuItem`
`getMenuItemSaveBeforeRunPanel()`
Get the menu item SaveBeforeRunPanel.
`TreeNodeNamingPolicy`
`getNamingPolicy()`
`JMeterTreeNode`
`getNodeOf(org.apache.jmeter.testelement.TestElement userObject)`
Find the JMeterTreeNode for a certain TestElement object.
`ValueReplacer`
`getReplacer()`
Get a ValueReplacer for the test tree.
`List<Stoppable>`
`getStoppables()`
`String`
`getTestPlanFile()`
`JMeterTreeListener`
`getTreeListener()`
Get the listener for JMeter's test tree.
`JMeterTreeModel`
`getTreeModel()`
Get the model for JMeter's test tree.
`static void`
`initInstance(JMeterTreeListener listener, JMeterTreeModel treeModel)`
When GuiPackage is requested for the first time, it should be given handles to JMeter's Tree Listener and TreeModel.
`void`
`invalidateCachedUi()`
`boolean`
`isDirty()`
Retrieves the state of the 'dirty' property, a flag that indicates if there are test tree components that have been modified since they were last saved.
`void`
`localeChanged(LocaleChangeEvent event)`
`void`
`notifyChangeInHistory(UndoHistory history)`
Called when history changes, it updates toolbar
`void`
`redo()`
Navigate forward through undo history
`void`
`refreshCurrentGui()`
Refresh GUI from node state.
`void`
`register(Stoppable stoppable)`
Register process to stop on reload
`void`
`registerAsListener()`
Register as listener of: - UndoHistory - Locale Changes
`void`
`removeNode(org.apache.jmeter.testelement.TestElement node)`
Remove a test element from the tree.
`void`
`removeTestPlanListener(TestPlanListener listener)`
Removes a test plan listener.
`void`
`setDirty(boolean dirty)`
The dirty property is a flag that indicates whether there are parts of JMeter's test tree that the user has not saved since last modification.
`void`
`setLoggerPanel(LoggerPanel loggerPanel)`
`void`
`setMainFrame(MainFrame newMainFrame)`
Set the main JMeter frame.
`void`
`setMainToolbar(JToolBar newToolbar)`
Set the main JMeter toolbar.
`void`
`setMenuItemLoggerPanel(JCheckBoxMenuItem menuItemLoggerPanel)`
Set the menu item LoggerPanel.
`void`
`setMenuItemSaveBeforeRunPanel(JCheckBoxMenuItem menuItemSaveBeforeRunPanel)`
Set the menu item SaveBeforeRunPanel.
`void`
`setSaveBeforeRunByPreference(boolean saveBeforeRun)`
Should Save Before Run by Preference Only
`void`
`setTestPlanFile(String f)`
Sets the filepath of the current test plan.
`boolean`
`shouldSaveBeforeRun()`
Should Save Before Run Decide by Preference and if not exists by Property
`boolean`
`shouldSaveBeforeRunByPreference()`
Should Save Before Run by Preference Only
`static void`
`showErrorMessage(String message, String title)`
`static void`
`showInfoMessage(String message, String title)`
`static void`
`showMessage(String message, String title, int type)`
`static void`
`showWarningMessage(String message, String title)`
`void`
`undo()`
Navigate back through undo history
`void`
`unregister(Stoppable stoppableToUnregister)`
Unregister stoppable
`void`
`updateCurrentGui()`
Update the GUI for the currently selected node.
`void`
`updateCurrentNode()`
This method should be called in order for GuiPackage to change the current node.
`void`
`updateUIForHiddenComponents()`
Tells hidden GUI components to update UIs when they are shown.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### getInstance

public static GuiPackage getInstance()
Retrieve the singleton GuiPackage instance.

Returns:
  the GuiPackage instance (may be null, e.g in non-Gui mode)

### registerAsListener

public void registerAsListener()
Register as listener of: - UndoHistory - Locale Changes

### initInstance

public static void initInstance(JMeterTreeListener listener, JMeterTreeModel treeModel)
When GuiPackage is requested for the first time, it should be given handles to JMeter's Tree Listener and TreeModel.

Parameters:
  `listener` - the TreeListener for JMeter's test tree
  `treeModel` - the model for JMeter's test tree

### getGui

public JMeterGUIComponent getGui(org.apache.jmeter.testelement.TestElement node)
Get a JMeterGUIComponent for the specified test element. If the GUI has already been created, that instance will be returned. Otherwise, if a GUI component of the same type has been created, and the component is not marked as an `UnsharedComponent`, that shared component will be returned. Otherwise, a new instance of the component will be created. The TestElement's GUI_CLASS property will be used to determine the appropriate type of GUI component to use.

Parameters:
  `node` - the test element which this GUI is being created for
Returns:
  the GUI component corresponding to the specified test element

### getGui

public JMeterGUIComponent getGui(org.apache.jmeter.testelement.TestElement node, Class<?> guiClass, Class<?> testClass)
Get a JMeterGUIComponent for the specified test element. If the GUI has already been created, that instance will be returned. Otherwise, if a GUI component of the same type has been created, and the component is not marked as an `UnsharedComponent`, that shared component will be returned. Otherwise, a new instance of the component will be created.

Parameters:
  `node` - the test element which this GUI is being created for
  `guiClass` - the fully qualified class name of the GUI component which will be created if it doesn't already exist
  `testClass` - the fully qualified class name of the test elements which have to be edited by the returned GUI component
Returns:
  the GUI component corresponding to the specified test element

### removeNode

@API(since="5.3", status=MAINTAINED) public void removeNode(org.apache.jmeter.testelement.TestElement node)
Remove a test element from the tree. This removes the reference to any associated GUI component.

Parameters:
  `node` - the test element being removed

### getCurrentGui

public JMeterGUIComponent getCurrentGui()
Convenience method for grabbing the gui for the current node.

Returns:
  the GUI component associated with the currently selected node

### getNodeOf

public JMeterTreeNode getNodeOf(org.apache.jmeter.testelement.TestElement userObject)
Find the JMeterTreeNode for a certain TestElement object.

Parameters:
  `userObject` - the test element to search for
Returns:
  the tree node associated with the test element

### createTestElement

public org.apache.jmeter.testelement.TestElement createTestElement(Class<?> guiClass, Class<?> testClass)
Create a TestElement corresponding to the specified GUI class.

Parameters:
  `guiClass` - the fully qualified class name of the GUI component or a TestBean class for TestBeanGUIs.
  `testClass` - the fully qualified class name of the test elements edited by this GUI component.
Returns:
  the test element corresponding to the specified GUI class.

### createTestElement

public org.apache.jmeter.testelement.TestElement createTestElement(String objClass)
Create a TestElement for a GUI or TestBean class.

This is a utility method to help actions do with one single String parameter.

Parameters:
  `objClass` - the fully qualified class name of the GUI component or of the TestBean subclass for which a TestBeanGUI is wanted.
Returns:
  the test element corresponding to the specified GUI class.

### updateCurrentGui

public void updateCurrentGui()
Update the GUI for the currently selected node. The GUI component is configured to reflect the settings in the current tree node.

### refreshCurrentGui

public void refreshCurrentGui()
Refresh GUI from node state. This method does not update the current node from GUI at the difference of `updateCurrentGui()`

### updateCurrentNode

public void updateCurrentNode()
This method should be called in order for GuiPackage to change the current node. This will save any changes made to the earlier node before choosing the new node.

### getCurrentNode

public JMeterTreeNode getCurrentNode()

### getCurrentElement

public org.apache.jmeter.testelement.TestElement getCurrentElement()

### setDirty

public void setDirty(boolean dirty)
The dirty property is a flag that indicates whether there are parts of JMeter's test tree that the user has not saved since last modification. Various `Command` actions set this property when components are modified/created/saved.

Parameters:
  `dirty` - the new value of the dirty flag

### isDirty

public boolean isDirty()
Retrieves the state of the 'dirty' property, a flag that indicates if there are test tree components that have been modified since they were last saved.

Returns:
  true if some tree components have been modified since they were last saved, false otherwise

### addSubTree

public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException
Add a subtree to the currently selected node.

Parameters:
  `subTree` - the subtree to add.
Returns:
  the resulting subtree starting with the currently selected node
Throws:
  `IllegalUserActionException` - if a subtree cannot be added to the currently selected node

### getCurrentSubTree

public HashTree getCurrentSubTree()
Get the currently selected subtree.

Returns:
  the subtree of the currently selected node

### getTreeModel

public JMeterTreeModel getTreeModel()
Get the model for JMeter's test tree.

Returns:
  the JMeter tree model

### getReplacer

public ValueReplacer getReplacer()
Get a ValueReplacer for the test tree.

Returns:
  a ValueReplacer configured for the test tree

### setMainFrame

public void setMainFrame(MainFrame newMainFrame)
Set the main JMeter frame.

Parameters:
  `newMainFrame` - the new JMeter main frame

### getMainFrame

public MainFrame getMainFrame()
Get the main JMeter frame.

Returns:
  the main JMeter frame

### getTreeListener

public JMeterTreeListener getTreeListener()
Get the listener for JMeter's test tree.

Returns:
  the JMeter test tree listener

### setMainToolbar

public void setMainToolbar(JToolBar newToolbar)
Set the main JMeter toolbar.

Parameters:
  `newToolbar` - the new JMeter main toolbar

### getMainToolbar

public JToolBar getMainToolbar()
Get the main JMeter toolbar.

Returns:
  the main JMeter toolbar

### displayPopUp

public void displayPopUp(MouseEvent e, JPopupMenu popup)
Display the specified popup menu with the source component and location from the specified mouse event.

Parameters:
  `e` - the mouse event causing this popup to be displayed
  `popup` - the popup menu to display

### displayPopUp

public void displayPopUp(Component invoker, MouseEvent e, JPopupMenu popup)
Display the specified popup menu at the location specified by a mouse event with the specified source component.

Parameters:
  `invoker` - the source component
  `e` - the mouse event causing this popup to be displayed
  `popup` - the popup menu to display

### localeChanged

public void localeChanged(LocaleChangeEvent event)

Specified by:
  `localeChanged` in interface `LocaleChangeListener`

### invalidateCachedUi

public void invalidateCachedUi()

### updateUIForHiddenComponents

@API(since="5.3", status=EXPERIMENTAL) public void updateUIForHiddenComponents()
Tells hidden GUI components to update UIs when they are shown.

When Look and Feel (or zoom scaling) changes, only visible components are updated. The hidden ones are updated as they are shown.

### setTestPlanFile

public void setTestPlanFile(String f)
Sets the filepath of the current test plan. It's shown in the main frame title and used on saving.

Parameters:
  `f` - The filepath of the current test plan

### getTestPlanFile

public String getTestPlanFile()

### clearTestPlan

public void clearTestPlan()
Clears the test plan and associated objects. Clears the test plan file name.

### clearTestPlan

public void clearTestPlan(org.apache.jmeter.testelement.TestElement element)
Clears the test plan element and associated object

Parameters:
  `element` - to clear

### showErrorMessage

public static void showErrorMessage(String message, String title)

### showInfoMessage

public static void showInfoMessage(String message, String title)

### showWarningMessage

public static void showWarningMessage(String message, String title)

### showMessage

public static void showMessage(String message, String title, int type)

### unregister

public void unregister(Stoppable stoppableToUnregister)
Unregister stoppable

Parameters:
  `stoppableToUnregister` - Stoppable to unregister

### register

public void register(Stoppable stoppable)
Register process to stop on reload

Parameters:
  `stoppable` - The `Stoppable` to be registered

### getStoppables

public List<Stoppable> getStoppables()

Returns:
  copy of list of `Stoppable`s

### setMenuItemLoggerPanel

public void setMenuItemLoggerPanel(JCheckBoxMenuItem menuItemLoggerPanel)
Set the menu item LoggerPanel.

Parameters:
  `menuItemLoggerPanel` - The menu item LoggerPanel

### getMenuItemLoggerPanel

public JCheckBoxMenuItem getMenuItemLoggerPanel()
Get the menu item LoggerPanel.

Returns:
  the menu item LoggerPanel

### setMenuItemSaveBeforeRunPanel

public void setMenuItemSaveBeforeRunPanel(JCheckBoxMenuItem menuItemSaveBeforeRunPanel)
Set the menu item SaveBeforeRunPanel.

Parameters:
  `menuItemSaveBeforeRunPanel` - The menu item SaveBeforeRunPanel

### getMenuItemSaveBeforeRunPanel

public JCheckBoxMenuItem getMenuItemSaveBeforeRunPanel()
Get the menu item SaveBeforeRunPanel.

Returns:
  the menu item SaveBeforeRunPanel

### setLoggerPanel

public void setLoggerPanel(LoggerPanel loggerPanel)

Parameters:
  `loggerPanel` - LoggerPanel

### getLoggerPanel

public LoggerPanel getLoggerPanel()

Returns:
  the loggerPanel

### undo

public void undo()
Navigate back through undo history

### redo

public void redo()
Navigate forward through undo history

### canRedo

public boolean canRedo()

Returns:
  true if history contains redo item

### canUndo

public boolean canUndo()

Returns:
  true if history contains undo item

### notifyChangeInHistory

public void notifyChangeInHistory(UndoHistory history)
Called when history changes, it updates toolbar

Specified by:
  `notifyChangeInHistory` in interface `UndoHistory.HistoryListener`

### getNamingPolicy

public TreeNodeNamingPolicy getNamingPolicy()

Returns:
  `TreeNodeNamingPolicy`

### getLogEventBus

public GuiLogEventBus getLogEventBus()
Return `GuiLogEventBus`.

Returns:
  `GuiLogEventBus`

### beginUndoTransaction

public void beginUndoTransaction()
Begin a group of actions modeled as 1 undo

### endUndoTransaction

public void endUndoTransaction()
End a group of actions modeled as 1 undo

### shouldSaveBeforeRunByPreference

public boolean shouldSaveBeforeRunByPreference()
Should Save Before Run by Preference Only

Returns:
  boolean

### setSaveBeforeRunByPreference

public void setSaveBeforeRunByPreference(boolean saveBeforeRun)
Should Save Before Run by Preference Only

Parameters:
  `saveBeforeRun` - boolean

### shouldSaveBeforeRun

public boolean shouldSaveBeforeRun()
Should Save Before Run Decide by Preference and if not exists by Property

Returns:
  boolean Should Save Before Run

### addTestPlanListener

public void addTestPlanListener(TestPlanListener listener)
Adds a test plan listener.

Parameters:
  `listener` - to add

### removeTestPlanListener

public void removeTestPlanListener(TestPlanListener listener)
Removes a test plan listener.

Parameters:
  `listener` - to remove