use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class GuiPackage method createTestElement.
/**
* Create a TestElement corresponding to the specified GUI class.
*
* @param guiClass
* the fully qualified class name of the GUI component or a
* TestBean class for TestBeanGUIs.
* @param testClass
* the fully qualified class name of the test elements edited by
* this GUI component.
* @return the test element corresponding to the specified GUI class.
*/
public TestElement createTestElement(Class<?> guiClass, Class<?> testClass) {
try {
JMeterGUIComponent comp = getGuiFromCache(guiClass, testClass);
comp.clearGui();
TestElement node = comp.createTestElement();
nodesToGui.put(node, comp);
return node;
} catch (Exception e) {
log.error("Problem retrieving gui", e);
return null;
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class GuiPackage method refreshCurrentGui.
/**
* Refresh GUI from node state.
* This method does not update the current node from GUI at the
* difference of {@link GuiPackage#updateCurrentGui()}
*/
public void refreshCurrentGui() {
currentNode = treeListener.getCurrentNode();
TestElement element = currentNode.getTestElement();
JMeterGUIComponent comp = getGui(element);
if (comp == null) {
log.debug("No component found for {}", currentNode.getName());
return;
}
comp.configure(element);
currentNodeUpdated = false;
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class MainFrame method addQuickComponentHotkeys.
private void addQuickComponentHotkeys(JTree treevar) {
Action quickComponent = new AbstractAction("Quick Component") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
String propname = "gui.quick_" + actionEvent.getActionCommand();
String comp = JMeterUtils.getProperty(propname);
log.debug("Event {}: {}", propname, comp);
if (comp == null) {
log.warn("No component set through property: {}", propname);
return;
}
GuiPackage guiPackage = GuiPackage.getInstance();
try {
guiPackage.updateCurrentNode();
TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp));
JMeterTreeNode parentNode = guiPackage.getCurrentNode();
while (!MenuFactory.canAddTo(parentNode, testElement)) {
parentNode = (JMeterTreeNode) parentNode.getParent();
}
if (parentNode.getParent() == null) {
log.debug("Cannot add element on very top level");
} else {
JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
}
} catch (Exception err) {
// $NON-NLS-1$
log.warn("Failed to perform quick component add: {}", comp, err);
}
}
};
InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9 };
for (int n = 0; n < keyStrokes.length; n++) {
treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class ChangeParent method doAction.
@Override
public void doAction(ActionEvent e) {
String name = ((Component) e.getSource()).getName();
GuiPackage guiPackage = GuiPackage.getInstance();
JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
if (!(currentNode.getUserObject() instanceof Controller)) {
Toolkit.getDefaultToolkit().beep();
return;
}
try {
guiPackage.updateCurrentNode();
TestElement controller = guiPackage.createTestElement(name);
changeParent(controller, guiPackage, currentNode);
} catch (Exception err) {
Toolkit.getDefaultToolkit().beep();
log.error("Failed to change parent", err);
}
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestCompiler method subtractNode.
/** {@inheritDoc} */
@Override
public void subtractNode() {
if (log.isDebugEnabled()) {
log.debug("Subtracting node, stack size = {}", stack.size());
}
TestElement child = stack.getLast();
trackIterationListeners(stack);
if (child instanceof Sampler) {
saveSamplerConfigs((Sampler) child);
} else if (child instanceof TransactionController) {
saveTransactionControllerConfigs((TransactionController) child);
}
stack.removeLast();
if (!stack.isEmpty()) {
TestElement parent = stack.getLast();
boolean duplicate = false;
// Bug 53750: this condition used to be in ObjectPair#addTestElements()
if (parent instanceof Controller && (child instanceof Sampler || child instanceof Controller)) {
if (parent instanceof TestCompilerHelper) {
TestCompilerHelper te = (TestCompilerHelper) parent;
duplicate = !te.addTestElementOnce(child);
} else {
// this is only possible for 3rd party controllers by default
ObjectPair pair = new ObjectPair(child, parent);
synchronized (PAIRING) {
// Called from multiple threads
if (!PAIRING.contains(pair)) {
parent.addTestElement(child);
PAIRING.add(pair);
} else {
duplicate = true;
}
}
}
}
if (duplicate) {
if (log.isWarnEnabled()) {
log.warn("Unexpected duplicate for {} and {}", parent.getClass(), child.getClass());
}
}
}
}
Aggregations