use of javax.swing.tree.TreePath in project zaproxy by zaproxy.
the class JCheckBoxTreeUnitTest method shouldUncheckSubTreeChildNodeWithChildNodes.
@Test
public void shouldUncheckSubTreeChildNodeWithChildNodes() {
// Given
TreeModelTest treeModel = TreeModelTest.create("A", "A/B", "A/B/C", "A/B/D");
TreePath rootNodePath = treeModel.createPath("A");
TreePath childNodePath = treeModel.createPath("A/B");
TreePath childNodeCPath = treeModel.createPath("A/B/C");
TreePath childNodeDPath = treeModel.createPath("A/B/D");
JCheckBoxTree checkBoxTree = new JCheckBoxTree();
checkBoxTree.setModel(treeModel);
checkBoxTree.checkSubTree(rootNodePath, true);
// When
checkBoxTree.checkSubTree(childNodePath, false);
// Then
assertThat(checkBoxTree.isChecked(childNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedPartially(childNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedFully(childNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isChecked(childNodeCPath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedPartially(childNodeCPath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedFully(childNodeCPath), is(equalTo(false)));
assertThat(checkBoxTree.isChecked(childNodeDPath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedPartially(childNodeDPath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedFully(childNodeDPath), is(equalTo(false)));
assertThat(checkBoxTree.isChecked(rootNodePath), is(equalTo(true)));
assertThat(checkBoxTree.isSelectedPartially(rootNodePath), is(equalTo(true)));
assertThat(checkBoxTree.isSelectedFully(rootNodePath), is(equalTo(false)));
assertThat(checkBoxTree.getCheckedPaths(), is(arrayContaining(rootNodePath)));
}
use of javax.swing.tree.TreePath in project zaproxy by zaproxy.
the class JCheckBoxTreeUnitTest method shouldHaveOnlyRootNodeExpandedByDefault.
@Test
public void shouldHaveOnlyRootNodeExpandedByDefault() {
// Given
TreeModelTest treeModel = TreeModelTest.create("A", "A/B", "A/B/C", "A/B/D", "A/E");
TreePath rootNodePath = treeModel.createPath("A");
TreePath childNodeBPath = treeModel.createPath("A/B");
TreePath childCChildNodeBPath = treeModel.createPath("A/B/C");
TreePath childDChildNodeBPath = treeModel.createPath("A/B/D");
TreePath childNodeEPath = treeModel.createPath("A/E");
JCheckBoxTree checkBoxTree = new JCheckBoxTree();
// When
checkBoxTree.setModel(treeModel);
// Then
assertThat(checkBoxTree.isExpanded(rootNodePath), is(equalTo(true)));
assertThat(checkBoxTree.isCollapsed(rootNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isExpanded(childNodeBPath), is(equalTo(false)));
assertThat(checkBoxTree.isCollapsed(childNodeBPath), is(equalTo(true)));
assertThat(checkBoxTree.isExpanded(childCChildNodeBPath), is(equalTo(false)));
assertThat(checkBoxTree.isCollapsed(childCChildNodeBPath), is(equalTo(true)));
assertThat(checkBoxTree.isExpanded(childDChildNodeBPath), is(equalTo(false)));
assertThat(checkBoxTree.isCollapsed(childDChildNodeBPath), is(equalTo(true)));
assertThat(checkBoxTree.isExpanded(childNodeEPath), is(equalTo(false)));
assertThat(checkBoxTree.isCollapsed(childNodeEPath), is(equalTo(true)));
}
use of javax.swing.tree.TreePath in project zaproxy by zaproxy.
the class JCheckBoxTreeUnitTest method shouldUncheckRootNodeWithoutChildNodes.
@Test
public void shouldUncheckRootNodeWithoutChildNodes() {
// Given
TreeModelTest treeModel = TreeModelTest.create("A");
TreePath rootNodePath = treeModel.createPath("A");
JCheckBoxTree checkBoxTree = new JCheckBoxTree();
checkBoxTree.setModel(treeModel);
checkBoxTree.check(rootNodePath, true);
// When
checkBoxTree.check(rootNodePath, false);
// Then
assertThat(checkBoxTree.isChecked(rootNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedPartially(rootNodePath), is(equalTo(false)));
assertThat(checkBoxTree.isSelectedFully(rootNodePath), is(equalTo(false)));
assertThat(checkBoxTree.getCheckedPaths(), is(emptyArray()));
}
use of javax.swing.tree.TreePath in project GsonFormat by zzz40500.
the class CheckTreeSelectionModel method addSelectionPaths.
@Override
public void addSelectionPaths(TreePath[] paths) {
// unselect all descendants of paths[]
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
TreePath[] selectionPaths = getSelectionPaths();
if (selectionPaths == null) {
break;
}
ArrayList toBeRemoved = new ArrayList();
for (int j = 0; j < selectionPaths.length; j++) {
if (isDescendant(selectionPaths[j], path)) {
toBeRemoved.add(selectionPaths[j]);
}
}
super.removeSelectionPaths((TreePath[]) toBeRemoved.toArray(new TreePath[0]));
}
// otherwize just select that path.
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
TreePath temp = null;
while (areSiblingsSelected(path)) {
temp = path;
if (path.getParentPath() == null) {
break;
}
path = path.getParentPath();
}
if (temp != null) {
if (temp.getParentPath() != null) {
addSelectionPath(temp.getParentPath());
} else {
if (!isSelectionEmpty()) {
removeSelectionPaths(getSelectionPaths());
}
super.addSelectionPaths(new TreePath[] { temp });
}
} else {
super.addSelectionPaths(new TreePath[] { path });
}
}
}
use of javax.swing.tree.TreePath in project zaproxy by zaproxy.
the class JCheckBoxTree method addSubtreeToCheckingStateTracking.
// Creating data structure of the current model for the checking mechanism
private void addSubtreeToCheckingStateTracking(DefaultMutableTreeNode node) {
TreeNode[] path = node.getPath();
TreePath tp = new TreePath(path);
CheckedNode cn = new CheckedNode(false, node.getChildCount() > 0, false);
nodesCheckingState.put(tp, cn);
for (int i = 0; i < node.getChildCount(); i++) {
addSubtreeToCheckingStateTracking((DefaultMutableTreeNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent());
}
}
Aggregations