private void removeNodeFromParent(DefaultMutableTreeNode node) {
    TreeNode parent = node.getParent();
    int idx = parent.getIndex(node);
    node.removeFromParent();

    (getModel()).nodesWereRemoved(parent, new int[] {idx}, new TreeNode[] {node});
  }
Exemplo n.º 2
0
  private static List<PathElement> createPath(final TreePath treePath) {
    final ArrayList<PathElement> result = new ArrayList<PathElement>();
    for (int i = 0; i < treePath.getPathCount(); i++) {
      final Object pathComponent = treePath.getPathComponent(i);
      if (pathComponent instanceof DefaultMutableTreeNode) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathComponent;
        final TreeNode parent = node.getParent();

        final Object userObject = node.getUserObject();
        if (userObject instanceof NodeDescriptor) {
          final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject;
          // nodeDescriptor.update();
          final int childIndex = parent != null ? parent.getIndex(node) : 0;
          result.add(
              new PathElement(
                  getDescriptorKey(nodeDescriptor),
                  getDescriptorType(nodeDescriptor),
                  childIndex,
                  nodeDescriptor));
        } else {
          result.add(new PathElement("", "", 0, userObject));
        }
      } else {
        return null;
      }
    }
    return result;
  }
Exemplo n.º 3
0
 /**
  * 刷新节点中文名称
  *
  * @param node
  */
 private void refreshNodeChName(TreeNode node) {
   TreeNode parNode = node.getParent();
   int index = parNode.getIndex(node);
   Caliber cal = (Caliber) ((DefaultMutableTreeNode) node).getUserObject();
   if (index == 0) {
     cal.setFirstNode(true);
   } else {
     cal.setFirstNode(false);
   }
 }
 private boolean isMovingAvailable(final CheckedTreeNode toolNode, Direction dir) {
   TreeNode parent = toolNode.getParent();
   int index = parent.getIndex(toolNode);
   return dir.isAvailable(index, parent.getChildCount());
 }