org.apache.jmeter.gui.tree.JMeterTreeNode Java Examples

The following examples show how to use org.apache.jmeter.gui.tree.JMeterTreeNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private Map<JMeterTreeNode, Boolean> getChildItems(JMeterTreeNode root, WeightedSwitchController element) {
    Map<JMeterTreeNode, Boolean> result = new LinkedHashMap<>();
    for (int i = 0; i < root.getChildCount(); i++) {
        JMeterTreeNode child = (JMeterTreeNode) root.getChildAt(i);

        TestElement te = child.getTestElement();
        if (element != root.getTestElement()) {
            result.putAll(getChildItems(child, element));
        } else {
            if (te instanceof Sampler || te instanceof Controller) {
                result.put(child, te.isEnabled());
            }
        }
    }
    return result;
}
 
Example #2
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void clearRowsFromCompositeModels(String vizualizerName) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored removing from composite");
        return;
    }
    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        //System.out.println("obj");
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().clearRows(vizualizerName);
    }
}
 
Example #3
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void fillGridFromTree(WeightedSwitchController wsc, CollectionProperty oldData) {
    JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
    JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();

    Map<JMeterTreeNode, Boolean> childItems = getChildItems(root, wsc);
    for (JMeterTreeNode node : childItems.keySet()) {
        String w = "100";
        JMeterProperty row = getRowByName(node.getTestElement().getName(), oldData);
        if (row != null) {
            w = ((CollectionProperty) row).get(1).getStringValue();
        }
        grid.getModel().addRow(new String[]{node.getTestElement().getName(), w, childItems.get(node).toString()});
    }
}
 
Example #4
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void addRowToCompositeModels(String rowName, AbstractGraphRow row) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored adding to composite");
        return;
    }

    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().addRow(rowName, row);
    }
}
 
Example #5
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public TestProvider(String path, String name) throws IllegalUserActionException, IOException {
    File file = new File(this.getClass().getResource(path).getFile());
    String basedir = TestJMeterUtils.fixWinPath(file.getParentFile().getAbsolutePath());

    File f = new File(basedir + '/' + name);
    mdl.addSubTree(SaveService.loadTree(f), (JMeterTreeNode) mdl.getRoot());
}
 
Example #6
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public TestProvider() throws IllegalUserActionException, IOException {
    File file = new File(this.getClass().getResource("/com/blazemeter/jmeter/debugger/sample1.jmx").getFile());
    String basedir = TestJMeterUtils.fixWinPath(file.getParentFile().getAbsolutePath());

    File f = new File(basedir + "/sample1.jmx");
    mdl.addSubTree(SaveService.loadTree(f), (JMeterTreeNode) mdl.getRoot());
}
 
Example #7
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
    JMeterTreeNode node = (JMeterTreeNode) treeSelectionEvent.getPath().getLastPathComponent();
    TestElement wrpElm = node.getTestElement();
    if (wrpElm instanceof OriginalLink) {
        TestElement te = (TestElement) ((OriginalLink) wrpElm).getOriginal();
        if (!(te instanceof AbstractThreadGroup)) {
            wrpElm = te;
        }
    }

    displayElementGui(wrpElm);
}
 
Example #8
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void highlightNode(Component component, JMeterTreeNode node, TestElement mc) {
    component.setFont(component.getFont().deriveFont(~Font.BOLD).deriveFont(~Font.ITALIC));
    TestElement userObject = (TestElement) node.getUserObject();
    if (Debugger.isBreakpoint(userObject)) {
        component.setForeground(Color.RED);
    }

    if (debugger == null) {
        return;
    }

    Wrapper currentElement = debugger.getCurrentElement();
    if (currentElement == null) {
        return;
    }

    Font font = component.getFont();
    TestElement currentWrapped = (TestElement) currentElement.getWrappedElement();
    if (mc == currentElement || mc == currentWrapped) {
        setComponentStyle(component, font, Font.BOLD, Font.BOLD);
    }

    Sampler currentSampler = debugger.getCurrentSampler();
    if (mc == currentSampler) { // can this ever happen?
        setComponentStyle(component, font, Font.BOLD + Font.ITALIC, font.getStyle() | Font.ITALIC);
    } else if (currentSampler instanceof Wrapper && mc == ((Wrapper) currentSampler).getWrappedElement()) {
        setComponentStyle(component, font, Font.BOLD + Font.ITALIC, font.getStyle() | Font.ITALIC);
    }
}
 
