/// <summary>
		/// Constructor. Initializes the dialog and populates the tree.
		/// </summary>
		public GXDataIOSourceDialog(GXDataIOSource dataIOSource, GXDataIOSourceAttribute sourceAttributes, GXDevice device)
        {
            InitializeComponent();
			PopulateTree(dataIOSource, sourceAttributes, device);
        }
		private void PopulateTree(GXDataIOSource dataIOSource, GXDataIOSourceAttribute sourceAttributes, object root)
		{
			GXDevice device = null;
			GXDeviceList devList = null;
			if (root is GXDevice)
			{
				device = root as GXDevice;
			}
			else if (root is GXDeviceList)
			{
				devList = root as GXDeviceList;
			}            

			object target = dataIOSource.Target;
			SourceAttributes = sourceAttributes;
			long UsedDataSources = -1;
			if (SourceAttributes != null)
			{
				UsedDataSources = (long)SourceAttributes.UsedDataSources;
			}
			TreeNode selNode = null;
			if (device != null)
			{
				TreeNode deviceNode;
				CreateDeviceNode(device, target, UsedDataSources, out deviceNode, ref selNode);
				this.DataSourceTree.Nodes.Add(deviceNode);
			}
			else if (devList != null)
			{
				TreeNode listNode = new TreeNode(devList.Name, 0, 0);
				listNode.Tag = devList;
				this.DataSourceTree.Nodes.Add(listNode);

				CreateDeviceGroupNodes(devList.DeviceGroups, listNode, target, ref selNode, UsedDataSources);
			}

			if (selNode != null)
			{
				this.DataSourceTree.SelectedNode = selNode;
			}
			else
			{
				this.DataSourceTree.SelectedNode = this.DataSourceTree.Nodes[0];
			}
		}