Copy nodes from one v2 Tree to another

We’re working on an application that allows a user to copy nodes from one tree to another. We have two trees and buttons between them. It turned out that copying nodes wasn’t as straightforward was we had hoped.

There were two issues. First when you add a node to a tree the first thing the component does is remove it from it’s current parent. Fortunately the XMLNode class provides a cloneNode function so before adding a node we only need to call cloneNode. The second issue is with branch settings. When you set a node as a branch using setIsBranch the Tree stores this information separately from the Tree’s data provider. Furthermore, there is no public method to retrieve branch information since getIsBranch will return true if the node is set as a branch OR if it has children.

In the end we created two functions, copySelectedNode clones and copies the selected node from one tree to another and then it calls copyIsBranchInfo to copy the branch information for the copied nodes. copyIsBranchInfo is a separate function since it needs to call itself recursively for all children of the copied node.

function copySelectedNode(fromTree:Tree, toTree:Tree):Void {

// do a deep clone so the copied node isn't removed from old tree
var fromNode:XMLNode = fromTree.selectedNode;
var toNode:XMLNode = fromNode.cloneNode(true);

toTree.addTreeNode(toNode);

copyIsBranchInfo(fromTree, fromNode, toTree, toNode);
}

function copyIsBranchInfo(fromTree:Tree,
fromNode:XMLNode,
toTree:Tree,
toNode:XMLNode):Void {
// Tree doesn't provide a method for checking if a node is
// absolutely set to a branch, it only has getIsBranch which returns
// true if it's set as a branch OR if it has children, which isn't what we
// want.
//
// branchNodes isn't defined as private, but it's clearly intended
// to be private. Iin order to accomlish a correct copy, we're
// going to access it anyways.
//

// if nothing is absolutely set, exit
if (fromTree.branchNodes == undefined) {
return;
}

if (fromTree.branchNodes[fromNode["getID"]()]) {
toTree.setIsBranch(toNode, true);
}

if (fromNode.hasChildNodes()) {
fromNode = fromNode.firstChild;
toNode = toNode.firstChild;
while (fromNode != undefined) {
copyIsBranchInfo(fromTree, fromNode, toTree, toNode);
fromNode = fromNode.nextSibling;
toNode = toNode.nextSibling;
}
}
}

copyButton.addEventListener("click",this);

function click(eventObj) {
copySelectedNode(leftTree, rightTree);
}

Flash Forward SF 2004 here I come!

I almost forgot to post anything about this until KeithÂ’s post reminded me. I’m heading out to San Francisco tomorrow to attend Flash Forward. This time I won’t be exhibiting or speaking so I should have a lot more time to attend sessions and hang out with people. I will try to blog some of the event and take a bunch of pictures. If will be out there make sure to say hello!

I will also have my laptop on me for anyone looking for a demo of BLDoc or our 3.0 release of the Charting Components

New PrimalScript update available

We won’t be posting this often, but since it’s the first update since the release of PrimalScript 3.1 I thought I would mention it. Sapien has released an update to PrimalScript that addresses some issues. You can find full details of what has changed here. In the future you can check if you are running the latest version of PrimalScript by select HELP > Check For Updates from within PrimalScript. Sapien released updates regularly so it’s good to get accustomed to checking for updates once in a while.

PrimalScript doesn’t have automatic update notifications so if you want to be notified of updates you can do this with some browsers. I added a bookmark to the change log and told FireFox to notify me when it changes. Instant update notifications.

When updating an existing installation, you only need to select the “Repair” option during setup. The installer will automatically update your existing installation.

Missing in Action @ MXDU

A little update. I wonÂ’t be speaking at MXDU as originally planned. I was really looking forward to it but my visa has yet to arrive from the Australian Embassy. Geoff has been really understanding about it and will have some contingency plans in place. Maybe IÂ’ll make it next year, and Peter take lots of pics!