public DataObjectEditor(DataObjectEditor parent)
        {
            InitializeComponent();
            this.parent = parent;
            this.tableLayoutPanelFields.HorizontalScroll.Enabled = false;
            this.tableLayoutPanelFields.HorizontalScroll.Visible = false;
            this.classSelector = new ClassSelector();
            this.Collapsed     = false;

            OnObjectEdited += RefreshEditors;
        }
 private Json.DataObject CreateInstance(Type type, ClassSelector selector)
 {
     Json.DataObject obj = null;
     if (type.IsAbstract)
     {
         if (selector.Types == null)
         {
             selector.Types = Constructor.RegisteredTypes.Where((t) =>
                                                                !t.IsAbstract && type.IsAssignableFrom(t));
         }
         selector.StartPosition = FormStartPosition.CenterParent;
         if (selector.ShowDialog() == DialogResult.OK &&
             selector.SelectedType != null)
         {
             obj = Constructor.Construct(selector.SelectedType);
         }
     }
     else
     {
         obj = Constructor.Construct(type);
     }
     return(obj);
 }
        private void AddInlineRow(Accessor accessor, TableLayoutPanel tableLayout)
        {
            Type type = accessor.GetAccessorType();

            if (!typeof(Json.DataObject).IsAssignableFrom(type))
            {
                Console.WriteLine("Cannot have non-DataObject inline fields.");
                return;
            }

            string fieldName = GetHumanReadableField(accessor.GetName());
            string typeName  = GetHumanReadableField(accessor.GetAccessorType().Name);

            GroupBox box = new GroupBox();

            box.Text    = fieldName;
            box.Padding = new Padding(3);
            tableLayout.RowCount++;
            tableLayout.Controls.Add(box, 0, tableLayout.RowCount - 1);
            tableLayout.SetColumnSpan(box, 2);

            TableLayoutPanel innerPanel = new TableLayoutPanel();

            innerPanel.Location = new Point(3, 20);
            innerPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            innerPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
            innerPanel.RowStyles.Add(new RowStyle());
            box.Controls.Add(innerPanel);

            Json.DataObject obj = accessor.Get() as Json.DataObject;

            if (obj != null)
            {
                AddRows(obj, innerPanel, "[" + fieldName + "] ");
            }

            if (!accessor.IsReadOnly())
            {
                int index = inlineAccessors.Count;
                inlineAccessors.Add(accessor);

                FlowLayoutPanel flp = new FlowLayoutPanel();
                flp.AutoSize = true;
                innerPanel.RowCount++;
                innerPanel.Controls.Add(flp, 0, innerPanel.RowCount - 1);
                innerPanel.SetColumnSpan(flp, 2);

                Button buttonAdd = new Button();
                buttonAdd.Text     = "New " + typeName;
                buttonAdd.AutoSize = true;
                flp.Controls.Add(buttonAdd);

                Button buttonDelete = new Button();
                buttonDelete.Text     = "Delete";
                buttonDelete.AutoSize = true;
                flp.Controls.Add(buttonDelete);


                ClassSelector selector = new ClassSelector();
                buttonAdd.Click += (o, e) =>
                {
                    Json.DataObject nObj = CreateInstance(accessor.GetAccessorType(), selector);
                    if (nObj != null)
                    {
                        if (obj != null)
                        {
                            JsonSerializer.copyFields(obj, nObj);
                        }
                        accessor.Set(nObj);
                        UnloadObject();
                        LoadObject();
                        OnObjectEdited(this, new InlineEditAction(Index, index, obj, nObj));
                    }
                };

                buttonDelete.Click += (o, e) =>
                {
                    accessor.Set(null);
                    UnloadObject();
                    LoadObject();
                    OnObjectEdited(this, new InlineEditAction(Index, index, obj, null));
                };
            }

            innerPanel.Height = innerPanel.PreferredSize.Height;
            box.Height        = innerPanel.Height + 30;
            box.Width         = tableLayout.Width - 10;
        }