Search in sources :

Example 6 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ModuleController method cloneChildren.

private static void cloneChildren(JMeterTreeNode to, JMeterTreeNode from) {
    Enumeration<JMeterTreeNode> enumr = from.children();
    while (enumr.hasMoreElements()) {
        JMeterTreeNode child = enumr.nextElement();
        JMeterTreeNode childClone = (JMeterTreeNode) child.clone();
        childClone.setUserObject(((TestElement) child.getUserObject()).clone());
        to.add(childClone);
        cloneChildren((JMeterTreeNode) to.getLastChild(), child);
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 7 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class Save method convertSubTree.

// package protected to allow access from test code
void convertSubTree(HashTree tree) {
    for (Object o : new LinkedList<>(tree.list())) {
        JMeterTreeNode item = (JMeterTreeNode) o;
        convertSubTree(tree.getTree(item));
        // requires JMeterTreeNode
        TestElement testElement = item.getTestElement();
        tree.replaceKey(item, testElement);
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) LinkedList(java.util.LinkedList)

Example 8 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class SearchTreeDialog method doSearch.

/**
     * @param e {@link ActionEvent}
     */
private void doSearch(ActionEvent e) {
    boolean expand = e.getSource() == searchAndExpandButton;
    String wordToSearch = searchTF.getText();
    if (StringUtils.isEmpty(wordToSearch)) {
        return;
    } else {
        this.lastSearch = wordToSearch;
    }
    // reset previous result
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SEARCH_RESET));
    // do search
    Searcher searcher = null;
    if (isRegexpCB.isSelected()) {
        searcher = new RegexpSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText());
    } else {
        searcher = new RawTextSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText());
    }
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel();
    Set<JMeterTreeNode> nodes = new HashSet<>();
    int numberOfMatches = 0;
    for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) {
        try {
            Searchable searchable = (Searchable) jMeterTreeNode.getUserObject();
            List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup();
            List<String> searchableTokens = searchable.getSearchableTokens();
            boolean result = searcher.search(searchableTokens);
            if (result) {
                numberOfMatches++;
                nodes.addAll(matchingNodes);
            }
        } catch (Exception ex) {
            logger.error("Error occurred searching for word:" + wordToSearch + " in node:" + jMeterTreeNode.getName(), ex);
        }
    }
    GuiPackage guiInstance = GuiPackage.getInstance();
    JTree jTree = guiInstance.getMainFrame().getTree();
    for (JMeterTreeNode jMeterTreeNode : nodes) {
        jMeterTreeNode.setMarkedBySearch(true);
        if (expand) {
            jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
        }
    }
    GuiPackage.getInstance().getMainFrame().repaint();
    searchTF.requestFocusInWindow();
    statusLabel.setText(MessageFormat.format(JMeterUtils.getResString("search_tree_matches"), new Object[] { numberOfMatches }));
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Searchable(org.apache.jmeter.gui.Searchable) HashSet(java.util.HashSet)

Example 9 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class Start method doAction.

@Override
public void doAction(ActionEvent e) {
    if (e.getActionCommand().equals(ActionNames.ACTION_START)) {
        popupShouldSave(e);
        startEngine(false);
    } else if (e.getActionCommand().equals(ActionNames.ACTION_START_NO_TIMERS)) {
        popupShouldSave(e);
        startEngine(true);
    } else if (e.getActionCommand().equals(ActionNames.ACTION_STOP)) {
        if (engine != null) {
            log.info("Stopping test");
            GuiPackage.getInstance().getMainFrame().showStoppingMessage("");
            engine.stopTest();
        }
    } else if (e.getActionCommand().equals(ActionNames.ACTION_SHUTDOWN)) {
        if (engine != null) {
            log.info("Shutting test down");
            GuiPackage.getInstance().getMainFrame().showStoppingMessage("");
            engine.askThreadsToStop();
        }
    } else if (e.getActionCommand().equals(ActionNames.RUN_TG) || e.getActionCommand().equals(ActionNames.RUN_TG_NO_TIMERS) || e.getActionCommand().equals(ActionNames.VALIDATE_TG)) {
        popupShouldSave(e);
        boolean noTimers = e.getActionCommand().equals(ActionNames.RUN_TG_NO_TIMERS);
        boolean isValidation = e.getActionCommand().equals(ActionNames.VALIDATE_TG);
        JMeterTreeListener treeListener = GuiPackage.getInstance().getTreeListener();
        JMeterTreeNode[] nodes = treeListener.getSelectedNodes();
        nodes = Copy.keepOnlyAncestors(nodes);
        AbstractThreadGroup[] tg = keepOnlyThreadGroups(nodes);
        if (nodes.length > 0) {
            startEngine(noTimers, isValidation, tg);
        } else {
            log.warn("No thread group selected the test will not be started");
        }
    }
}
Also used : JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 10 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class Remove method doAction.

@Override
public void doAction(ActionEvent e) {
    int isConfirm = SKIP_CONFIRM ? JOptionPane.YES_OPTION : JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), // $NON-NLS-1$
    JMeterUtils.getResString("remove_confirm_msg"), // $NON-NLS-1$
    JMeterUtils.getResString("remove_confirm_title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (isConfirm == JOptionPane.YES_OPTION) {
        // TODO - removes the nodes from the CheckDirty map - should it be done later, in case some can't be removed?
        ActionRouter.getInstance().actionPerformed(new ActionEvent(e.getSource(), e.getID(), ActionNames.CHECK_REMOVE));
        GuiPackage guiPackage = GuiPackage.getInstance();
        JMeterTreeNode[] nodes = guiPackage.getTreeListener().getSelectedNodes();
        // Save parent node for later
        TreePath newTreePath = guiPackage.getTreeListener().removedSelectedNode();
        for (int i = nodes.length - 1; i >= 0; i--) {
            removeNode(nodes[i]);
        }
        guiPackage.getTreeListener().getJTree().setSelectionPath(newTreePath);
        guiPackage.updateCurrentGui();
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Aggregations

JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)68 GuiPackage (org.apache.jmeter.gui.GuiPackage)21 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)18 TestElement (org.apache.jmeter.testelement.TestElement)18 TreePath (javax.swing.tree.TreePath)10 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)10 IOException (java.io.IOException)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)7 TestPlan (org.apache.jmeter.testelement.TestPlan)7 HashTree (org.apache.jorphan.collections.HashTree)7 ActionEvent (java.awt.event.ActionEvent)6 JTree (javax.swing.JTree)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)6 TreeNode (javax.swing.tree.TreeNode)5 LinkedList (java.util.LinkedList)4 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)4