private static void addPathToActionsTree(JTree tree, ActionUrl url) { final TreePath treePath = CustomizationUtil.getTreePath(tree, url); if (treePath == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); final int absolutePosition = url.getAbsolutePosition(); if (node.getChildCount() >= absolutePosition && absolutePosition >= 0) { if (url.getComponent() instanceof Group) { node.insert(ActionsTreeUtil.createNode((Group) url.getComponent()), absolutePosition); } else { node.insert(new DefaultMutableTreeNode(url.getComponent()), absolutePosition); } } }
private static void removePathFromActionsTree(JTree tree, ActionUrl url) { if (url.myComponent == null) return; final TreePath treePath = CustomizationUtil.getTreePath(tree, url); if (treePath == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); final int absolutePosition = url.getAbsolutePosition(); if (node.getChildCount() > absolutePosition && absolutePosition >= 0) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(absolutePosition); if (child.getUserObject().equals(url.getComponent())) { node.remove(child); } } }
private static void movePathInActionsTree(JTree tree, ActionUrl url) { final TreePath treePath = CustomizationUtil.getTreePath(tree, url); if (treePath != null) { if (treePath.getLastPathComponent() != null) { final DefaultMutableTreeNode parent = ((DefaultMutableTreeNode) treePath.getLastPathComponent()); final int absolutePosition = url.getAbsolutePosition(); final int initialPosition = url.getInitialPosition(); if (parent.getChildCount() > absolutePosition && absolutePosition >= 0) { if (parent.getChildCount() > initialPosition && initialPosition >= 0) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) parent.getChildAt(initialPosition); if (child.getUserObject().equals(url.getComponent())) { parent.remove(child); parent.insert(child, absolutePosition); } } } } } }
private List<ActionUrl> findActionsUnderSelection() { final ArrayList<ActionUrl> actions = new ArrayList<ActionUrl>(); final TreePath[] selectionPaths = myActionsTree.getSelectionPaths(); if (selectionPaths != null) { for (TreePath path : selectionPaths) { final ActionUrl selectedUrl = CustomizationUtil.getActionUrl(path, ActionUrl.MOVE); final ArrayList<String> selectedGroupPath = new ArrayList<String>(selectedUrl.getGroupPath()); final Object component = selectedUrl.getComponent(); if (component instanceof Group) { selectedGroupPath.add(((Group) component).getName()); for (ActionUrl action : mySelectedSchema.getActions()) { final ArrayList<String> groupPath = action.getGroupPath(); final int idx = Collections.indexOfSubList(groupPath, selectedGroupPath); if (idx > -1) { actions.add(action); } } } } } return actions; }