Called from the root tree node when a new node is inserted into tree. This method creates properties
            to represent the node for display and inserts it into the item model controller.
332556
def __insert_child(self, parent_tree_node, index, tree_node):
        
        # manage the item model
        parent_item = self.__mapping[id(parent_tree_node)]
        self.item_model_controller.begin_insert(index, index, parent_item.row, parent_item.id)
        properties = {
            "display": self.__display_for_tree_node(tree_node),
            "tree_node": tree_node  # used for removal and other lookup
        }
        item = self.item_model_controller.create_item(properties)
        parent_item.insert_child(index, item)
        self.__mapping[id(tree_node)] = item
        self.item_model_controller.end_insert()
901859
def fill_treeview(self, tree, input_dict):
        

        tree.model().removeRows(0, tree.model().rowCount())

        def add_element(item, key, value):
            child_name = QtWidgets.QStandardItem(key)

            if isinstance(value, dict):
                for key_child, value_child in value.items():
                    add_element(child_name, key_child, value_child)
                item.appendRow(child_name)
            else:
                child_value = QtWidgets.QStandardItem(str(value))

                item.appendRow([child_name, child_value])

        for index, (key, value) in enumerate(input_dict.items()):

            if isinstance(value, dict):
                item = QtWidgets.QStandardItem(key)
                for sub_key, sub_value in value.items():
                    add_element(item, sub_key, sub_value)
                tree.model().appendRow(item)
            elif isinstance(value, str):
                item = QtGui.QStandardItem(key)
                item_value = QtGui.QStandardItem(value)
                item_value.setEditable(True)
                item_value.setSelectable(True)
                tree.model().appendRow([item, item_value])
691616
def insert(self, key):
        
        # Create new node
        n = TreeNode(key)
        if not self.node:
            self.node = n
            self.node.left = AvlTree()
            self.node.right = AvlTree()
        elif key < self.node.val:
            self.node.left.insert(key)
        elif key > self.node.val:
            self.node.right.insert(key)
        self.re_balance()
1205821
public void gotoEnd() {
	currentNode = tree;
	while (currentNode.hasChildren()) {
	    currentNode = currentNode.getChildren().get(
		    currentNode.getChildren().size() - 1);
	}
    }
411079
function _new_node_at(bnode, level){

	ll("adding " + bnode.id() + " at level " + level + "!");

	// Create new vertex and add to set.
	var new_vertex = new bbop.layout.sugiyama.simple_vertex(bnode.id());
	new_vertex.level = level;
	vertex_set[ new_vertex.id() ] = new_vertex;
	
	// Check the node in to the 'seen' references.
	first_seen_reference[ new_vertex.id() ] = level;
	last_seen_reference[ new_vertex.id() ] = level;		 
    }
483413
public boolean addProposedItem(final ItemsNodeInterval newNode) {
        Preconditions.checkState(newNode.getItems().size() == 1, "Invalid node=%s", newNode);
        final Item item = newNode.getItems().get(0);

        return addNode(newNode, new AddNodeCallback() {
            @Override
            public boolean onExistingNode(final NodeInterval existingNode) {
                // If we receive a new proposed that is the same kind as the reversed existing (current node),
                // we match existing and proposed. If not, we keep the proposed item as-is outside of the tree.
                if (isSameKind((ItemsNodeInterval) existingNode)) {
                    final ItemsInterval existingOrNewNodeItems = ((ItemsNodeInterval) existingNode).getItemsInterval();
                    existingOrNewNodeItems.cancelItems(item);
                    return true;
                } else {
                    return false;
                }
            }

            @Override
            public boolean shouldInsertNode(final NodeInterval insertionNode) {
                // At this stage, we're currently merging a proposed item that does not fit any of the existing intervals.
                // If this new node is about to be inserted at the root level, this means the proposed item overlaps any
                // existing item. We keep these as-is, outside of the tree: they will become part of the resulting list.
                if (insertionNode.isRoot()) {
                    return false;
                }

                // If we receive a new proposed that is the same kind as the reversed existing (parent node),
                // we want to insert it to generate a piece of repair (see SubscriptionItemTree#buildForMerge).
                // If not, we keep the proposed item as-is outside of the tree.
                return isSameKind((ItemsNodeInterval) insertionNode);
            }

            private boolean isSameKind(final ItemsNodeInterval insertionNode) {
                final List<Item> insertionNodeItems = insertionNode.getItems();
                Preconditions.checkState(insertionNodeItems.size() == 1, "Expected existing node to have only one item");
                final Item insertionNodeItem = insertionNodeItems.get(0);
                return insertionNodeItem.isSameKind(item);
            }
        });
    }