Example #9
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void selectThreadGroup(AbstractThreadGroup tg) {
    debugger.selectThreadGroup(tg);
    treeModel.clearTestPlan();
    HashTree origTree = debugger.getSelectedTree();
    TreeCloner cloner = new TreeCloner();
    origTree.traverse(cloner);
    HashTree selectedTree = cloner.getClonedTree();

    // Hack to resolve ModuleControllers from JMeter.java
    SearchClass<ReplaceableController> replaceableControllers = new SearchClass<>(ReplaceableController.class);
    selectedTree.traverse(replaceableControllers);
    Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
    for (ReplaceableController replaceableController : replaceableControllersRes) {
        replaceableController.resolveReplacementSubTree((JMeterTreeNode) treeModel.getRoot());
    }

    JMeter.convertSubTree(selectedTree);
    try {
        treeModel.addSubTree(selectedTree, (JMeterTreeNode) treeModel.getRoot());
    } catch (IllegalUserActionException e) {
        throw new RuntimeException(e);
    }

    // select TG for visual convenience
    SearchByClass<DebuggingThreadGroup> tgs = new SearchByClass<>(DebuggingThreadGroup.class);
    selectedTree.traverse(tgs);
    for (DebuggingThreadGroup forSel : tgs.getSearchResults()) {
        Wrapper<AbstractThreadGroup> wtg = new ThreadGroupWrapper();
        wtg.setWrappedElement(forSel);
        selectTargetInTree(wtg);
    }
}
 
Example #10
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void clearListeners() {
    GuiPackage guiPackage = GuiPackage.getInstance();
    for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
        JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
        if (guiComp instanceof Clearable){
            Clearable item = (Clearable) guiComp;
            try {
                item.clearData();
            } catch (Exception ex) {
                log.error("Can't clear: {} {}", node, guiComp, ex);
            }
        }
    }
}
 
Example #11
Source File: FixedJMeterTreeCellRenderer.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean p_hasFocus) {
    JMeterTreeNode node = (JMeterTreeNode) value;
    TestElement mc = node.getTestElement();

    JMeterTreeNode fakeNode = (JMeterTreeNode) node.clone();
    if (mc instanceof OriginalLink) {
        fakeNode.setUserObject(((OriginalLink) mc).getOriginal());
    } else {
        fakeNode.setUserObject(mc);
    }
    Component treeCellRendererComponent = super.getTreeCellRendererComponent(tree, fakeNode, sel, expanded, leaf, row, p_hasFocus);
    hiliter.highlightNode(treeCellRendererComponent, node, mc);
    return treeCellRendererComponent;
}
 
Example #12
Source File: DebuggerDialogBase.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    int selRow = tree.getRowForLocation(e.getX(), e.getY());

    if (tree.getPathForLocation(e.getX(), e.getY()) != null) {
        final TreePath currentPath = tree.getPathForLocation(e.getX(), e.getY());

        if (selRow != -1 && currentPath != null) {
            if (isRightClick(e)) {
                if (tree.getSelectionCount() < 2) {
                    tree.setSelectionPath(currentPath);
                }
                final JMeterTreeNode node = (JMeterTreeNode) currentPath.getLastPathComponent();
                TestElement te = (TestElement) node.getUserObject();
                if (te instanceof ConfigElement || te instanceof TestPlan || te instanceof ThreadGroup || te instanceof WorkBench) {
                    log.debug("No breakpoint possible for " + te);
                    return;
                }
                JPopupMenu popup = getPopup(te);
                popup.pack();
                popup.show(tree, e.getX(), e.getY());
                popup.setVisible(true);
                popup.requestFocusInWindow();
            }
        }
    }
}
 
Example #13
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private TestElement getOriginalObject(JMeterTreeNode node) {
    Object obj = (node).getUserObject();
    if (obj instanceof OriginalLink) {
        Object original = ((OriginalLink) obj).getOriginal();
        return (TestElement) original;
    } else {
        return (TestElement) obj;
    }
}
 
