public CollectionPropertyEditor(
     Dictionary <string, string> properties,
     string propertyName,
     CollectionPropertyEditorUtils.CollectionType collectionType,
     Func <Dictionary <string, string>, string, PropertyEditor <T> > creator
     )
     : base(properties, propertyName)
 {
     m_collectonType = collectionType;
     m_creator       = creator;
     if (m_creator == null)
     {
         throw new Exception("Creator function cannot be null!");
     }
     InitializeComponent();
 }
                public FieldContainer(
                    EditorDialog dialog,
                    CollectionPropertyEditorUtils.CollectionType collectionType,
                    Func <Dictionary <string, string>, string, PropertyEditor <T> > creator,
                    string jsonValue,
                    string memberName = null
                    )
                {
                    m_collectionType = collectionType;
                    m_creator        = creator;
                    if (m_creator == null)
                    {
                        throw new Exception("Creator cannot be null!");
                    }
                    MetroSkinManager.ApplyMetroStyle(this);
                    Height = 0;

                    MetroTile remove = new MetroTile();

                    MetroSkinManager.ApplyMetroStyle(remove);
                    remove.Text               = "-";
                    remove.TextAlign          = ContentAlignment.MiddleCenter;
                    remove.TileTextFontWeight = MetroTileTextWeight.Bold;
                    remove.Width              = DEFAULT_BUTTON_SIZE + DEFAULT_BUTTON_SIZE;
                    remove.Height             = DEFAULT_BUTTON_SIZE;
                    remove.Left               = Width - remove.Width;
                    remove.Anchor             = AnchorStyles.Top | AnchorStyles.Right;
                    remove.Click             += new EventHandler(remove_Click);
                    Controls.Add(remove);

                    MetroTile add = new MetroTile();

                    MetroSkinManager.ApplyMetroStyle(add);
                    add.Text               = "+";
                    add.TextAlign          = ContentAlignment.MiddleCenter;
                    add.TileTextFontWeight = MetroTileTextWeight.Bold;
                    add.Width              = DEFAULT_BUTTON_SIZE + DEFAULT_BUTTON_SIZE;
                    add.Height             = DEFAULT_BUTTON_SIZE;
                    add.Left               = Width - add.Width - DEFAULT_SEPARATOR - remove.Width;
                    add.Anchor             = AnchorStyles.Top | AnchorStyles.Right;
                    add.Click             += new EventHandler(add_Click);
                    Controls.Add(add);

                    Height += Math.Max(add.Height, remove.Height);

                    if (m_collectionType == CollectionPropertyEditorUtils.CollectionType.JsonObject)
                    {
                        m_memberTextBox = new MetroTextBox();
                        MetroSkinManager.ApplyMetroStyle(m_memberTextBox);
                        m_memberTextBox.Text         = memberName;
                        m_memberTextBox.Width        = Width;
                        m_memberTextBox.Top          = Height;
                        m_memberTextBox.Anchor       = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        m_memberTextBox.TextChanged += new EventHandler(m_memberTextBox_TextChanged);
                        Controls.Add(m_memberTextBox);
                        Height += m_memberTextBox.Height;
                    }

                    try
                    {
                        m_propertyEditor = m_creator(m_imHereForNothing, "-.-");
                        if (m_propertyEditor == null)
                        {
                            throw new Exception("Property editor couldn't be created properly!");
                        }
                        MetroUserControl editor   = m_propertyEditor as MetroUserControl;
                        IEditorJsonValue jvEditor = m_propertyEditor as IEditorJsonValue;
                        if (editor != null && jvEditor != null)
                        {
                            jvEditor.Text      = "Item";
                            jvEditor.JsonValue = jsonValue;
                            jvEditor.UpdateEditorValue();
                            editor.Width  = Width;
                            editor.Top    = Height;
                            editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            Controls.Add(editor);
                            Height += editor.Height;
                        }
                    }
                    catch (Exception ex)
                    {
                        while (ex.InnerException != null)
                        {
                            ex = ex.InnerException;
                        }
                        ErrorPropertyEditor editor = new ErrorPropertyEditor("Item", ex.Message);
                        editor.Tag    = string.Format("{0}\n{1}\n\nStack trace:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                        editor.Width  = Width;
                        editor.Top    = Height;
                        editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        Controls.Add(editor);
                        Height += editor.Height;
                    }
                }
            public EditorDialog(
                CollectionPropertyEditorUtils.CollectionType collectionType,
                Func <Dictionary <string, string>, string, PropertyEditor <T> > creator
                )
            {
                m_collectionType = collectionType;
                m_creator        = creator;

                MetroSkinManager.ApplyMetroStyle(this);
                Text          = "Collection Editor";
                TextAlign     = MetroFormTextAlign.Center;
                Size          = DEFAULT_SIZE;
                ShowInTaskbar = false;
                ControlBox    = false;
                Resizable     = false;
                DialogResult  = DialogResult.None;

                MetroPanel panel = new MetroPanel();

                MetroSkinManager.ApplyMetroStyle(panel);
                panel.Dock = DockStyle.Fill;
                Controls.Add(panel);

                MetroPanel contentPanel = new MetroPanel();

                MetroSkinManager.ApplyMetroStyle(contentPanel);
                contentPanel.Width  = panel.Width;
                contentPanel.Height = panel.Height - DEFAULT_BUTTON_HEIGHT - DEFAULT_SEPARATOR - DEFAULT_BUTTON_HEIGHT - 16;
                contentPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
                panel.Controls.Add(contentPanel);

                m_content = new MetroPanel();
                MetroSkinManager.ApplyMetroStyle(m_content);
                m_content.Dock = DockStyle.Fill;
                m_content.Controls.Clear();
                contentPanel.Controls.Add(m_content);

                m_contentScrollbarV = new MetroScrollBar(MetroScrollOrientation.Vertical);
                MetroSkinManager.ApplyMetroStyle(m_contentScrollbarV);
                m_contentScrollbarV.Dock    = DockStyle.Right;
                m_contentScrollbarV.Scroll += new ScrollEventHandler(m_contentScrollbarV_Scroll);
                contentPanel.Controls.Add(m_contentScrollbarV);

                m_addButton = new MetroTile();
                MetroSkinManager.ApplyMetroStyle(m_addButton);
                m_addButton.Text               = "Add Item";
                m_addButton.TextAlign          = ContentAlignment.MiddleCenter;
                m_addButton.TileTextFontWeight = MetroTileTextWeight.Bold;
                m_addButton.Width              = panel.Width;
                m_addButton.Height             = DEFAULT_BUTTON_HEIGHT;
                m_addButton.Top    = panel.Height - DEFAULT_BUTTON_HEIGHT - DEFAULT_SEPARATOR - DEFAULT_BUTTON_HEIGHT;
                m_addButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
                m_addButton.Click += new EventHandler(m_addButton_Click);
                panel.Controls.Add(m_addButton);

                m_okButton = new MetroTile();
                MetroSkinManager.ApplyMetroStyle(m_okButton);
                m_okButton.Text               = "OK";
                m_okButton.TextAlign          = ContentAlignment.MiddleCenter;
                m_okButton.TileTextFontWeight = MetroTileTextWeight.Bold;
                m_okButton.Width              = panel.Width;
                m_okButton.Height             = DEFAULT_BUTTON_HEIGHT;
                m_okButton.Top    = panel.Height - DEFAULT_BUTTON_HEIGHT;
                m_okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
                m_okButton.Click += new EventHandler(m_okButton_Click);
                panel.Controls.Add(m_okButton);
            }