@Override public void doAction(ActionEvent e) throws IllegalUserActionException { if (!commands.contains(e.getActionCommand())) { throw new IllegalUserActionException("Invalid user command:" + e.getActionCommand()); } if (e.getActionCommand().equals(ActionNames.SAVE_GRAPHICS)) { JMeterGUIComponent component = GuiPackage.getInstance().getCurrentGui(); // get the JComponent from the visualizer if (component instanceof Printable) { JComponent comp = ((Printable) component).getPrintableComponent(); saveImage(comp); } } if (e.getActionCommand().equals(ActionNames.SAVE_GRAPHICS_ALL)) { JMeterGUIComponent component = GuiPackage.getInstance().getCurrentGui(); JComponent comp = ((JComponent) component).getRootPane(); saveImage(comp); } }
TestBeanGUI testBeanGUI = (TestBeanGUI) GuiPackage.getInstance().getCurrentGui(); Field customizer = TestBeanGUI.class.getDeclaredField(PropsKeys.CUSTOMIZER); customizer.setAccessible(true);
/** * {@inheritDoc} */ @Override public void localeChanged(LocaleChangeEvent event) { // First make sure we save the content of the current GUI (since we // will flush it away): updateCurrentNode(); // Forget about all GUIs we've created so far: we'll need to re-created // them all! guis = new HashMap<>(); nodesToGui = new HashMap<>(); testBeanGUIs = new HashMap<>(); // BeanInfo objects also contain locale-sensitive data -- flush them // away: Introspector.flushCaches(); // Now put the current GUI in place. [This code was copied from the // EditCommand action -- we can't just trigger the action because that // would populate the current node with the contents of the new GUI -- // which is empty.] MainFrame mf = getMainFrame(); // Fetch once if (mf == null) { // Probably caused by unit testing on headless system log.warn("Mainframe is null"); } else { mf.setMainPanel((javax.swing.JComponent) getCurrentGui()); mf.setEditMenu(getTreeListener().getCurrentNode().createPopupMenu()); } }
@Override public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); final String actionCommand = e.getActionCommand(); if (actionCommand.equals(ActionNames.CLEAR)) { JMeterGUIComponent guiComp = guiPackage.getCurrentGui(); if (guiComp instanceof Clearable){ ((Clearable) guiComp).clearData(); } } else { guiPackage.getMainFrame().clearData(); for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) { JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement()); if (guiComp instanceof Clearable){ Clearable item = (Clearable) guiComp; try { item.clearData(); } catch (Exception ex) { log.error("Can't clear: {} {}", node, guiComp, ex); } } } } } }
KeyStrokes.SAVE_GRAPHICS); menu.add(savePicture); if (!(GuiPackage.getInstance().getCurrentGui() instanceof Printable)) { savePicture.setEnabled(false);
@Override public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); JMeterGUIComponent currentGui = guiPackage.getCurrentGui(); guiPackage.getMainFrame().setMainPanel((javax.swing.JComponent) currentGui); guiPackage.getMainFrame().setEditMenu(guiPackage.getTreeListener().getCurrentNode().createPopupMenu()); guiPackage.getMainFrame().setFileLoadEnabled(true); guiPackage.getMainFrame().setFileSaveEnabled(true); }
private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) { // keep the old name if it was not the default one Controller currentController = (Controller) currentNode.getUserObject(); JMeterGUIComponent currentGui = guiPackage.getCurrentGui(); String defaultName = JMeterUtils.getResString(currentGui.getLabelResource()); if(StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)){ newParent.setName(currentController.getName()); } JMeterTreeModel treeModel = guiPackage.getTreeModel(); JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel); JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent(); int index = parentNode.getIndex(currentNode); treeModel.insertNodeInto(newNode, parentNode, index); treeModel.removeNodeFromParent(currentNode); int childCount = currentNode.getChildCount(); for (int i = 0; i < childCount; i++) { // Using index 0 is voluntary as child is removed in next step and added to new parent JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0); treeModel.removeNodeFromParent(node); treeModel.insertNodeInto(node, newNode, newNode.getChildCount()); } // select the node TreeNode[] nodes = treeModel.getPathToRoot(newNode); JTree tree = guiPackage.getTreeListener().getJTree(); tree.setSelectionPath(new TreePath(nodes)); }
guicomp.configure(component); guicomp.modifyTestElement(component); guiPackage.getCurrentGui(); // put the gui object back