Наследование: nHydrate.Generator.Common.GeneratorFramework.BaseModelObjectController
Пример #1
0
        public override void Refresh()
        {
            try
            {
                if ((this.TreeView != null) && (this.TreeView.InvokeRequired))
                {
                    this.TreeView.Invoke(new EmptyDelegate(this.Refresh));
                    return;
                }

                this.Text               = "Fields";
                this.Name               = "Fields";
                this.ImageIndex         = ImageHelper.GetImageIndex(TreeIconConstants.FolderClose);
                this.SelectedImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderOpen);

                //Add new nodes
                var referenceCollection = (ReferenceCollection)this.Object;

                //Save the selected item
                var selectedKey = string.Empty;
                if ((this.TreeView != null) && (this.TreeView.SelectedNode != null) && (this.Nodes.Contains(this.TreeView.SelectedNode)))
                {
                    var reference = referenceCollection.GetByKey(this.TreeView.SelectedNode.Name);
                    if (reference != null)
                    {
                        selectedKey = ((CustomAggregateColumn)reference.Object).Key;
                    }
                }

                foreach (Reference reference in referenceCollection)
                {
                    if (this.Nodes.Find(reference.Key, false).Length == 0)
                    {
                        var tc = new CustomAggregateColumnController(reference.Object);
                        tc.Node.Name = reference.Key;
                        tc.Node.Text = ((CustomAggregateColumn)reference.Object).Name;
                        this.Nodes.Add(tc.Node);
                    }
                }

                //Rename nodes if name change
                foreach (TreeNode node in this.Nodes)
                {
                    var item = referenceCollection.FirstOrDefault(x => x.Key == node.Name);
                    if (item != null)
                    {
                        node.Text = ((CustomAggregateColumn)item.Object).Name;
                    }
                }

                //Remove non-existing nodes
                for (var ii = this.Nodes.Count - 1; ii >= 0; ii--)
                {
                    var node = (CustomAggregateColumnNode)this.Nodes[ii];
                    if (!referenceCollection.Contains(node.Name))
                    {
                        this.Nodes.RemoveAt(ii);
                    }
                }

                //Save the selected item
                if ((this.TreeView != null) && (!string.IsNullOrEmpty(selectedKey)))
                {
                    foreach (TreeNode node in this.Nodes)
                    {
                        var reference = referenceCollection.GetByKey(node.Name);
                        if ((reference != null) && (selectedKey == ((CustomAggregateColumn)reference.Object).Key))
                        {
                            this.TreeView.SelectedNode = node;
                        }
                    }
                }

                this.Sort();

                this.Controller.UIControl.Refresh();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 public CustomAggregateColumnNode(CustomAggregateColumnController controller)
   : base(controller)
 {
 }
Пример #3
0
 public CustomAggregateColumnNode(CustomAggregateColumnController controller)
     : base(controller)
 {
 }
		public override void Refresh()
		{
			try
			{
				if((this.TreeView != null) && (this.TreeView.InvokeRequired))
				{
					this.TreeView.Invoke(new EmptyDelegate(this.Refresh));
					return;
				}

				this.Text = "Fields";
				this.Name = "Fields";
				this.ImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderClose);
				this.SelectedImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderOpen);

				//Add new nodes
				var referenceCollection = (ReferenceCollection)this.Object;

				//Save the selected item
				var selectedKey = string.Empty;
				if((this.TreeView != null) && (this.TreeView.SelectedNode != null) && (this.Nodes.Contains(this.TreeView.SelectedNode)))
				{
					var reference = referenceCollection.GetByKey(this.TreeView.SelectedNode.Name);
					if(reference != null)
						selectedKey = ((CustomAggregateColumn)reference.Object).Key;
				}

				foreach(Reference reference in referenceCollection)
				{
					if(this.Nodes.Find(reference.Key, false).Length == 0)
					{
						var tc = new CustomAggregateColumnController(reference.Object);
						tc.Node.Name = reference.Key;
						tc.Node.Text = ((CustomAggregateColumn)reference.Object).Name;
						this.Nodes.Add(tc.Node);
					}
				}

				//Rename nodes if name change
				foreach (TreeNode node in this.Nodes)
				{
					var item = referenceCollection.FirstOrDefault(x => x.Key == node.Name);
					if (item != null) node.Text = ((CustomAggregateColumn)item.Object).Name;
				}

				//Remove non-existing nodes
				for(var ii = this.Nodes.Count - 1 ; ii >= 0 ; ii--)
				{
					var node = (CustomAggregateColumnNode)this.Nodes[ii];
					if(!referenceCollection.Contains(node.Name))
					{
						this.Nodes.RemoveAt(ii);
					}
				}

				//Save the selected item      
				if((this.TreeView != null) && (!string.IsNullOrEmpty(selectedKey)))
				{
					foreach(TreeNode node in this.Nodes)
					{
						var reference = referenceCollection.GetByKey(node.Name);
						if((reference != null) && (selectedKey == ((CustomAggregateColumn)reference.Object).Key))
							this.TreeView.SelectedNode = node;
					}
				}

				this.Sort();

				this.Controller.UIControl.Refresh();

			}
			catch(Exception ex)
			{
				throw;
			}

		}