Search in sources :

Example 36 with TreeNode

use of javax.swing.tree.TreeNode in project jmeter by apache.

the class ChangeParent method changeParent.

private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) {
    // keep the old name if it was not the default one
    Controller currentController = (Controller) currentNode.getUserObject();
    JMeterGUIComponent currentGui = guiPackage.getCurrentGui();
    String defaultName = JMeterUtils.getResString(currentGui.getLabelResource());
    if (StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)) {
        newParent.setName(currentController.getName());
    }
    JMeterTreeModel treeModel = guiPackage.getTreeModel();
    JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel);
    JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
    int index = parentNode.getIndex(currentNode);
    treeModel.insertNodeInto(newNode, parentNode, index);
    treeModel.removeNodeFromParent(currentNode);
    int childCount = currentNode.getChildCount();
    for (int i = 0; i < childCount; i++) {
        // Using index 0 is voluntary as child is removed in next step and added to new parent
        JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
        treeModel.removeNodeFromParent(node);
        treeModel.insertNodeInto(node, newNode, newNode.getChildCount());
    }
    // select the node
    TreeNode[] nodes = treeModel.getPathToRoot(newNode);
    JTree tree = guiPackage.getTreeListener().getJTree();
    tree.setSelectionPath(new TreePath(nodes));
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Controller(org.apache.jmeter.control.Controller)

Example 37 with TreeNode

use of javax.swing.tree.TreeNode in project jmeter by apache.

the class CollapseExpandTreeBranch method doAction.

/**
     * This method performs the actual command processing.
     *
     * @param e the generic UI action event
     */
@Override
public void doAction(ActionEvent e) {
    JMeterTreeListener treeListener = GuiPackage.getInstance().getTreeListener();
    JTree jTree = GuiPackage.getInstance().getMainFrame().getTree();
    JMeterTreeNode[] selectedNodes = treeListener.getSelectedNodes();
    for (JMeterTreeNode currentNode : selectedNodes) {
        if (!currentNode.isLeaf()) {
            TreeNode[] nodes = GuiPackage.getInstance().getTreeModel().getPathToRoot(currentNode);
            TreePath path = new TreePath(nodes);
            boolean collapse = ActionNames.COLLAPSE.equals(e.getActionCommand());
            expandCollapseNode(jTree, path, collapse);
        }
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 38 with TreeNode

use of javax.swing.tree.TreeNode in project jmeter by apache.

the class CollapseExpandTreeBranch method expandCollapseNode.

private void expandCollapseNode(JTree jTree, TreePath parent, boolean collapse) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.isLeaf()) {
        return;
    }
    Enumeration<?> children = node.children();
    while (children.hasMoreElements()) {
        TreeNode child = (TreeNode) children.nextElement();
        TreePath path = parent.pathByAddingChild(child);
        expandCollapseNode(jTree, path, collapse);
    }
    if (collapse) {
        jTree.collapsePath(parent);
    } else {
        jTree.expandPath(parent);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 39 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-community by JetBrains.

the class InspectionViewNavigationPanel method resetChildrenNavigation.

private void resetChildrenNavigation() {
    final int currentChildrenCount = myNode.getChildCount();
    if (myShownChildrenCount != currentChildrenCount) {
        myLinks.removeAll();
        myLinks.add(Box.createVerticalStrut(JBUI.scale(10)));
        for (int i = 0; i < currentChildrenCount; i++) {
            final TreeNode child = myNode.getChildAt(i);
            final LinkLabel link = new LinkLabel(child.toString(), null) {

                @Override
                public void doClick() {
                    TreeUtil.selectInTree((DefaultMutableTreeNode) child, true, myTree);
                }
            };
            link.setBorder(IdeBorderFactory.createEmptyBorder(1, 17, 3, 1));
            myLinks.add(link);
        }
        myShownChildrenCount = currentChildrenCount;
    }
}
Also used : TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LinkLabel(com.intellij.ui.components.labels.LinkLabel)

Example 40 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-community by JetBrains.

the class CachedInspectionTreeNode method dropCache.

@SuppressWarnings("ResultOfMethodCallIgnored")
protected void dropCache(Project project) {
    myValid = calculateIsValid();
    myPresentableName = calculatePresentableName();
    for (int i = 0; i < getChildCount(); i++) {
        TreeNode child = getChildAt(i);
        if (child instanceof CachedInspectionTreeNode) {
            ((CachedInspectionTreeNode) child).dropCache(project);
        }
    }
}
Also used : TreeNode(javax.swing.tree.TreeNode)

Aggregations

TreeNode (javax.swing.tree.TreeNode)183 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)77 TreePath (javax.swing.tree.TreePath)64 JTree (javax.swing.JTree)25 Nullable (org.jetbrains.annotations.Nullable)20 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)18 MPart (gov.sandia.n2a.eqset.MPart)15 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)15 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)14 ArrayList (java.util.ArrayList)13 Enumeration (java.util.Enumeration)13 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)12 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)11 CannotRedoException (javax.swing.undo.CannotRedoException)10 NotNull (org.jetbrains.annotations.NotNull)10 CannotUndoException (javax.swing.undo.CannotUndoException)9 FontMetrics (java.awt.FontMetrics)8 MutableTreeNode (javax.swing.tree.MutableTreeNode)8 BioModelNode (cbit.vcell.desktop.BioModelNode)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)6