private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final) setLayout(new VerticalLayout(5, VerticalLayout.BOTH, VerticalLayout.TOP)); setBorder(makeBorder()); add(makeTitlePanel()); JPanel modulesPanel = new JPanel(); expandButton = new JButton(JMeterUtils.getResString("find_target_element")); //$NON-NLS-1$ expandButton.addActionListener(this); modulesPanel.add(expandButton); modulesPanel.setLayout(new BoxLayout(modulesPanel, BoxLayout.Y_AXIS)); modulesPanel.add(Box.createRigidArea(new Dimension(0,5))); JLabel nodesLabel = new JLabel(JMeterUtils.getResString("module_controller_module_to_run")); // $NON-NLS-1$ modulesPanel.add(nodesLabel); modulesPanel.add(warningLabel); add(modulesPanel); JPanel treePanel = new JPanel(); treePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); treePanel.add(moduleToRunTreeNodes); add(treePanel); }
/** {@inheritDoc}} */ @Override public void modifyTestElement(TestElement element) { configureTestElement(element); JMeterTreeNode tn = null; DefaultMutableTreeNode lastSelected = (DefaultMutableTreeNode) this.moduleToRunTreeNodes.getLastSelectedPathComponent(); if (lastSelected != null && lastSelected.getUserObject() instanceof JMeterTreeNode) { tn = (JMeterTreeNode) lastSelected.getUserObject(); } if (tn != null) { selected = tn; // prevent from selecting thread group or test plan elements if (isTestElementAllowed(selected.getTestElement())) { ((ModuleController) element).setSelectedNode(selected); } } }
/** * Expand module to run tree to selected JMeterTreeNode and set selection path to it * @param selected - referenced module to run */ private void focusSelectedOnTree(JMeterTreeNode selected) { TreeNode[] path = selected.getPath(); TreeNode[] filteredPath = new TreeNode[path.length-1]; //ignore first element of path - WorkBench, (why WorkBench is appearing in the path ???) System.arraycopy(path, 1, filteredPath, 0, path.length - 1); DefaultMutableTreeNode root = (DefaultMutableTreeNode) moduleToRunTreeNodes.getModel().getRoot(); //treepath of test plan tree and module to run tree cannot be compared directly - moduleToRunTreeModel.getPathToRoot() //custom method for finding an JMeterTreeNode element in DefaultMutableTreeNode have to be used TreeNode[] dmtnPath = this.findPathInTreeModel(1, filteredPath, root); if (dmtnPath.length > 0) { TreePath treePath = new TreePath(dmtnPath); moduleToRunTreeNodes.setSelectionPath(treePath); moduleToRunTreeNodes.scrollPathToVisible(treePath); } }
/** {@inheritDoc}} */ @Override public void configure(TestElement el) { super.configure(el); hasAtLeastOneController = false; ModuleController controller = (ModuleController) el; this.selected = controller.getSelectedNode(); if (selected == null && controller.getNodePath() != null) { warningLabel.setText(JMeterUtils.getResString("module_controller_warning") // $NON-NLS-1$ + renderPath(controller.getNodePath())); warningLabel.setVisible(true); expandButton.setEnabled(false); } else { warningLabel.setVisible(false); expandButton.setEnabled(true); } reinitialize(); }
/** * Reinitializes the visual representation of JMeter Tree keeping only the Controllers, Test Fragment, Thread Groups, Test Plan * <ol> * <li>Rebuilds moduleToRunTreeModel</li> * <li>selects the node referenced by ModuleController</li> * <li>Updates warning label</li> * </ol> */ private void reinitialize() { ((DefaultMutableTreeNode) moduleToRunTreeModel.getRoot()).removeAllChildren(); GuiPackage gp = GuiPackage.getInstance(); JMeterTreeNode root; if (gp != null) { root = (JMeterTreeNode) GuiPackage.getInstance().getTreeModel().getRoot(); buildTreeNodeModel(root, 0, null); moduleToRunTreeModel.nodeStructureChanged((TreeNode) moduleToRunTreeModel.getRoot()); } if (selected != null) { //expand Module to run tree to selected node and set selection path to it this.focusSelectedOnTree(selected); } if (!hasAtLeastOneController) { warningLabel.setText(JMeterUtils.getResString("module_controller_warning_no_controller")); warningLabel.setVisible(true); } }
/** {@inheritDoc}} */ @Override public TestElement createTestElement() { ModuleController mc = new ModuleController(); configureTestElement(mc); if (selected != null) { mc.setSelectedNode(selected); } return mc; }
warningLabel.setVisible(false); init();
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(cur); parent.add(newNode); buildTreeNodeModel(cur, level + 1, newNode); final boolean isController = te instanceof Controller && !(te instanceof ModuleController ((DefaultMutableTreeNode) moduleToRunTreeModel.getRoot()) .setUserObject(cur); buildTreeNodeModel(cur, level, (DefaultMutableTreeNode) moduleToRunTreeModel.getRoot());
return child.getPath(); } else { return findPathInTreeModel(level + 1, testPlanPath, child);