}
private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] subConfigs,
JMeterTreeNode myTarget) {
try {
final JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
boolean firstInBatch = false;
long now = System.currentTimeMillis();
long deltaT = now - lastTime;
int cachedGroupingMode = groupingMode.get();
if (deltaT > sampleGap) {
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());
}
firstInBatch = true;// Remember this was first in its batch
}
if (lastTime == 0) {
deltaT = 0; // Decent value for timers
}
lastTime = now;
if (cachedGroupingMode == GROUPING_STORE_FIRST_ONLY) {
if (!firstInBatch) {
return; // Huh! don't store this one!
}
// 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) {
// Find the last controller in the target to store the
// 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(new Runnable() {
@Override
public void run() {
try {
final JMeterTreeNode newNode = treeModel.addComponent(sampler, myTargetFinal);
if (firstInBatchFinal) {
if (addAssertions.get()) {
addAssertion(treeModel, newNode);
}
addTimers(treeModel, newNode, deltaTFinal);
}
for (int i = 0; subConfigs != null && i < subConfigs.length; i++) {
if (subConfigs[i] instanceof HeaderManager) {
final TestElement headerManager = subConfigs[i];
headerManager.setProperty(TestElement.GUI_CLASS, HEADER_PANEL);
treeModel.addComponent(headerManager, newNode);
}
}
} catch (IllegalUserActionException e) {
JMeterUtils.reportErrorToUser(e.getMessage());
}