Search in sources :

Example 46 with GitTreeNode

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);
        }
    }
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

Example 47 with GitTreeNode

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);
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Test(org.junit.Test)

Example 48 with GitTreeNode

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);
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Test(org.junit.Test)

Example 49 with GitTreeNode

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);
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode) ArrayList(java.util.ArrayList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Test(org.junit.Test)

Aggregations

GitTreeNode (com.oxygenxml.git.view.GitTreeNode)49 FileStatus (com.oxygenxml.git.service.entities.FileStatus)33 File (java.io.File)30 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)23 AbstractAction (javax.swing.AbstractAction)19 GitController (com.oxygenxml.git.view.event.GitController)18 JButton (javax.swing.JButton)15 TreePath (javax.swing.tree.TreePath)14 Test (org.junit.Test)14 JDialog (javax.swing.JDialog)13 JTree (javax.swing.JTree)8 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)7 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 JTextField (javax.swing.JTextField)7 JCheckBox (javax.swing.JCheckBox)6 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 JLabel (javax.swing.JLabel)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4