throw new Exception("Error in TestPlan - see log file");
}
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
GuiPackage guiInstance = GuiPackage.getInstance();
if(isTestPlan && !merging) {
guiInstance.clearTestPlan((TestElement)tree.getArray()[0]);
}
if (merging){ // Check if target of merge is reasonable
TestElement te = (TestElement)tree.getArray()[0];
if (!(te instanceof WorkBench || te instanceof TestPlan)){// These are handled specially by addToTree
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");
}
}
}
HashTree newTree = guiInstance.addSubTree(tree);
guiInstance.updateCurrentGui();
guiInstance.getMainFrame().getTree().setSelectionPath(
new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
tree = guiInstance.getCurrentSubTree();
// Send different event wether we are merging a test plan into another test plan,
// or loading a testplan from scratch
ActionEvent actionEvent = null;
if(!merging) {
actionEvent = new ActionEvent(tree.get(tree.getArray()[tree.size() - 1]), id, ActionNames.SUB_TREE_LOADED);
}
else {
actionEvent = new ActionEvent(tree.get(tree.getArray()[tree.size() - 1]), id, ActionNames.SUB_TREE_MERGED);
}
ActionRouter.getInstance().actionPerformed(actionEvent);
if (expandTree && !merging) { // don't automatically expand when merging
JTree jTree = guiInstance.getMainFrame().getTree();
for(int i = 0; i < jTree.getRowCount(); i++) {
jTree.expandRow(i);
}
}