Search in sources :

Example 21 with TreeNode

use of javax.swing.tree.TreeNode in project zaproxy by zaproxy.

the class NodeSelectDialog method showDialog.

public Target showDialog(Target defaultTarget) {
    // Assume Contexts can be selected
    this.getTreeContext().setVisible(true);
    SiteNode siteRoot = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot();
    populateContexts((SiteNode) this.contextTree.getRoot());
    if (defaultTarget != null) {
        populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), defaultTarget.getStartNode());
    } else {
        populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), null);
    }
    if (selectedSiteNode != null) {
        // Found the default node, select it
        TreePath path = new TreePath(this.siteTree.getPathToRoot(selectedSiteNode));
        this.getTreeSite().setExpandsSelectedPaths(true);
        this.getTreeSite().setSelectionPath(path);
        this.getTreeSite().scrollPathToVisible(path);
        this.getTreeSite().expandPath(path);
    } else {
        // no default path, just expand the top level
        TreePath path = new TreePath(this.siteTree.getPathToRoot((TreeNode) this.siteTree.getRoot()));
        this.getTreeSite().expandPath(path);
    }
    this.setVisible(true);
    // The dialog is modal so this wont return until the dialog visibility is unset
    if (selectedSiteNode != null) {
        return new Target(selectedSiteNode);
    }
    return selectedTarget;
}
Also used : Target(org.zaproxy.zap.model.Target) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 22 with TreeNode

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

the class RemoveCustomFieldAction method perform.

@Override
protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
    UserExpressionDescriptorImpl descriptor = (UserExpressionDescriptorImpl) ((JavaValue) node.getValueContainer()).getDescriptor();
    EnumerationChildrenRenderer enumerationChildrenRenderer = getParentEnumerationRenderer(descriptor);
    if (enumerationChildrenRenderer != null) {
        enumerationChildrenRenderer.getChildren().remove(descriptor.getEnumerationIndex());
        TreeNode parent = node.getParent();
        int index = parent.getIndex(node);
        int indexToSelect = index + 1 < parent.getChildCount() ? index + 1 : index - 1;
        TreeUtil.selectNode(node.getTree(), indexToSelect >= 0 ? parent.getChildAt(indexToSelect) : parent);
        XDebuggerUtilImpl.rebuildTreeAndViews(node.getTree());
    }
}
Also used : EnumerationChildrenRenderer(com.intellij.debugger.ui.tree.render.EnumerationChildrenRenderer) UserExpressionDescriptorImpl(com.intellij.debugger.ui.impl.watch.UserExpressionDescriptorImpl) TreeNode(javax.swing.tree.TreeNode)

Example 23 with TreeNode

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

the class TreeBuilder method nodeChanged.

public void nodeChanged(TreeNode node) {
    TreeModelEvent event = null;
    TreeNode parent = node.getParent();
    if (parent != null) {
        int anIndex = parent.getIndex(node);
        event = new TreeModelEvent(this, getPathToRoot(parent, 0), new int[] { anIndex }, new Object[] { node });
    } else if (node == getRoot()) {
        event = new TreeModelEvent(this, getPathToRoot(node, 0), null, null);
    }
    if (event != null) {
        myDispatcher.getMulticaster().treeNodesChanged(event);
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeNode(javax.swing.tree.TreeNode)

Example 24 with TreeNode

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

the class Move method moveAndSelectNode.

private static void moveAndSelectNode(JMeterTreeNode currentNode, JMeterTreeNode parentNode, int newIndx) {
    GuiPackage guiInstance = GuiPackage.getInstance();
    guiInstance.getTreeModel().removeNodeFromParent(currentNode);
    guiInstance.getTreeModel().insertNodeInto(currentNode, parentNode, newIndx);
    // select the node
    TreeNode[] nodes = guiInstance.getTreeModel().getPathToRoot(currentNode);
    JTree jTree = guiInstance.getMainFrame().getTree();
    jTree.setSelectionPath(new TreePath(nodes));
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 25 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)

Aggregations

TreeNode (javax.swing.tree.TreeNode)149 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)74 TreePath (javax.swing.tree.TreePath)56 Nullable (org.jetbrains.annotations.Nullable)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)12 ArrayList (java.util.ArrayList)10 Enumeration (java.util.Enumeration)10 NotNull (org.jetbrains.annotations.NotNull)10 MutableTreeNode (javax.swing.tree.MutableTreeNode)8 JTree (javax.swing.JTree)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)6 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)4 Tree (com.intellij.ui.treeStructure.Tree)4 Point (java.awt.Point)4 File (java.io.File)4 AllIcons (com.intellij.icons.AllIcons)3 Pair (com.intellij.openapi.util.Pair)3