/*
this method is used to update tree items and set the new root
after grouping the data model
548108
private void buildGroupedRoot(Map<?,?> groupedItems, RecursiveTreeItem parent, int groupIndex) {
        boolean setRoot = false;
        if (parent == null) {
            parent = new RecursiveTreeItem<>(new RecursiveTreeObject(), RecursiveTreeObject::getChildren);
            setRoot = true;
        }

        for (Map.Entry<?, ?> entry : groupedItems.entrySet()) {
            Object key = entry.getKey();
            RecursiveTreeObject groupItem = new RecursiveTreeObject<>();
            groupItem.setGroupedValue(key);
            groupItem.setGroupedColumn(groupOrder.get(groupIndex));

            RecursiveTreeItem node = new RecursiveTreeItem<>(groupItem, RecursiveTreeObject::getChildren);
            // TODO: need to be removed once the selection issue is fixed
            node.expandedProperty().addListener((o, oldVal, newVal) -> {
                getSelectionModel().clearSelection();
            });

            parent.originalItems.add(node);
            parent.getChildren().add(node);

            Object children = entry.getValue();
            if (children instanceof List) {
                node.originalItems.addAll((List) children);
                node.getChildren().addAll((List) children);
            } else if (children instanceof Map) {
                buildGroupedRoot((Map) children, node, groupIndex + 1);
            }
        }

        // update ui
        if (setRoot) {
            final RecursiveTreeItem<S> newParent = parent;
            JFXUtilities.runInFX(() -> {
                ArrayList<TreeTableColumn<S, ?>> sortOrder = new ArrayList<>();
                sortOrder.addAll(getSortOrder());
                internalSetRoot = true;
                setRoot(newParent);
                internalSetRoot = false;
                getSortOrder().addAll(sortOrder);
                getSelectionModel().select(0);
            });
        }
    }
128076
function updateClassesWrite(treeNodes) {
	var node, j;
	for (var i = 0; i < treeNodes.length; i++) {
		node = treeNodes[i];
		for (j = 0; j < node._changes.length; j++) {
			(node._changes[j][0] ? addQuery : removeQuery)(node._element, node._changes[j][1]);
		}
		node._changes = [];
		updateClassesWrite(node._children);
	}
}
1013136
void migrateGroup(Node oldGroupNode) throws Exception
   {
      String groupName = oldGroupNode.getName();
      String desc = utils.readString(oldGroupNode, GroupProperties.JOS_DESCRIPTION);
      String label = utils.readString(oldGroupNode, GroupProperties.JOS_LABEL);
      String parentId = utils.readString(oldGroupNode, MigrationTool.JOS_PARENT_ID);

      GroupImpl group = new GroupImpl(groupName, parentId);
      group.setDescription(desc);
      group.setLabel(label);

      Group parentGroup = findGroupById(group.getParentId());

      if (findGroupById(group.getId()) != null)
      {
         removeGroup(group, false);
      }

      addChild(parentGroup, group, false);
   }
162831
function(delta){
      events.childNodesModified.call(this, delta);

      var array;
      if (array = delta.inserted)
      {
        for (var i = 0, child; child = array[i++];)
        {
          child.groupId_ = child.delegate ? child.delegate.basisObjectId : child.data.id;
          this.map_[child.groupId_] = child;
        }

        if (this.dataSource && this.nullGroup.first)
        {
          var parentNode = this.owner;
          var nodes = arrayFrom(this.nullGroup.nodes); // basis.array.from, because nullGroup.nodes may be transformed
          for (var i = nodes.length; i-- > 0;)
            parentNode.insertBefore(nodes[i], nodes[i].nextSibling);
        }
      }
    }
1278450
function(root) {
      // establish $ instance variable
      var $ = this.$ = this.$ || {};
      // populate $ from nodes with ID from the LOCAL tree
      if (root) {
        var n$ = root.querySelectorAll("[id]");
        for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
          $[n.id] = n;
        };
      }
    }
318747
public void renameNodesInTree(String oldName, String newName) {
		List<Node> nodes = getNodesFromTreeByName(oldName);
		Iterator i = nodes.iterator();
		while (i.hasNext()) {
			Node n = (Node) i.next();
			n.setName(newName);
		}
	}
1191441
function onAddChild(e) {
        var self = this;
        if (e.target === self) {
            updateSubTreeStatus(self, e.component, self.get('depth'), e.index);
        }
    }
272276
def updateDatasetMenu(self):
        
        enabled = True
        current = self.vtgui.dbs_tree_view.currentIndex()
        if current:
            leaf = self.vtgui.dbs_tree_model.nodeFromIndex(current)
            if leaf.node_kind in (u'group', u'root group'):
                enabled = False

        self.plot_action.setEnabled(enabled)
686497
function (el) {
        if (el.__storage === this) {
            return;
        }

        if (el instanceof Group) {
            el.addChildrenToStorage(this);
        }

        this.addToStorage(el);
        this._roots.push(el);
    }
1364720
public void setTree(CmsTree<CmsTreeItem> tree) {

        m_tree = tree;
        for (Widget widget : m_children) {
            if (widget instanceof CmsTreeItem) {
                ((CmsTreeItem)widget).setTree(tree);
            }
        }
    }
584616
@Override
    public boolean setGroup(Node node) throws Exception {
        LdapGroup newLdapGroup = (LdapGroup) node;
        newLdapGroup = updateGroupMembers(newLdapGroup);
        LdapGroup oldLdapGroup = (LdapGroup) getGroup(newLdapGroup.getCn());
        if (oldLdapGroup.isEmpty()) {
            creationCount++;
            Logger.info(LOG_BIND + getOuForNode(newLdapGroup));
            ctx.bind(getOuForNode(newLdapGroup), null, newLdapGroup.getAttributes());
            return true;
        } else {
            ModificationItem[] mods = buildModificationsForGroup(newLdapGroup, oldLdapGroup);
            if (mods.length > 0) {
                modificationCount++;
                Logger.info(LOG_MODIFY_ATTRIBUTES + getOuForNode(newLdapGroup));
                ctx.modifyAttributes(getOuForNode(newLdapGroup), mods);
                return true;
            }
        }
        return false;
    }
1335287
function CompareTreeModel(rootPath, fetchItems, root) {
		this.rootPath = rootPath;
		this.fetchItems = fetchItems;
		this.root = root;
	}
567211
protected void update() {
        int sz = dataModel.getSize();
        int[] selected = helperList.getSelectedIndices();
        ArrayList sourceItems = new ArrayList(sz);
        ArrayList chosenItems = new ArrayList(selected.length);

        // Start with the source items filled from our data model
        for (int i = 0; i < sz; i++) {
            sourceItems.add(dataModel.getElementAt(i));
        }

        // Now move the selected items to the chosen list
        for (int i = selected.length - 1; i >= 0; i--) {
            chosenItems.add(sourceItems.remove(selected[i]));
        }

        Collections.reverse(chosenItems); // We built it backwards

        // Now install the two new lists
        sourceList.setListData(sourceItems.toArray());
        chosenList.setListData(chosenItems.toArray());
    }
747416
public void setRootGroups(final List<Group> rootGroups)
    {
        synchronized(this.getRootGroups())
        {
            if(rootGroups != this.getRootGroups())
            {
                this.getRootGroups().clear();
                
                if(rootGroups != null)
                {
                    this.getRootGroups().addAll(rootGroups);
                }
            }
        }
    }
219857
private StringTreeNode buildOrgHierarchyTree(final Object[] data) {
		StringTreeNode childNode = new StringTreeNode((String) data[0]);

		if (data.length > 1) {
			for (int i = 1; i < data.length; i++) {
				childNode.add(buildOrgHierarchyTree((Object[]) data[i]));
			}
		}

		return childNode;
	}
464386
public function rebuildTree()
    {
        $em = $this->getEntityManager();

        // Reset tree...
        $sql = 'UPDATE kuma_folders SET lvl=NULL,lft=NULL,rgt=NULL';
        $stmt = $em->getConnection()->prepare($sql);
        $stmt->execute();

        $folders = $this->findBy(array(), array('parent' => 'ASC', 'name' => 'asc'));

        $rootFolder = $folders[0];
        $first = true;
        foreach ($folders as $folder) {
            // Force parent load
            $parent = $folder->getParent();
            if (is_null($parent)) {
                $folder->setLevel(0);
                if ($first) {
                    $this->persistAsFirstChild($folder);
                    $first = false;
                } else {
                    $this->persistAsNextSiblingOf($folder, $rootFolder);
                }
            } else {
                $folder->setLevel($parent->getLevel() + 1);
                $this->persistAsLastChildOf($folder, $parent);
            }
        }
        $em->flush();
    }
666938
@SuppressWarnings("WeakerAccess")
    public void update(int node, double centroid, int count, List<Double> data, boolean forceInPlace) {
        if (centroid == centroids[node]||forceInPlace) {
            // we prefer to update in place so repeated values don't shuffle around and for merging
            centroids[node] = centroid;
            counts[node] = count;
            if (datas != null) {
                datas[node] = data;
            }
        } else {
            // have to do full scale update
            this.centroid = centroid;
            this.count = count;
            this.data = data;
            tree.update(node);
        }
    }