use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class TreeUtil method buildTreeFromString.
/**
* Builds a tree from a given forward slash delimited string.
*
* @param model
* The tree model
* @param str
* The string to build the tree from
*/
public static void buildTreeFromString(final DefaultTreeModel model, final String str) {
// Fetch the root node
GitTreeNode root = (GitTreeNode) model.getRoot();
// Split the string around the delimiter
String[] strings = str.split("/");
// Create a node object to use for traversing down the tree as it
// is being created
GitTreeNode node = root;
// Iterate of the string array
for (String s : strings) {
// Look for the index of a node at the current level that
// has a value equal to the current string
int index = childIndex(node, s);
// Index less than 0, this is a new node not currently present on the tree
if (index < 0) {
// Add the new node
GitTreeNode newChild = new GitTreeNode(s);
node.insert(newChild, node.getChildCount());
node = newChild;
} else {
// Existing node, skip to the next string
node = (GitTreeNode) node.getChildAt(index);
}
}
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class TreeFormatterTest method testGetNodeFromString_3.
/**
* EXM-41140
*
* Get the right node (the root) for an empty path.
*/
@Test
public void testGetNodeFromString_3() {
List<String> paths = new ArrayList<String>();
paths.add("src/add/poc.txt");
paths.add("src/add/hello.txt");
paths.add("src/add/java/info.txt");
GitTreeNode root = new GitTreeNode("Test");
DefaultTreeModel model = new DefaultTreeModel(root);
for (String string : paths) {
TreeUtil.buildTreeFromString(model, string);
}
GitTreeNode node = TreeUtil.getTreeNodeFromString(model, "");
assertEquals(root, node);
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class TreeFormatterTest method testGetNodeFromString_2.
/**
* Getting tree node from a string should return <code>null</code> if
* there is no corresponding node.
*/
@Test
public void testGetNodeFromString_2() {
List<String> paths = new ArrayList<String>();
paths.add("src/add/poc.txt");
paths.add("src/add/hello.txt");
paths.add("src/add/java/info.txt");
GitTreeNode root = new GitTreeNode("Test");
DefaultTreeModel model = new DefaultTreeModel(root);
for (String string : paths) {
TreeUtil.buildTreeFromString(model, string);
}
GitTreeNode node = TreeUtil.getTreeNodeFromString(model, "path/to/non/existing/file.xml");
assertNull(node);
node = TreeUtil.getTreeNodeFromString(model, "src/add/non-existing.txt");
assertNull(node);
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class TreeFormatterTest method testGetNodeFromString.
@Test
public void testGetNodeFromString() {
List<String> paths = new ArrayList<String>();
paths.add("src/add/poc.txt");
paths.add("src/add/hello.txt");
paths.add("src/add/java/info.txt");
paths.add("src/main/java/test.java");
paths.add("src/main/java/package/file.java");
paths.add("resources/java/find.txt");
GitTreeNode root = new GitTreeNode("Test");
DefaultTreeModel model = new DefaultTreeModel(root);
for (String string : paths) {
TreeUtil.buildTreeFromString(model, string);
}
GitTreeNode node = TreeUtil.getTreeNodeFromString(model, "src/add/java/info.txt");
String actual = (String) node.getUserObject();
String expected = "info.txt";
assertEquals(actual, expected);
}
Aggregations