1306275
def add_root(cls, **kwargs):
        """"""

        # do we have a root node already?
        last_root = cls.get_last_root_node()

        if last_root and last_root.node_order_by:
            # there are root nodes and node_order_by has been set
            # delegate sorted insertion to add_sibling
            return last_root.add_sibling('sorted-sibling', **kwargs)

        if last_root:
            # adding the new root node as the last one
            newtree_id = last_root.tree_id + 1
        else:
            # adding the first root node
            newtree_id = 1

        if len(kwargs) == 1 and 'instance' in kwargs:
            # adding the passed (unsaved) instance to the tree
            newobj = kwargs['instance']
            if newobj.pk:
                raise NodeAlreadySaved("Attempted to add a tree node that is "\
                    "already in the database")
        else:
            # creating the new object
            newobj = get_result_class(cls)(**kwargs)

        newobj.depth = 1
        newobj.tree_id = newtree_id
        newobj.lft = 1
        newobj.rgt = 2
        # saving the instance before returning it
        newobj.save()
        return newobj
799597
private void initTopicTree() {
        try {
            Object data = view.getViewData();
            
            if (!(data instanceof TopicTree)) {
                return;
            }
            
            TopicTree topicTree = (TopicTree) data;
            HelpTopicNode baseNode;
            
            if (helpViewType == HelpViewType.TOC) {
                HelpTopic topic = new HelpTopic(null, hs.getName(), hs.getName());
                baseNode = new HelpTopicNode(topic);
                rootNode.addChild(baseNode);
            } else {
                baseNode = rootNode;
            }
            
            initTopicTree(baseNode, topicTree.getRoot());
            
        } catch (IOException e) {
            return;
        }
        
    }
1019390
public void addNode(NodeT node) {
        node.setOwner(this);
        nodeTable.put(node.key(), node);
    }
352065
private function SaveNew()
    {
        $treeBuilder = new TreeBuilder(new PageTreeProvider($this->site));
        $treeBuilder->Insert($this->page, $this->parent, $this->previous);
    }
411380
function (node, newNode) {
        return node.nextSibling ? node.parentNode.insertBefore(newNode, node.nextSibling):
            node.parentNode.appendChild(newNode);
    }
591223
def __initialize_node(self, attributes_flags=int(Qt.ItemIsSelectable | Qt.ItemIsEnabled)):
        

        self["traced"] = umbra.ui.nodes.GraphModelAttribute(name="traced",
                                                            value=foundations.trace.is_traced(self.__module),
                                                            flags=attributes_flags)
        self.update_node_attributes()
914555
private void onItemSelected(TreeItem treeItem) {

        treeItem.getElement().focus();
        final LinkedList<String> path = resolvePath(treeItem);

        formView.clearDisplay();
        descView.clearDisplay();

        ModelNode address = toAddress(path);
        ModelNode displayAddress = address.clone();

        boolean isPlaceHolder = (treeItem instanceof PlaceholderItem);
        //ChildInformation childInfo = findChildInfo(treeItem);

        if(path.size()%2==0) {

            /*String denominatorType = AddressUtils.getDenominatorType(address.asPropertyList());
            boolean isSingleton = denominatorType!=null ? childInfo.isSingleton(denominatorType) : false; // false==root*/

            // addressable resources
            presenter.readResource(address, isPlaceHolder);

            toggleEditor(true);
            filter.setEnabled(true);

        }
        else {
            toggleEditor(false);
            // display tweaks
            displayAddress.add(path.getLast(), WILDCARD);

            // force loading of children upon selection
            loadChildren((ModelTreeItem)treeItem, false);
            filter.setEnabled(false);
        }

        nodeHeader.updateDescription(displayAddress);
    }
1025569
private void loadCustomNodeChildren(final TreeItemIdNode node) {

		// Check node was flagged as having children or already has children
		if (!node.hasChildren() || !node.getChildren().isEmpty()) {
			return;
		}

		// Get the row index for the node
		String itemId = node.getItemId();
		List<Integer> rowIndex = getRowIndexForCustomItemId(itemId);

		// Get the tree item model
		TreeItemModel model = getTreeModel();

		// Check tree item is expandable and has children
		if (!model.isExpandable(rowIndex) || !model.hasChildren(rowIndex)) {
			node.setHasChildren(false);
			return;
		}

		// Check actual child count (could have no children even though hasChildren returned true)
		int count = model.getChildCount(rowIndex);
		if (count <= 0) {
			node.setHasChildren(false);
			return;
		}

		// Get the map of item ids already in the custom tree
		Map<String, TreeItemIdNode> mapIds = getCustomIdNodeMap();

		// Add children of item to the node tree
		boolean childAdded = false;
		for (int i = 0; i < count; i++) {
			List<Integer> childIdx = new ArrayList<>(rowIndex);
			childIdx.add(i);
			String childItemId = model.getItemId(childIdx);
			// Check the child item is not already in the custom tree
			if (mapIds.containsKey(childItemId)) {
				continue;
			}
			TreeItemIdNode childNode = new TreeItemIdNode(childItemId);
			childNode.setHasChildren(model.hasChildren(childIdx));
			node.addChild(childNode);
			childAdded = true;
			// For client mode we have to drill down all the children
			if (childNode.hasChildren() && getExpandMode() == WTree.ExpandMode.CLIENT) {
				loadCustomNodeChildren(childNode);
			}
		}
		// This could happen if all the children have been used in the custom map
		if (!childAdded) {
			node.setHasChildren(false);
		}

	}
