Search in sources :

Example 6 with HashTree

use of org.apache.jorphan.collections.HashTree 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 7 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class RemoteStart method doAction.

@Override
public void doAction(ActionEvent e) {
    String name = ((Component) e.getSource()).getName();
    if (name != null) {
        name = name.trim();
    }
    String action = e.getActionCommand();
    if (action.equals(ActionNames.REMOTE_STOP)) {
        GuiPackage.getInstance().getMainFrame().showStoppingMessage(name);
        distributedRunner.stop(Arrays.asList(name));
    } else if (action.equals(ActionNames.REMOTE_SHUT)) {
        GuiPackage.getInstance().getMainFrame().showStoppingMessage(name);
        distributedRunner.shutdown(Arrays.asList(name));
    } else if (action.equals(ActionNames.REMOTE_START)) {
        popupShouldSave(e);
        HashTree testTree = getTestTree();
        if (popupCheckExistingFileListener(testTree)) {
            distributedRunner.init(Arrays.asList(name), testTree);
            distributedRunner.start(Arrays.asList(name));
        }
    } else if (action.equals(ActionNames.REMOTE_START_ALL)) {
        popupShouldSave(e);
        HashTree testTree = getTestTree();
        if (popupCheckExistingFileListener(testTree)) {
            distributedRunner.init(getRemoteHosts(), testTree);
            distributedRunner.start();
        }
    } else if (action.equals(ActionNames.REMOTE_STOP_ALL)) {
        distributedRunner.stop(getRemoteHosts());
    } else if (action.equals(ActionNames.REMOTE_SHUT_ALL)) {
        distributedRunner.shutdown(getRemoteHosts());
    } else if (action.equals(ActionNames.REMOTE_EXIT)) {
        distributedRunner.exit(Arrays.asList(name));
    } else if (action.equals(ActionNames.REMOTE_EXIT_ALL)) {
        distributedRunner.exit(getRemoteHosts());
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) Component(java.awt.Component)

Example 8 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class HashTreeConverter method unmarshal.

/** {@inheritDoc} */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    boolean isKey = true;
    Object current = null;
    HashTree tree = (HashTree) createCollection(context.getRequiredType());
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        Object item = readItem(reader, context, tree);
        if (isKey) {
            tree.add(item);
            current = item;
            isKey = false;
        } else {
            tree.set(current, (HashTree) item);
            isKey = true;
        }
        reader.moveUp();
    }
    return tree;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree)

Example 9 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class HashTreeConverter method marshal.

/** {@inheritDoc} */
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
    HashTree tree = (HashTree) arg0;
    for (Object item : tree.list()) {
        writeItem(item, context, writer);
        writeItem(tree.getTree(item), context, writer);
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree)

Example 10 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class GuiPackage method addSubTree.

/**
     * Add a subtree to the currently selected node.
     *
     * @param subTree
     *            the subtree to add.
     *
     * @return the resulting subtree starting with the currently selected node
     *
     * @throws IllegalUserActionException
     *             if a subtree cannot be added to the currently selected node
     */
public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException {
    HashTree hashTree = treeModel.addSubTree(subTree, treeListener.getCurrentNode());
    undoHistory.clear();
    undoHistory.add(this.treeModel, "Loaded tree");
    return hashTree;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree)

Aggregations

HashTree (org.apache.jorphan.collections.HashTree)24 File (java.io.File)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 IOException (java.io.IOException)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)5 ActionEvent (java.awt.event.ActionEvent)4 ConversionException (com.thoughtworks.xstream.converters.ConversionException)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3 TestElement (org.apache.jmeter.testelement.TestElement)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 SocketException (java.net.SocketException)2 LinkedList (java.util.LinkedList)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 ReplaceableController (org.apache.jmeter.control.ReplaceableController)2