Example #1
0
        public override void SaveClassControls(ITypeDict obj, TableLayoutPanel control)
        {
            CollectionBox lbxValue = (CollectionBox)control.Controls[0];

            for (int ii = 0; ii < lbxValue.Collection.Count; ii++)
            {
                obj.Set(lbxValue.Collection[ii]);
            }
        }
Example #2
0
        public override ITypeDict SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            CollectionBox lbxValue = (CollectionBox)control.Children[1];

            ITypeDict member              = (ITypeDict)Activator.CreateInstance(type);
            CollectionBoxViewModel mv     = (CollectionBoxViewModel)lbxValue.DataContext;
            List <object>          states = (List <object>)mv.GetList(typeof(List <object>));

            for (int ii = 0; ii < states.Count; ii++)
            {
                member.Set(states[ii]);
            }
            return(member);
        }
Example #3
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Array member)
        {
            LoadLabelControl(control, name);

            RankedListAttribute rangeAtt = ReflectionExt.FindAttribute <RankedListAttribute>(attributes);

            if (rangeAtt != null)
            {
                RankedCollectionBox lbxValue = new RankedCollectionBox();
                lbxValue.MaxHeight   = 180;
                lbxValue.DataContext = createViewModel(control, parent, name, type, attributes, member, rangeAtt.Index1);
                control.Children.Add(lbxValue);
            }
            else
            {
                CollectionBox lbxValue = new CollectionBox();
                lbxValue.MaxHeight   = 180;
                lbxValue.DataContext = createViewModel(control, parent, name, type, attributes, member, false);
                control.Children.Add(lbxValue);
            }
        }
Example #4
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IList member)
        {
            LoadLabelControl(control, name);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IList <>), member.GetType(), 0);

            CollectionBox lbxValue = new CollectionBox();

            lbxValue.MaxHeight = 180;
            CollectionBoxViewModel mv = new CollectionBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem += (int index, object element, CollectionBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + index + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes));

                //TODO: make this a member and reference it that way
                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true);

                frmData.SelectedOKEvent += async() =>
                {
                    object newElement = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true);

                    bool itemExists = false;

                    List <object> states = (List <object>)mv.GetList(typeof(List <object>));
                    for (int ii = 0; ii < states.Count; ii++)
                    {
                        //ignore the current index being edited
                        //if the element is null, then we are editing a new object, so skip
                        if (ii != index || element == null)
                        {
                            if (states[ii].Equals(newElement))
                            {
                                itemExists = true;
                            }
                        }
                    }

                    if (itemExists)
                    {
                        await MessageBox.Show(control.GetOwningForm(), "Cannot add duplicate states.", "Entry already exists.", MessageBox.MessageBoxButtons.Ok);
                    }
                    else
                    {
                        op(index, newElement);
                        frmData.Close();
                    }
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            List <object> states = new List <object>();

            foreach (object state in member)
            {
                states.Add(state);
            }
            mv.LoadFromList(states);
            control.Children.Add(lbxValue);
        }
Example #5
0
        public override void LoadClassControls(ITypeDict obj, TableLayoutPanel control)
        {
            CollectionBox lbxValue = new CollectionBox();

            lbxValue.Dock = DockStyle.Fill;
            lbxValue.Size = new Size(0, 150);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ITypeDict <>), obj.GetType(), 0);

            lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] {
            });
            //add lambda expression for editing a single element
            lbxValue.OnEditItem = (int index, object element, CollectionBox.EditElementOp op) =>
            {
                ElementForm frmData = new ElementForm();
                if (element == null)
                {
                    frmData.Text = "New " + elementType.Name;
                }
                else
                {
                    frmData.Text = element.ToString();
                }

                DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(StateCollection) [" + index + "]", elementType, new object[0] {
                }, element, true);

                frmData.OnOK += (object okSender, EventArgs okE) =>
                {
                    DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "StateCollection", elementType, new object[0] {
                    }, ref element, true);

                    bool itemExists = false;
                    for (int ii = 0; ii < lbxValue.Collection.Count; ii++)
                    {
                        if (ii != index)
                        {
                            if (lbxValue.Collection[ii].GetType() == element.GetType())
                            {
                                itemExists = true;
                            }
                        }
                    }

                    if (itemExists)
                    {
                        MessageBox.Show("Cannot add duplicate states.", "Entry already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        op(index, element);
                        frmData.Close();
                    }
                };
                frmData.OnCancel += (object okSender, EventArgs okE) =>
                {
                    frmData.Close();
                };

                frmData.Show();
            };

            List <object> states = new List <object>();

            foreach (object state in obj)
            {
                states.Add(state);
            }
            lbxValue.LoadFromList(typeof(List <object>), states);
            control.Controls.Add(lbxValue);
        }