1270741
private NodeImpl doAddNode(NodeImpl parentNode, InternalQName name, InternalQName primaryTypeName,
      NodeDefinitionData nodeDef) throws ItemExistsException, RepositoryException, ConstraintViolationException,
      VersionException, LockException
   {
      validateChildNode(parentNode, name, primaryTypeName, nodeDef);

      // Initialize data
      InternalQName[] mixinTypeNames = new InternalQName[0];
      String identifier = IdGenerator.generate();

      int orderNum = parentNode.getNextChildOrderNum();
      int index = parentNode.getNextChildIndex(name, primaryTypeName, parentNode.nodeData(), nodeDef);

      QPath path = QPath.makeChildPath(parentNode.getInternalPath(), name, index);

      AccessControlList acl = parentNode.getACL();

      // create new nodedata, [PN] fix of use index as persisted version
      NodeData nodeData =
         new TransientNodeData(path, identifier, -1, primaryTypeName, mixinTypeNames, orderNum, parentNode
            .getInternalIdentifier(), acl);

      // Create new Node
      ItemState state = ItemState.createAddedState(nodeData, false);
      NodeImpl node = (NodeImpl)dataManager.update(state, true);

      NodeTypeDataManager ntmanager = session.getWorkspace().getNodeTypesHolder();
      ItemAutocreator itemAutocreator = new ItemAutocreator(ntmanager, valueFactory, dataManager, true);

      PlainChangesLog changes =
         itemAutocreator.makeAutoCreatedItems(node.nodeData(), primaryTypeName, dataManager, session.getUserID());
      for (ItemState autoCreatedState : changes.getAllStates())
      {
         dataManager.updateItemState(autoCreatedState);
      }

      session.getActionHandler().postAddNode(node);

      return node;
   }
409097
protected void layout(TreeNode node) {
    if (node != null) {
      TreeNode child = node.child;

      while (child != null) {
        layout(child);
        child = child.next;
      }

      if (node.child != null) {
        attachParent(node, join(node));
      } else {
        layoutLeaf(node);
      }
    }
  }
1059317
private void addChildrenForOUNode(CmsOrganizationalUnit item) {

        List<Object> itemsToRemove = new ArrayList<Object>();

        Collection<?> childCol = m_treeContainer.getChildren(item);
        if (childCol != null) {
            itemsToRemove.addAll(childCol);
        }

        try {
            if (m_app.isOUManagable(item.getName())) {

                List<I_CmsOuTreeType> types = m_app.getTreeTypeProvider().getTreeTypes();
                for (I_CmsOuTreeType type : types) {
                    if (!type.isValidForOu(m_cms, item.getName())) {
                        continue;
                    }
                    if (type.isOrgUnit()) {
                        continue;
                    }
                    String itemId = type.getId() + item.getName();
                    Item newItem = m_treeContainer.addItem(itemId);
                    itemsToRemove.remove(itemId);
                    if (newItem != null) {
                        newItem.getItemProperty(PROP_NAME).setValue(getIconCaptionHTML(itemId, type));
                        newItem.getItemProperty(PROP_TYPE).setValue(type);
                        m_treeContainer.setParent(itemId, item);
                        setChildrenAllowed(itemId, type.isExpandable());
                    }
                }
            }
            List<CmsOrganizationalUnit> ous = OpenCms.getOrgUnitManager().getOrganizationalUnits(
                m_cms,
                item.getName(),
                false);
            List<CmsOrganizationalUnit> webOus = new ArrayList<CmsOrganizationalUnit>();
            for (CmsOrganizationalUnit ou : ous) {
                if (m_app.isParentOfManagableOU(ou.getName())) {
                    itemsToRemove.remove(ou);
                    if (ou.hasFlagWebuser()) {
                        webOus.add(ou);
                    } else {
                        addOuToTree(ou, item);
                    }
                }
            }
            for (CmsOrganizationalUnit ou : webOus) {
                if (m_app.isParentOfManagableOU(ou.getName())) {
                    itemsToRemove.remove(ou);
                    addOuToTree(ou, item);
                }
            }
        } catch (CmsException e) {
            LOG.error("Can't read ou", e);
        }
        for (Object it : itemsToRemove) {
            m_treeContainer.removeItemRecursively(it);
        }
    }