Example #14
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private JMeterTreeNode getClonedNode(JMeterTreeNode node) {
    TestElement orig = getOriginalObject(node);
    TestElement cloned = (TestElement) orig.clone();
    TestElement altered = getAlteredElement(cloned);

    if (altered instanceof Wrapper) {
        Wrapper wrp = (Wrapper) altered;
        //noinspection unchecked
        wrp.setWrappedElement(cloned);
        PropertyIterator iter = cloned.propertyIterator();
        while (iter.hasNext()) {
            JMeterProperty prop = iter.next();
            if (!prop.getName().startsWith("TestElement")) {
                wrp.setProperty(prop.clone());
            }
        }
    }

    if (altered instanceof OriginalLink) {
        OriginalLink link = (OriginalLink) altered;
        //noinspection unchecked
        link.setOriginal(orig);
    } else {
        log.debug("Not linking original: " + altered);
    }

    JMeterTreeNode res = new JMeterTreeNode();
    altered.setName(cloned.getName());
    altered.setEnabled(cloned.isEnabled());
    if (altered.getProperty(TestElement.GUI_CLASS) instanceof NullProperty) {
        altered.setProperty(TestElement.GUI_CLASS, ControllerDebugGui.class.getCanonicalName());
    }
    res.setUserObject(altered);
    return res;
}
 
Example #15
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
protected Object addNodeToTree(Object node) {
    if (node instanceof JMeterTreeNode) {
        node = getClonedNode((JMeterTreeNode) node);
        newTree.add(stack, node);
    } else {
        throw new IllegalArgumentException();
    }
    return node;
}
 
Example #16
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private boolean isIgnored(Object node) {
    if (node instanceof JMeterTreeNode) {
        Object te = ((JMeterTreeNode) node).getUserObject();
        return te instanceof AbstractThreadGroup && te != onlyTG;
    }
    return false;
}
 
Example #17
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private AbstractThreadGroup getSelectedThreadGroup(AbstractThreadGroup[] grps) {
    JMeterTreeNode currentElement = GuiPackage.getInstance().getCurrentNode();
    if (currentElement != null) {
        SearchParentClass<AbstractThreadGroup> searcher = new SearchParentClass(currentElement, AbstractThreadGroup.class);
        treeProvider.getTestTree().traverse(searcher);
        return searcher.hasResults() ? searcher.getSearchResults().get(0) : grps[0];
    }
    return grps[0];
}
 
Example #18
Source File: SearchClass.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void addNode(Object node, HashTree subTree) {
    if (node instanceof JMeterTreeNode) {
        Object userObj = ((JMeterTreeNode) node).getUserObject();
        if (searchClass.isAssignableFrom(userObj.getClass())) {
            //noinspection unchecked
            results.add((T) userObj);
        }
    }
}
 
Example #19
Source File: SearchParentClass.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private T findParentByClass(JMeterTreeNode node) {
    if (node != null) {
        Object userObject = node.getUserObject();
        return searchParentClass.isAssignableFrom(userObject.getClass()) ?
                (T) userObject :
                findParentByClass((JMeterTreeNode) node.getParent());
    }

    return null;
}
 
Example #20
Source File: SearchParentClass.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void addNode(Object node, HashTree subTree) {
    if (node instanceof JMeterTreeNode) {
        JMeterTreeNode jMeterTreeNode = ((JMeterTreeNode) node);
        if (node.equals(searchNode)) {
            T parent = findParentByClass(jMeterTreeNode);
            if (parent != null) {
                results.add(parent);
            }
        }
    }
}
 
Example #21
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 4 votes vote down vote up
/**
 * @return the target fileconfigholder node
 */
public JMeterTreeNode getTarget()
{
    return null;
}
 
Example #22
Source File: SearchParentClass.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public SearchParentClass(JMeterTreeNode searchNode, Class<T> searchParentClass) {
    this.searchNode = searchNode;
    this.searchParentClass = searchParentClass;
}
 
Example #23
Source File: ReplaceableGenericControllerDebug.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public void resolveReplacementSubTree(JMeterTreeNode context) {
    if (wrapped instanceof ReplaceableController) {
        ((ReplaceableController) wrapped).resolveReplacementSubTree(context);
    }
}
 
Example #24
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the target node where the samples generated by the proxy have to be
 * stored.
 *
 * @param target target node to store generated samples
 */
public void setTarget(JMeterTreeNode target)
{
}
 
Example #25
Source File: NodeHighlighter.java    From jmeter-debugger with Apache License 2.0 votes vote down vote up
void highlightNode(Component treeCellRendererComponent, JMeterTreeNode node, TestElement mc);