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);
}
}
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);
}
}
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 }));
}
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");
}
}
}
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();
}
}
Aggregations