Search in sources :

Example 26 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTreeModel method clearModel.

/**
 * Clears all the nodes in the model and leaves an empty root.
 */
private void clearModel() {
    filesStatuses.clear();
    // Rebuild the tree
    GitTreeNode root = (GitTreeNode) getRoot();
    root.removeAllChildren();
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

Example 27 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTreeModel method deleteNodes.

/**
 * Delete nodes from the tree based on the given files
 *
 * @param fileToBeUpdated
 *          - the files on which the nodes will be deleted
 */
private void deleteNodes(List<FileStatus> fileToBeUpdated) {
    for (FileStatus fileStatus : fileToBeUpdated) {
        GitTreeNode node = TreeUtil.getTreeNodeFromString(this, fileStatus.getFileLocation());
        while (node != null && node.getParent() != null) {
            GitTreeNode parentNode = (GitTreeNode) node.getParent();
            if (node.getSiblingCount() != 1) {
                parentNode.remove(node);
                break;
            } else {
                parentNode.remove(node);
            }
            node = parentNode;
        }
    }
    filesStatuses.removeAll(fileToBeUpdated);
    TreeUtil.sortGitTree(this);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

Example 28 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementPanel method updateTreeView.

/**
 * Updates a tree structure with the given branches.
 *
 * @param branchList The branches used to generate the nodes.
 */
private void updateTreeView(List<String> branchList) {
    if (branchesTree != null) {
        Enumeration<TreePath> expandedPaths = TreeUtil.getLastExpandedPaths(branchesTree);
        TreePath selectionPath = branchesTree.getSelectionPath();
        // Create the tree with the new model
        BranchManagementTreeModel newModel = new BranchManagementTreeModel(GitAccess.getInstance().getWorkingCopyName(), branchList);
        branchesTree.setModel(newModel);
        // restore last expanded paths after refresh
        TreeUtil.restoreLastExpandedPaths(expandedPaths, branchesTree);
        // EXM-46684 Restore previous selection only if it still present in the model.
        if (selectionPath != null && branchList.contains(((GitTreeNode) selectionPath.getLastPathComponent()).getUserObject())) {
            branchesTree.setSelectionPath(selectionPath);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

Example 29 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementPanel method addTreeListeners.

/**
 * Adds the tree listeners.
 */
private void addTreeListeners() {
    // Expand several levels at once when only one child on each level
    branchesTree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            TreeUtil.expandSingleChildPath(branchesTree, event);
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        // Nothing
        }
    });
    // Show context menu when pressing the Meny key
    branchesTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU) {
                TreePath selectionPath = branchesTree.getSelectionPath();
                if (selectionPath != null) {
                    Rectangle pathBounds = branchesTree.getPathBounds(selectionPath);
                    if (pathBounds != null) {
                        Point nodePoint = new Point(pathBounds.x, pathBounds.y + pathBounds.height);
                        showContextualMenu(selectionPath, nodePoint);
                    }
                }
            }
        }
    });
    branchesTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            // Show context menu
            branchesTree.requestFocus();
            if (e.isPopupTrigger()) {
                Point nodePoint = e.getPoint();
                TreePath pathForLocation = branchesTree.getPathForLocation(nodePoint.x, nodePoint.y);
                showContextualMenu(pathForLocation, nodePoint);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            mousePressed(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (!e.isConsumed() && !e.isPopupTrigger() && e.getClickCount() == 2) {
                // Checkout branch on double click
                e.consume();
                Point nodePoint = e.getPoint();
                TreePath pathForLocation = branchesTree.getPathForLocation(nodePoint.x, nodePoint.y);
                if (pathForLocation != null) {
                    AbstractAction checkoutAction = branchesTreeActionProvider.getCheckoutAction((GitTreeNode) pathForLocation.getLastPathComponent());
                    if (checkoutAction != null) {
                        checkoutAction.actionPerformed(null);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) TreeExpansionListener(javax.swing.event.TreeExpansionListener) MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) MouseAdapter(java.awt.event.MouseAdapter) Point(java.awt.Point) AbstractAction(javax.swing.AbstractAction) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 30 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTreeModel method deleteNodes.

/**
 * Delete nodes from the tree based on the given branches.
 *
 * @param branchesToBeUpdated The branches on which the nodes will be deleted.
 */
private void deleteNodes(List<String> branchesToBeUpdated) {
    for (String branchName : branchesToBeUpdated) {
        GitTreeNode node = TreeUtil.getTreeNodeFromString(this, branchName);
        while (node != null && node.getParent() != null) {
            GitTreeNode parentNode = (GitTreeNode) node.getParent();
            if (node.getSiblingCount() != 1) {
                parentNode.remove(node);
                break;
            } else {
                parentNode.remove(node);
            }
            node = parentNode;
        }
    }
    branches.removeAll(branchesToBeUpdated);
    TreeUtil.sortGitTree(this);
}
Also used : GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

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