/// <summary>
        ///
        /// </summary>
        /// <param name="expandState"></param>
        public void Expand(bool expandState)
        {
            // expand or collapse in a single transation
            StartTransaction(expandState? "Expand Tree": "Collapse Tree");

            // mark shape as expanded
            Expanded = expandState;

            // show/hide the plus or minus
            NExpandCollapseCheck check = GetExpandCollapseCheck();

            ((NPathPrimitive)check.Primitives.GetChildAt(1)).Visible = !expandState;
            ((NPathPrimitive)check.Primitives.GetChildAt(2)).Visible = expandState;

            // show/hide all outgoing shapes
            NNodeList nodes = GetOutgoingShapes();

            for (int i = 0; i < nodes.Count; i++)
            {
                NShape shape = (nodes[i] as NShape);
                shape.Visible = expandState;
            }

            // show/hide all destination shapes
            nodes = GetDestinationShapes();
            for (int i = 0; i < nodes.Count; i++)
            {
                NShape shape = (nodes[i] as NShape);
                shape.Visible = expandState;
            }

            // expand/collapse the destination shapes
            for (int i = 0; i < nodes.Count; i++)
            {
                NExpandableShape expandableShape = (nodes[i] as NExpandableShape);
                if (expandableShape != null)
                {
                    expandableShape.Expand(expandState);
                }
            }

            // commit the transaction
            Commit();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        public override void OnMouseDown(NMouseEventArgs e)
        {
            // handle only the left mouse down single click on the check box
            if (e.Button == MouseButtons.Left || e.Clicks == 1)
            {
                NExpandCollapseCheck check = GetExpandCollapseCheck();

                // check to see if the hit was on some of the check box children
                if (NSceneTree.IsAncestorOfNode(check, e.HitNode))
                {
                    Expand(!Expanded);

                    // mark as processed and return (stops event bubbling)
                    e.Processed = true;
                    return;
                }
            }

            // bubble event to previous mouse event handler
            base.OnMouseDown(e);
        }
        public NExpandableShape()
        {
            // add a rectangle shape as base
            NRectangleShape rect = new NRectangleShape(new NRectangleF(0, 0, 100, 100));

            rect.DestroyShapeElements(ShapeElementsMask.All);
            rect.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit);
            Shapes.AddChild(rect);

            // add an expand collapse shape
            NExpandCollapseCheck check = new NExpandCollapseCheck();

            check.Bounds            = new NRectangleF(105, 0, 10, 10);
            check.Protection        = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit);
            check.ResizeInAggregate = ResizeInAggregate.RepositionOnly;
            Shapes.AddChild(check);

            // update the model bounds with the rectangle bounds
            UpdateModelBounds(rect.Transform.TransformBounds(rect.ModelBounds));

            // initially it is expanded
            m_bExpanded = true;

            // by default the group has one dynamic port anchored to the rectangle
            CreateShapeElements(ShapeElementsMask.Ports);
            NDynamicPort port = new NDynamicPort(rect.UniqueId, ContentAlignment.MiddleCenter, DynamicPortGlueMode.GlueToContour);

            Ports.AddChild(port);
            Ports.DefaultInwardPortUniqueId = port.UniqueId;

            // by default the group has one rotated bounds port anchored to the rectangle
            CreateShapeElements(ShapeElementsMask.Labels);
            NRotatedBoundsLabel label = new NRotatedBoundsLabel("", rect.UniqueId, new Nevron.Diagram.NMargins(10));

            Labels.AddChild(label);
            Labels.DefaultLabelUniqueId = label.UniqueId;
        }