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