Search in sources :

Example 1 with WorkBench

use of org.apache.jmeter.testelement.WorkBench in project jmeter by apache.

the class JMeterTreeModel method addSubTree.

/**
     * Adds the sub tree at the given node. Returns a boolean indicating whether
     * the added sub tree was a full test plan.
     * 
     * @param subTree
     *            The {@link HashTree} which is to be inserted into
     *            <code>current</code>
     * @param current
     *            The node in which the <code>subTree</code> is to be inserted.
     *            Will be overridden, when an instance of {@link TestPlan} or
     *            {@link WorkBench} is found in the subtree.
     * @return newly created sub tree now found at <code>current</code>
     * @throws IllegalUserActionException
     *             when <code>current</code> is not an instance of
     *             {@link AbstractConfigGui} and no instance of {@link TestPlan}
     *             or {@link WorkBench} could be found in the
     *             <code>subTree</code>
     */
public HashTree addSubTree(HashTree subTree, JMeterTreeNode current) throws IllegalUserActionException {
    for (Object o : subTree.list()) {
        TestElement item = (TestElement) o;
        if (item instanceof TestPlan) {
            TestPlan tp = (TestPlan) item;
            current = (JMeterTreeNode) ((JMeterTreeNode) getRoot()).getChildAt(0);
            final TestPlan userObject = (TestPlan) current.getUserObject();
            userObject.addTestElement(item);
            userObject.setName(item.getName());
            userObject.setFunctionalMode(tp.isFunctionalMode());
            userObject.setSerialized(tp.isSerialized());
            addSubTree(subTree.getTree(item), current);
        } else if (item instanceof WorkBench) {
            current = (JMeterTreeNode) ((JMeterTreeNode) getRoot()).getChildAt(1);
            final TestElement testElement = (TestElement) current.getUserObject();
            testElement.addTestElement(item);
            testElement.setName(item.getName());
            addSubTree(subTree.getTree(item), current);
        } else {
            addSubTree(subTree.getTree(item), addComponent(item, current));
        }
    }
    return getCurrentSubTree(current);
}
Also used : TestPlan(org.apache.jmeter.testelement.TestPlan) TestElement(org.apache.jmeter.testelement.TestElement) WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 2 with WorkBench

use of org.apache.jmeter.testelement.WorkBench in project jmeter by apache.

the class Load method insertLoadedTree.

/**
     * Inserts (or merges) the tree into the GUI.
     * Does not check if the previous tree has been saved.
     * Clears the existing GUI test plan if we are inserting a complete plan.
     * @param id the id for the ActionEvent that is created
     * @param tree the tree to load
     * @param merging true if the tree is to be merged; false if it is to replace the existing tree
     * @return true if the loaded tree was a full test plan
     * @throws IllegalUserActionException if the tree cannot be merged at the selected position or the tree is empty
     */
// Does not appear to be used externally; called by #loadProjectFile()
public static boolean insertLoadedTree(final int id, final HashTree tree, final boolean merging) throws IllegalUserActionException {
    if (tree == null) {
        throw new IllegalUserActionException("Empty TestPlan or error reading test plan - see log file");
    }
    final boolean isTestPlan = tree.getArray()[0] instanceof TestPlan;
    // If we are loading a new test plan, initialize the tree with the testplan node we are loading
    final GuiPackage guiInstance = GuiPackage.getInstance();
    if (isTestPlan && !merging) {
        // Why does this not call guiInstance.clearTestPlan() ?
        // Is there a reason for not clearing everything?
        guiInstance.clearTestPlan((TestElement) tree.getArray()[0]);
    }
    if (merging) {
        // Check if target of merge is reasonable
        final TestElement te = (TestElement) tree.getArray()[0];
        if (!(te instanceof WorkBench || te instanceof TestPlan)) {
            // These are handled specially by addToTree
            final boolean ok = MenuFactory.canAddTo(guiInstance.getCurrentNode(), te);
            if (!ok) {
                String name = te.getName();
                String className = te.getClass().getName();
                className = className.substring(className.lastIndexOf('.') + 1);
                throw new IllegalUserActionException("Can't merge " + name + " (" + className + ") here");
            }
        }
    }
    final HashTree newTree = guiInstance.addSubTree(tree);
    guiInstance.updateCurrentGui();
    guiInstance.getMainFrame().getTree().setSelectionPath(new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
    final HashTree subTree = guiInstance.getCurrentSubTree();
    // Send different event wether we are merging a test plan into another test plan,
    // or loading a testplan from scratch
    ActionEvent actionEvent = new ActionEvent(subTree.get(subTree.getArray()[subTree.size() - 1]), id, merging ? ActionNames.SUB_TREE_MERGED : ActionNames.SUB_TREE_LOADED);
    ActionRouter.getInstance().actionPerformed(actionEvent);
    final JTree jTree = guiInstance.getMainFrame().getTree();
    if (EXPAND_TREE && !merging) {
        // don't automatically expand when merging
        for (int i = 0; i < jTree.getRowCount(); i++) {
            jTree.expandRow(i);
        }
    } else {
        jTree.expandRow(0);
    }
    jTree.setSelectionPath(jTree.getPathForRow(1));
    FocusRequester.requestFocus(jTree);
    return isTestPlan;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) TestPlan(org.apache.jmeter.testelement.TestPlan) ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) WorkBench(org.apache.jmeter.testelement.WorkBench) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 3 with WorkBench

use of org.apache.jmeter.testelement.WorkBench in project jmeter by apache.

the class WorkBenchGui method configure.

/**
     * A newly created component can be initialized with the contents of a Test
     * Element object by calling this method. The component is responsible for
     * querying the Test Element object for the relevant information to display
     * in its GUI.
     *
     * @param el
     *            the TestElement to configure
     */
@Override
public void configure(TestElement el) {
    super.configure(el);
    if (el instanceof WorkBench) {
        WorkBench tp = (WorkBench) el;
        saveWorkBench.setSelected(tp.getSaveWorkBench());
    }
}
Also used : WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 4 with WorkBench

use of org.apache.jmeter.testelement.WorkBench in project jmeter by apache.

the class WorkBenchGui method createTestElement.

/* Implements JMeterGUIComponent.createTestElement() */
@Override
public TestElement createTestElement() {
    WorkBench wb = new WorkBench();
    modifyTestElement(wb);
    return wb;
}
Also used : WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 5 with WorkBench

use of org.apache.jmeter.testelement.WorkBench in project jmeter by apache.

the class NamePanel method createTestElement.

/** {@inheritDoc} */
@Override
public TestElement createTestElement() {
    WorkBench wb = new WorkBench();
    modifyTestElement(wb);
    return wb;
}
Also used : WorkBench(org.apache.jmeter.testelement.WorkBench)

Aggregations

WorkBench (org.apache.jmeter.testelement.WorkBench)7 TestElement (org.apache.jmeter.testelement.TestElement)4 TestPlan (org.apache.jmeter.testelement.TestPlan)4 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 ActionEvent (java.awt.event.ActionEvent)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 Controller (org.apache.jmeter.control.Controller)1 TreeNodeWrapper (org.apache.jmeter.control.gui.TreeNodeWrapper)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 GuiPackage (org.apache.jmeter.gui.GuiPackage)1 RecordingController (org.apache.jmeter.protocol.http.control.RecordingController)1 HashTree (org.apache.jorphan.collections.HashTree)1