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