Пример #1
0
        public void AddKeyListKeys(
            StackPanel view, string key,
            List <AdminShell.Key> keys,
            ModifyRepo repo = null,
            AdminShell.PackageEnv package = null,
            string addExistingEntities    = null)
        {
            // sometimes needless to show
            if (repo == null && (keys == null || keys.Count < 1))
            {
                return;
            }
            int rows = 1; // default!

            if (keys != null && keys.Count > 1)
            {
                rows = keys.Count;
            }
            int rowOfs = 0;

            if (repo != null)
            {
                rowOfs = 1;
            }

            // Grid
            var g = new Grid();

            g.Margin = new Thickness(0, 0, 0, 0);

            // 0 key
            var gc = new ColumnDefinition();

            gc.Width = new GridLength(100);
            g.ColumnDefinitions.Add(gc);

            // 1 type
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 2 local
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 3 id type
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 4 value
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Star);
            g.ColumnDefinitions.Add(gc);

            // 5 buttons behind it
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // rows
            for (int r = 0; r < rows + rowOfs; r++)
            {
                var gr = new RowDefinition();
                gr.Height = new GridLength(1.0, GridUnitType.Auto);
                g.RowDefinitions.Add(gr);
            }

            // populate key
            AddSmallLabelTo(g, 0, 0, margin: new Thickness(5, 0, 0, 0), content: "" + key + ":");

            // populate [+] and [Select] buttons
            if (repo != null)
            {
                var g2 = AddSmallGrid(1, 3, new string[] { "*", "#", "#" });
                Grid.SetRow(g2, 0);
                Grid.SetColumn(g2, 1);
                Grid.SetColumnSpan(g2, 5);
                g.Children.Add(g2);

                if (addExistingEntities != null && package != null)
                {
                    repo.RegisterControl(AddSmallButtonTo(g2, 0, 1, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "Add existing"),
                                         (o) => {
                        var k2 = SmartSelectAasEntityKeys(package.AasEnv, addExistingEntities);
                        if (k2 != null)
                        {
                            keys.Clear();
                            keys.AddRange(k2);
                        }
                        return(new ModifyRepo.LambdaActionRedrawEntity());
                    });
                }

                repo.RegisterControl(AddSmallButtonTo(g2, 0, 2, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "Add blank"),
                                     (o) => {
                    var k = new AdminShell.Key();
                    keys.Add(k);
                    return(new ModifyRepo.LambdaActionRedrawEntity());
                });
            }

            // contents?
            if (keys != null)
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    if (repo == null)
                    {
                        // lang
                        AddSmallLabelTo(g, 0 + i + rowOfs, 1, padding: new Thickness(2, 0, 0, 0), content: "(" + keys[i].type + ")");

                        // local
                        AddSmallLabelTo(g, 0 + i + rowOfs, 2, padding: new Thickness(2, 0, 0, 0), content: "" + ((keys[i].local) ? "(Local)" : "(no-Local)"));

                        // id type
                        AddSmallLabelTo(g, 0 + i + rowOfs, 3, padding: new Thickness(2, 0, 0, 0), content: "[" + keys[i].idType + "]");

                        // value
                        AddSmallLabelTo(g, 0 + i + rowOfs, 4, padding: new Thickness(2, 0, 0, 0), content: "" + keys[i].value);
                    }

                    else
                    {
                        // save in current context
                        var currentI = 0 + i;

                        // type
                        var cbType = repo.RegisterControl(
                            AddSmallComboBoxTo(g, 0 + i + rowOfs, 1, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].type,
                                               minWidth: 100, items: AdminShell.Key.KeyElements, isEditable: false),
                            (o) =>
                        {
                            keys[currentI].type = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        }) as ComboBox;
                        SmallComboBoxSelectNearestItem(cbType, cbType.Text);

                        // local
                        repo.RegisterControl(
                            AddSmallCheckBoxTo(g, 0 + i + rowOfs, 2, margin: new Thickness(2, 2, 2, 2), content: "local", isChecked: keys[currentI].local),
                            (o) =>
                        {
                            keys[currentI].local = (bool)o;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // id type
                        repo.RegisterControl(
                            AddSmallComboBoxTo(g, 0 + i + rowOfs, 3, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].idType,
                                               minWidth: 100, items: AdminShell.Key.IdentifierTypeNames, isEditable: false),
                            (o) =>
                        {
                            keys[currentI].idType = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // value
                        repo.RegisterControl(
                            AddSmallTextBoxTo(g, 0 + i + rowOfs, 4, margin: new Thickness(2, 2, 2, 2), text: "" + keys[currentI].value),
                            (o) =>
                        {
                            keys[currentI].value = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // button [-]
                        repo.RegisterControl(AddSmallButtonTo(g, 0 + i + rowOfs, 5, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "-"),
                                             (o) => {
                            keys.RemoveAt(currentI);
                            return(new ModifyRepo.LambdaActionRedrawEntity());
                        });
                    }
                }
            }

            // in total
            view.Children.Add(g);
        }
Пример #2
0
        public void AddAction(StackPanel view, string key, string[] actionStr, ModifyRepo repo = null, Func <object, ModifyRepo.LambdaAction> action = null)
        {
            // access
            if (repo == null || actionStr == null)
            {
                return;
            }
            var numButton = actionStr.Length;

            // Grid
            var g = new Grid();

            g.Margin = new Thickness(0, 5, 0, 5);

            // 0 key
            var gc = new ColumnDefinition();

            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 1+x button
            for (int i = 0; i < 1 /* numButton*/; i++)
            {
                gc       = new ColumnDefinition();
                gc.Width = new GridLength(1.0, GridUnitType.Star);
                g.ColumnDefinitions.Add(gc);
            }

            // 0 row
            var gr = new RowDefinition();

            gr.Height = new GridLength(1.0, GridUnitType.Star);
            g.RowDefinitions.Add(gr);

            // key label
            var x = AddSmallLabelTo(g, 0, 0, margin: new Thickness(5, 0, 0, 0), content: "" + key);

            x.VerticalContentAlignment = VerticalAlignment.Center;

            // 1 + action button
#if never
            for (int i = 0; i < numButton; i++)
            {
                int currentI = i;
                repo.RegisterControl(ElemViewAddSmallButtonTo(g, 0, 1 + i, margin: new Thickness(0, 0, 5, 0), padding: new Thickness(5, 0, 5, 0), content: "" + actionStr[i]),
                                     (o) => {
                    return(action(currentI));    // button # as argument!
                });
            }
#else
            var wp = AddSmallWrapPanelTo(g, 0, 1, margin: new Thickness(5, 0, 5, 0));
            for (int i = 0; i < numButton; i++)
            {
                int currentI = i;
                var b        = new Button();
                b.Content = "" + actionStr[i];
                b.Margin  = new Thickness(2, 2, 2, 2);
                b.Padding = new Thickness(5, 0, 5, 0);
                wp.Children.Add(b);
                repo.RegisterControl(b,
                                     (o) => {
                    return(action(currentI));    // button # as argument!
                });
            }
#endif
            // in total
            view.Children.Add(g);
        }
Пример #3
0
        public void AddKeyListLangStr(StackPanel view, string key, List <AdminShell.LangStr> langStr, ModifyRepo repo = null)
        {
            // sometimes needless to show
            if (repo == null && (langStr == null || langStr.Count < 1))
            {
                return;
            }
            int rows = 1; // default!

            if (langStr != null && langStr.Count > 1)
            {
                rows = langStr.Count;
            }
            int rowOfs = 0;

            if (repo != null)
            {
                rowOfs = 1;
            }

            // Grid
            var g = new Grid();

            g.Margin = new Thickness(0, 0, 0, 0);

            // 0 key
            var gc = new ColumnDefinition();

            gc.Width = new GridLength(100);
            g.ColumnDefinitions.Add(gc);

            // 1 langs
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // 2 values
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Star);
            g.ColumnDefinitions.Add(gc);

            // 3 buttons behind it
            gc       = new ColumnDefinition();
            gc.Width = new GridLength(1.0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(gc);

            // rows
            for (int r = 0; r < rows + rowOfs; r++)
            {
                var gr = new RowDefinition();
                gr.Height = new GridLength(1.0, GridUnitType.Auto);
                g.RowDefinitions.Add(gr);
            }

            // populate key
            AddSmallLabelTo(g, 0, 0, margin: new Thickness(5, 0, 0, 0), content: "" + key + ":");

            // populate [+]
            if (repo != null)
            {
                repo.RegisterControl(AddSmallButtonTo(g, 0, 3, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "Add blank"),
                                     (o) =>
                {
                    var ls = new AdminShell.LangStr();
                    langStr.Add(ls);
                    return(new ModifyRepo.LambdaActionRedrawEntity());
                });
            }

            // contents?
            if (langStr != null)
            {
                for (int i = 0; i < langStr.Count; i++)
                {
                    if (repo == null)
                    {
                        // lang
                        AddSmallLabelTo(g, 0 + i + rowOfs, 1, padding: new Thickness(2, 0, 0, 0), content: "[" + langStr[i].lang + "]");

                        // str
                        AddSmallLabelTo(g, 0 + i + rowOfs, 2, padding: new Thickness(2, 0, 0, 0), content: "" + langStr[i].str);
                    }

                    else
                    {
                        // save in current context
                        var currentI = 0 + i;
                        // lang
                        repo.RegisterControl(
                            AddSmallComboBoxTo(g, 0 + i + rowOfs, 1, margin: new Thickness(0, 2, 2, 2), text: "" + langStr[currentI].lang,
                                               minWidth: 50, items: defaultLanguages, isEditable: true),
                            (o) =>
                        {
                            langStr[currentI].lang = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // str
                        repo.RegisterControl(
                            AddSmallTextBoxTo(g, 0 + i + rowOfs, 2, margin: new Thickness(2, 2, 2, 2), text: "" + langStr[currentI].str),
                            (o) =>
                        {
                            langStr[currentI].str = o as string;
                            return(new ModifyRepo.LambdaActionNone());
                        });

                        // button [-]
                        repo.RegisterControl(AddSmallButtonTo(g, 0 + i + rowOfs, 3, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: "-"),
                                             (o) => {
                            langStr.RemoveAt(currentI);
                            return(new ModifyRepo.LambdaActionRedrawEntity());
                        });
                    }
                }
            }

            // in total
            view.Children.Add(g);
        }
Пример #4
0
        public void AddKeyValue(
            StackPanel view, string key, string value, string nullValue = null,
            ModifyRepo repo        = null, Func <object, ModifyRepo.LambdaAction> setValue = null,
            string[] comboBoxItems = null, bool comboBoxIsEditable = false,
            string auxButtonTitle  = null, Func <object, ModifyRepo.LambdaAction> auxButtonLambda = null)
        {
            // draw anyway?
            if (repo != null && value == null)
            {
                // generate default value
                value = "";
            }
            else
            {
                // normal handling
                if (value == null && nullValue == null)
                {
                    return;
                }
                if (value == null)
                {
                    value = nullValue;
                }
            }


            // Grid
            var g = new Grid();

            g.Margin = new Thickness(0, 1, 0, 1);
            var gc1 = new ColumnDefinition();

            gc1.Width = new GridLength(100);
            g.ColumnDefinitions.Add(gc1);
            var gc2 = new ColumnDefinition();

            gc2.Width = new GridLength(1.0, GridUnitType.Star);
            g.ColumnDefinitions.Add(gc2);
            var auxButton = repo != null && auxButtonTitle != null && auxButtonLambda != null;

            if (auxButton)
            {
                var gc3 = new ColumnDefinition();
                gc3.Width = new GridLength(1.0, GridUnitType.Auto);
                g.ColumnDefinitions.Add(gc3);
            }

            // Label for key
            AddSmallLabelTo(g, 0, 0, padding: new Thickness(5, 0, 0, 0), content: "" + key + ":");

            // Label / TextBox for value
            if (repo == null)
            {
                AddSmallLabelTo(g, 0, 1, padding: new Thickness(2, 0, 0, 0), content: "" + value);
            }
            else if (comboBoxItems != null)
            {
                // guess some max width, in order
                var maxc = 5;
                foreach (var c in comboBoxItems)
                {
                    if (c.Length > maxc)
                    {
                        maxc = c.Length;
                    }
                }
                var maxWidth = 10 * maxc; // about one em
                // use combo box
                repo.RegisterControl(
                    AddSmallComboBoxTo(g, 0, 1, margin: new Thickness(0, 2, 2, 2), padding: new Thickness(2, 0, 2, 0), text: "" + value,
                                       minWidth: 60, maxWidth: maxWidth, items: comboBoxItems, isEditable: comboBoxIsEditable),
                    setValue);
            }
            else
            {
                // use plain text box
                repo.RegisterControl(AddSmallTextBoxTo(g, 0, 1, margin: new Thickness(0, 2, 2, 2), text: "" + value),
                                     setValue);
            }

            if (auxButton)
            {
                repo.RegisterControl(AddSmallButtonTo(g, 0, 2, margin: new Thickness(2, 2, 2, 2), padding: new Thickness(5, 0, 5, 0), content: auxButtonTitle),
                                     auxButtonLambda);
            }

            // in total
            view.Children.Add(g);
        }