Search in sources :

Example 31 with JMeterTreeNode

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

the class MainFrame method addQuickComponentHotkeys.

private void addQuickComponentHotkeys(JTree treevar) {
    Action quickComponent = new AbstractAction("Quick Component") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String propname = "gui.quick_" + actionEvent.getActionCommand();
            String comp = JMeterUtils.getProperty(propname);
            log.debug("Event {}: {}", propname, comp);
            if (comp == null) {
                log.warn("No component set through property: {}", propname);
                return;
            }
            GuiPackage guiPackage = GuiPackage.getInstance();
            try {
                guiPackage.updateCurrentNode();
                TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp));
                JMeterTreeNode parentNode = guiPackage.getCurrentNode();
                while (!MenuFactory.canAddTo(parentNode, testElement)) {
                    parentNode = (JMeterTreeNode) parentNode.getParent();
                }
                if (parentNode.getParent() == null) {
                    log.debug("Cannot add element on very top level");
                } else {
                    JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
                    guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
                }
            } catch (Exception err) {
                // $NON-NLS-1$
                log.warn("Failed to perform quick component add: {}", comp, err);
            }
        }
    };
    InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9 };
    for (int n = 0; n < keyStrokes.length; n++) {
        treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
        inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) TreePath(javax.swing.tree.TreePath) KeyStroke(javax.swing.KeyStroke) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 32 with JMeterTreeNode

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

the class ApplyNamingConvention method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
    if (!(currentNode.getUserObject() instanceof Controller)) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    try {
        applyNamingPolicyToCurrentNode(guiPackage, currentNode);
    } catch (Exception err) {
        Toolkit.getDefaultToolkit().beep();
        log.error("Failed to apply naming policy", err);
        JMeterUtils.reportErrorToUser("Failed to apply naming policy", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Controller(org.apache.jmeter.control.Controller)

Example 33 with JMeterTreeNode

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

the class ChangeParent method changeParent.

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));
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Controller(org.apache.jmeter.control.Controller)

Example 34 with JMeterTreeNode

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

the class ChangeParent method doAction.

@Override
public void doAction(ActionEvent e) {
    String name = ((Component) e.getSource()).getName();
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
    if (!(currentNode.getUserObject() instanceof Controller)) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    try {
        guiPackage.updateCurrentNode();
        TestElement controller = guiPackage.createTestElement(name);
        changeParent(controller, guiPackage, currentNode);
    } catch (Exception err) {
        Toolkit.getDefaultToolkit().beep();
        log.error("Failed to change parent", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Component(java.awt.Component) Controller(org.apache.jmeter.control.Controller) TestElement(org.apache.jmeter.testelement.TestElement)

Example 35 with JMeterTreeNode

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

the class UndoHistory method add.

/**
     * Add tree model copy to the history
     * <p>
     * This method relies on the rule that the record in history made AFTER
     * change has been made to test plan
     *
     * @param treeModel JMeterTreeModel
     * @param comment   String
     */
public void add(JMeterTreeModel treeModel, String comment) {
    if (!isEnabled()) {
        log.debug("undo.history.size is set to 0, undo/redo feature is disabled");
        return;
    }
    // don't add element if we are in the middle of undo/redo or a big loading
    if (working) {
        log.debug("Not adding history because of noop");
        return;
    }
    JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
    if (root.getChildCount() < 1) {
        log.debug("Not adding history because of no children");
        return;
    }
    String name = root.getName();
    log.debug("Adding history element {}: {}", name, comment);
    working = true;
    // get test plan tree
    HashTree tree = treeModel.getCurrentSubTree((JMeterTreeNode) treeModel.getRoot());
    // first clone to not convert original tree
    tree = (HashTree) tree.getTree(tree.getArray()[0]).clone();
    position++;
    while (history.size() > position) {
        if (log.isDebugEnabled()) {
            log.debug("Removing further record, position: {}, size: {}", position, history.size());
        }
        history.remove(history.size() - 1);
    }
    // cloning is required because we need to immute stored data
    HashTree copy = UndoCommand.convertAndCloneSubTree(tree);
    history.add(new UndoHistoryItem(copy, comment));
    log.debug("Added history element, position: {}, size: {}", position, history.size());
    working = false;
    notifyListeners();
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) 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