Example #1
0
        private void BindNode(ISimulatorNode simNode, TreeNode node, TreeNodeCollection parent)
        {
            node.Text = simNode.DisplayName;
            node.Tag  = simNode;

            var menu = new ContextMenu();

            foreach (var nodeAction in simNode.Actions)
            {
                var action = new MenuItem(nodeAction.DisplayName);
                action.Click += new EventHandler(
                    delegate(Object o, EventArgs a)
                {
                    nodeAction.Invoke();
                }
                    );
                menu.MenuItems.Add(action);
            }

            if (simNode.Actions.Any())
            {
                menu.MenuItems.Add("-");
            }

            foreach (var factory in simNode.Children)
            {
                var action = new MenuItem(factory.DisplayName);
                action.Click += new EventHandler(
                    delegate(Object o, EventArgs a)
                {
                    var callbacks = new TreeNodeCallbacks(this);
                    var child     = factory.Create(callbacks);
                    if (child != null)
                    {
                        this.BindNode(child, callbacks.node, node.Nodes);
                    }
                }
                    );
                menu.MenuItems.Add(action);
            }

            if (simNode.Children.Any())
            {
                menu.MenuItems.Add("-");
            }

            var item = new MenuItem("Remove");

            item.Click += new EventHandler(
                delegate(Object o, EventArgs a)
            {
                ShutdownFrom(node);
                parent.Remove(node);
            }
                );

            menu.MenuItems.Add(item);
            node.ContextMenu = menu;
            parent.Add(node);
        }
        private void BindNode(ISimulatorNode simNode, TreeNode node, TreeNodeCollection parent)
        {
            node.Text = simNode.DisplayName;
            node.Tag = simNode;

            var menu = new ContextMenu();

            foreach (var nodeAction in simNode.Actions)
            {
                var action = new MenuItem(nodeAction.DisplayName);
                action.Click += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        nodeAction.Invoke();
                    }
                );
                menu.MenuItems.Add(action);
            }

            if (simNode.Actions.Any())
            {
                menu.MenuItems.Add("-");
            }

            foreach (var factory in simNode.Children)
            {
                var action = new MenuItem(factory.DisplayName);
                action.Click += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        var callbacks = new TreeNodeCallbacks(this);
                        var child = factory.Create(callbacks);
                        if (child != null)
                        {
                            this.BindNode(child, callbacks.node, node.Nodes);
                        }
                    }
                );
                menu.MenuItems.Add(action);
            }

            if (simNode.Children.Any())
            {
                menu.MenuItems.Add("-");
            }

            var item = new MenuItem("Remove");
            item.Click += new EventHandler(
                delegate(Object o, EventArgs a)
                {
                    ShutdownFrom(node);
                    parent.Remove(node);
                }
            );

            menu.MenuItems.Add(item);
            node.ContextMenu = menu;
            parent.Add(node);
        }