use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class ProxyControl method placeSampler.
private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, JMeterTreeNode myTarget) {
try {
final JMeterTreeModel treeModel = getJmeterTreeModel();
boolean firstInBatch = false;
long now = System.currentTimeMillis();
long deltaT = now - lastTime;
int cachedGroupingMode = groupingMode;
if (deltaT > SAMPLE_GAP) {
if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
addDivider(treeModel, myTarget);
}
if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
addSimpleController(treeModel, myTarget, sampler.getName());
}
if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
addTransactionController(treeModel, myTarget, sampler.getName());
}
// Remember this was first in its batch
firstInBatch = true;
}
if (lastTime == 0) {
// Decent value for timers
deltaT = 0;
}
lastTime = now;
if (cachedGroupingMode == GROUPING_STORE_FIRST_ONLY) {
if (!firstInBatch) {
// Huh! don't store this one!
return;
}
// If we're not storing subsequent samplers, we'll need the
// first sampler to do all the work...:
sampler.setFollowRedirects(true);
sampler.setImageParser(true);
}
if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS || cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
// sampler there:
for (int i = myTarget.getChildCount() - 1; i >= 0; i--) {
JMeterTreeNode c = (JMeterTreeNode) myTarget.getChildAt(i);
if (c.getTestElement() instanceof GenericController) {
myTarget = c;
break;
}
}
}
final long deltaTFinal = deltaT;
final boolean firstInBatchFinal = firstInBatch;
final JMeterTreeNode myTargetFinal = myTarget;
JMeterUtils.runSafe(true, () -> {
try {
final JMeterTreeNode newNode = treeModel.addComponent(sampler, myTargetFinal);
if (firstInBatchFinal) {
if (addAssertions) {
addAssertion(treeModel, newNode);
}
addTimers(treeModel, newNode, deltaTFinal);
}
if (testElements != null) {
for (TestElement testElement : testElements) {
if (isAddableTestElement(testElement)) {
treeModel.addComponent(testElement, newNode);
}
}
}
} catch (IllegalUserActionException e) {
log.error("Error placing sampler", e);
JMeterUtils.reportErrorToUser(e.getMessage());
}
});
} catch (Exception e) {
log.error("Error placing sampler", e);
JMeterUtils.reportErrorToUser(e.getMessage());
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class RecordController method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == clearButton) {
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
if (!(currentNode.getUserObject() instanceof org.apache.jmeter.protocol.http.control.RecordingController)) {
Toolkit.getDefaultToolkit().beep();
return;
}
try {
guiPackage.updateCurrentNode();
JMeterTreeModel treeModel = guiPackage.getTreeModel();
int childCount = currentNode.getChildCount();
for (int i = 0; i < childCount; i++) {
JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
treeModel.removeNodeFromParent(node);
}
} catch (Exception err) {
Toolkit.getDefaultToolkit().beep();
log.error("Error while removing recorded samples", err);
}
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class UndoHistory method treeNodesChanged.
/**
* Record the changes in the node as the undo step
*
* @param tme {@link TreeModelEvent} with event details
*/
@Override
public void treeNodesChanged(TreeModelEvent tme) {
String name = ((JMeterTreeNode) tme.getTreePath().getLastPathComponent()).getName();
log.debug("Nodes changed {}", name);
final JMeterTreeModel sender = (JMeterTreeModel) tme.getSource();
add(sender, "Node changed " + name);
}
use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.
the class Duplicate method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage instance = GuiPackage.getInstance();
JMeterTreeListener treeListener = instance.getTreeListener();
JMeterTreeNode[] copiedNodes = Copy.cloneTreeNodes(treeListener.getSelectedNodes());
JMeterTreeNode currentNode = treeListener.getCurrentNode();
JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
JMeterTreeModel treeModel = instance.getTreeModel();
for (JMeterTreeNode copiedNode : copiedNodes) {
int index = parentNode.getIndex(currentNode) + 1;
treeModel.insertNodeInto(copiedNode, parentNode, index);
}
instance.getMainFrame().repaint();
}
Aggregations