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;
}
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());
}
}
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);
}
}
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));
}
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));
}
Aggregations