DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userData, allowsChildren); int ix = target.getChildCount(); if (before != null) { ix = model.getIndexOfChild(target, before); } if(log.isDebugEnabled()) { log.debug("Insert into " + target + " at " + ix + " before " + before); }  model.insertNodeInto(newNode, target, ix);  if (data instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode source = (DefaultMutableTreeNode)data; int n = source.getChildCount(); DefaultMutableTreeNode[] children = new DefaultMutableTreeNode[n]; for (int i = 0; i < n; i++) children[i] = (DefaultMutableTreeNode) source.getChildAt(i); for (int i = 0; i < n; i++) model.insertNodeInto(children[i], newNode, i); } selectNode(newNode); return action;
if (data instanceof DMTNArray) { DMTNArray nodes = (DMTNArray) data; for (int i = 0; i < nodes.nodes.length; i++) addElement(nodes.nodes[i], target, before); } else addElement(data, target, before); return action;
  public int addElement(Transferable t,                        DefaultMutableTreeNode target,                        DefaultMutableTreeNode before) {    DataFlavor[] flavors = t.getTransferDataFlavors();    int action = isDroppable(flavors, target);    if (action == DnDConstants.ACTION_NONE)       return action; // do nothing    Object data = null;    try {      data = t.getTransferData(flavors[0]);    } catch (Exception e) {      if(log.isErrorEnabled()) {        log.error("Exception adding dropped element:", e);        return DnDConstants.ACTION_NONE;      }    }    // the data being added    Object userData = data;    boolean allowsChildren = false;    // if the data being added is a tree node, then extract the user data    if (data instanceof DefaultMutableTreeNode) {      userData = ((DefaultMutableTreeNode)data).getUserObject();      if (userData instanceof String || userData instanceof Experiment)        allowsChildren = true;    }    // create a new tree node for the transferred data    DefaultMutableTreeNode newNode =      new DefaultMutableTreeNode(userData, allowsChildren);    int ix = target.getChildCount();    if (before != null) {      ix = model.getIndexOfChild(target, before);    }    if(log.isDebugEnabled()) {      log.debug("Insert into " + target + " at " + ix + " before " + before);    }    // put the new tree node into the target    model.insertNodeInto(newNode, target, ix);    // if the data being transferred is a tree node, then add its children    if (data instanceof DefaultMutableTreeNode) {      DefaultMutableTreeNode source = (DefaultMutableTreeNode)data;      int n = source.getChildCount();      DefaultMutableTreeNode[] children = new DefaultMutableTreeNode[n];      for (int i = 0; i < n; i++)         children[i] = (DefaultMutableTreeNode) source.getChildAt(i);      for (int i = 0; i < n; i++)         model.insertNodeInto(children[i], newNode, i);    }    selectNode(newNode);    return action;  // Always MOVE  }