Beispiel #1
0
        public void EntityListUpDownDeleteHelper <T>(StackPanel stack, ModifyRepo repo, List <T> list, T entity, object alternativeReturn, string label = "Entities:")
        {
            AddAction(stack, label, new string[] { "Move up", "Move down", "Delete" }, repo, (buttonNdx) =>
            {
                if (buttonNdx is int)
                {
                    if ((int)buttonNdx == 0)
                    {
                        MoveElementInListUpwards <T>(list, entity);
                        return(new ModifyRepo.LambdaActionRedrawAllElements(nextFocus: entity, isExpanded: null));
                    }

                    if ((int)buttonNdx == 1)
                    {
                        MoveElementInListDownwards <T>(list, entity);
                        return(new ModifyRepo.LambdaActionRedrawAllElements(nextFocus: entity, isExpanded: null));
                    }

                    if ((int)buttonNdx == 2)
                    {
                        if (MessageBoxResult.Yes == MessageBox.Show("Delete selected entity? This operation can not be reverted!", "AASX", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                        {
                            var ret = DeleteElementInListDownwards <T>(list, entity, alternativeReturn);
                            return(new ModifyRepo.LambdaActionRedrawAllElements(nextFocus: ret, isExpanded: null));
                        }
                    }
                }
                return(new ModifyRepo.LambdaActionNone());
            });
        }
Beispiel #2
0
        //
        // Safeguarding functions (checking if somethingis null and doing ..)
        //

        public bool SafeguardAccess(StackPanel view, ModifyRepo repo, object data, string key, string actionStr, Func <object, ModifyRepo.LambdaAction> action)
        {
            if (repo != null && data == null)
            {
                AddAction(view, key, actionStr, repo, action);
            }
            return(data != null);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public void AddAction(StackPanel view, string key, string actionStr, ModifyRepo repo = null, Func <object, ModifyRepo.LambdaAction> action = null)
 {
     AddAction(view, key, new string[] { actionStr }, repo, action);
 }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public DisplayRenderHints DisplayOrEditVisualAasxElement(
            PackageCentral packages,
            ListOfVisualElementBasic entities,
            bool editMode, bool hintMode = false, bool showIriMode = false,
            VisualElementEnvironmentItem.ConceptDescSortOrder?cdSortOrder = null,
            IFlyoutProvider flyoutProvider         = null,
            IPushApplicationEvent appEventProvider = null,
            DispEditHighlight.HighlightFieldInfo hightlightField = null)
        {
            //
            // Start
            //

            // hint mode disable, when not edit
            hintMode = hintMode && editMode;

            // remember objects for UI thread / redrawing
            this._packages            = packages;
            this._theEntities         = entities;
            _helper.packages          = packages;
            _helper.highlightField    = hightlightField;
            _helper.appEventsProvider = appEventProvider;

            // primary access
            var renderHints = new DisplayRenderHints();

            if (theMasterPanel == null || entities == null || entities.Count < 1)
            {
                renderHints.showDataPanel = false;
                return(renderHints);
            }

#if MONOUI
            var stack = ClearDisplayDefautlStack();
#else
            var stack = new AnyUiStackPanel();
#endif

            // create display context for WPF
            _displayContext     = new AnyUiDisplayContextWpf(flyoutProvider, packages);
            _helper.levelColors = DispLevelColors.GetLevelColorsFromOptions(Options.Curr);

            // modify repository
            ModifyRepo repo = null;
            if (editMode)
            {
                // some functionality still uses repo != null to detect editMode!!
                repo = new ModifyRepo();
            }
            _helper.editMode    = editMode;
            _helper.hintMode    = hintMode;
            _helper.repo        = repo;
            _helper.showIriMode = showIriMode;
            _helper.context     = _displayContext;

            // inform plug that their potential panel might not shown anymore
            Plugins.AllPluginsInvoke("clear-panel-visual-extension");

            //
            // Test for Blazor
            //
#if __test_blazor
            if (false)
            {
                var lab = new AnyUiLabel();
                lab.Content    = "Hallo";
                lab.Foreground = AnyUiBrushes.DarkBlue;
                stack.Children.Add(lab);

                if (editMode)
                {
                    var tb = new AnyUiTextBox();
                    tb.Foreground = AnyUiBrushes.Black;
                    tb.Text       = "Initial";
                    stack.Children.Add(tb);
                    repo.RegisterControl(tb, (o) =>
                    {
                        Log.Singleton.Info($"Text changed to .. {""+o}");
                        return(new AnyUiLambdaActionNone());
                    });

                    var btn = new AnyUiButton();
                    btn.Content = "Click me!";
                    stack.Children.Add(btn);
                    repo.RegisterControl(btn, (o) =>
                    {
                        Log.Singleton.Error("Button clicked!");
                        return(new AnyUiLambdaActionRedrawAllElements(null));
                    });
                }
            }
#endif

            var inhibitRenderStackToPanel = false;

            if (entities.ExactlyOne)
            {
                //
                // Dispatch: ONE item
                //
                var entity = entities.First();

                // maintain parent. If in doubt, set null
                ListOfVisualElement.SetParentsBasedOnChildHierarchy(entity);

                //
                // Dispatch
                //

                if (entity is VisualElementEnvironmentItem veei)
                {
                    _helper.DisplayOrEditAasEntityAasEnv(
                        packages, veei.theEnv, veei, editMode, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementAdminShell veaas)
                {
                    _helper.DisplayOrEditAasEntityAas(
                        packages, veaas.theEnv, veaas.theAas, editMode, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementAsset veas)
                {
                    _helper.DisplayOrEditAasEntityAsset(
                        packages, veas.theEnv, veas.theAsset, editMode, repo, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodelRef vesmref)
                {
                    // data
                    AdminShell.AdministrationShell aas = null;
                    if (vesmref.Parent is VisualElementAdminShell xpaas)
                    {
                        aas = xpaas.theAas;
                    }

                    // edit
                    _helper.DisplayOrEditAasEntitySubmodelOrRef(
                        packages, vesmref.theEnv, aas, vesmref.theSubmodelRef, vesmref.theSubmodel, editMode, stack,
                        hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodel vesm && vesm.theSubmodel != null)
                {
                    _helper.DisplayOrEditAasEntitySubmodelOrRef(
                        packages, vesm.theEnv, null, null, vesm.theSubmodel, editMode, stack,
                        hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodelElement vesme)
                {
                    _helper.DisplayOrEditAasEntitySubmodelElement(
                        packages, vesme.theEnv, vesme.theContainer, vesme.theWrapper, vesme.theWrapper.submodelElement,
                        editMode,
                        repo, stack, hintMode: hintMode,
                        nestedCds: cdSortOrder.HasValue &&
                        cdSortOrder.Value == VisualElementEnvironmentItem.ConceptDescSortOrder.BySme);
                }
                else if (entity is VisualElementOperationVariable vepv)
                {
                    _helper.DisplayOrEditAasEntityOperationVariable(
                        packages, vepv.theEnv, vepv.theContainer, vepv.theOpVar, editMode,
                        stack, hintMode: hintMode);
                }
                else if (entity is VisualElementConceptDescription vecd)
                {
                    _helper.DisplayOrEditAasEntityConceptDescription(
                        packages, vecd.theEnv, null, vecd.theCD, editMode, repo, stack, hintMode: hintMode,
                        preventMove: cdSortOrder.HasValue &&
                        cdSortOrder.Value != VisualElementEnvironmentItem.ConceptDescSortOrder.None);
                }
                else if (entity is VisualElementView vevw)
                {
                    if (vevw.Parent != null && vevw.Parent is VisualElementAdminShell xpaas)
                    {
                        _helper.DisplayOrEditAasEntityView(
                            packages, vevw.theEnv, xpaas.theAas, vevw.theView, editMode, stack,
                            hintMode: hintMode);
                    }
                    else
                    {
                        _helper.AddGroup(stack, "View is corrupted!", _helper.levelColors.MainSection);
                    }
                }
                else if (entity is VisualElementReference verf)
                {
                    if (verf.Parent != null && verf.Parent is VisualElementView xpev)
                    {
                        _helper.DisplayOrEditAasEntityViewReference(
                            packages, verf.theEnv, xpev.theView, (AdminShell.ContainedElementRef)verf.theReference,
                            editMode, stack);
                    }
                    else
                    {
                        _helper.AddGroup(stack, "Reference is corrupted!", _helper.levelColors.MainSection);
                    }
                }
                else
                if (entity is VisualElementSupplementalFile vesf)
                {
                    _helper.DisplayOrEditAasEntitySupplementaryFile(packages, vesf.theFile, editMode, stack);
                }
                else if (entity is VisualElementPluginExtension vepe)
                {
                    // create controls
                    object result = null;

                    try
                    {
                        // replace at top level
                        theMasterPanel.Children.Clear();
                        if (vepe.thePlugin != null)
                        {
                            result = vepe.thePlugin.InvokeAction(
                                "fill-panel-visual-extension", vepe.thePackage, vepe.theReferable, theMasterPanel);
                        }
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }

                    // add?
                    if (result == null)
                    {
                        // re-init display!
#if MONOUI
                        stack = ClearDisplayDefautlStack();
#else
                        stack = new AnyUiStackPanel();
#endif

                        // helping message
                        _helper.AddGroup(
                            stack, "Entity from Plugin cannot be rendered!", _helper.levelColors.MainSection);
                    }
                    else
                    {
                        // this is natively done; do NOT render Any UI to WPF
                        inhibitRenderStackToPanel = true;
                    }

                    // show no panel nor scroll
                    renderHints.scrollingPanel = false;
                    renderHints.showDataPanel  = false;
                }
                else
                {
                    _helper.AddGroup(stack, "Entity is unknown!", _helper.levelColors.MainSection);
                }
            }
        //
        // Helper functions
        //

        public void DispSmeCutCopyPasteHelper(
            Panel stack, ModifyRepo repo,
            AdminShell.AdministrationShellEnv env,
            AdminShell.Referable parentContainer,
            CopyPasteBuffer cpb,
            AdminShell.SubmodelElementWrapper wrapper,
            AdminShell.SubmodelElement sme,
            string label = "Buffer:")
        {
            // access
            if (parentContainer == null || cpb == null || sme == null)
            {
                return;
            }

            // use an action
            this.AddAction(
                stack, label,
                new[] { "Cut", "Copy", "Paste above", "Paste below", "Paste into" }, repo,
                (buttonNdx) =>
            {
                if (buttonNdx == 0 || buttonNdx == 1)
                {
                    // store info
                    cpb.valid     = true;
                    cpb.duplicate = buttonNdx == 1;
                    cpb.item      = new CopyPasteItemSME(env, parentContainer, wrapper, sme);

                    // user feedback
                    AasxPackageExplorer.Log.Singleton.Info(
                        StoredPrint.Color.Blue,
                        "Stored SubmodelElement '{0}'({1}) to internal buffer.{2}", "" + sme.idShort,
                        "" + sme?.GetElementName(),
                        cpb.duplicate
                                ? " Paste will duplicate."
                                : " Paste will cut at original position.");
                }

                if (buttonNdx == 2 || buttonNdx == 3 || buttonNdx == 4)
                {
                    // present
                    var item = cpb?.item as CopyPasteItemSME;
                    if (!cpb.valid || item?.sme == null || item?.wrapper == null ||
                        item?.parentContainer == null)
                    {
                        if (this.flyoutProvider != null)
                        {
                            this.flyoutProvider.MessageBoxFlyoutShow(
                                "No (valid) information for SubmodelElements in copy/paste buffer.",
                                "Copy & Paste",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        return(new ModifyRepo.LambdaActionNone());
                    }

                    // user feedback
                    AasxPackageExplorer.Log.Singleton.Info(
                        "Pasting buffer with SubmodelElement '{0}'({1}) to internal buffer.",
                        "" + item.sme.idShort, "" + item.sme.GetElementName());

                    // apply info
                    var smw2 = new AdminShell.SubmodelElementWrapper(item.sme, shallowCopy: false);

                    // insertation depends on parent container
                    if (buttonNdx == 2)
                    {
                        if (parentContainer is AdminShell.Submodel pcsm && wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcsm.submodelElements, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.SubmodelElementCollection pcsmc &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcsmc.value, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.Entity pcent &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcent.statements, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.AnnotatedRelationshipElement pcarel &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcarel.annotations, smw2, wrapper);
                        }

                        // TODO (Michael Hoffmeister, 2020-08-01): Operation mssing here?
                    }
Beispiel #10
0
        public DisplayRenderHints DisplayOrEditVisualAasxElement(
            PackageCentral packages,
            ListOfVisualElementBasic entities,
            bool editMode, bool hintMode = false, bool showIriMode = false,
            VisualElementEnvironmentItem.ConceptDescSortOrder?cdSortOrder = null,
            IFlyoutProvider flyoutProvider         = null,
            IPushApplicationEvent appEventProvider = null,
            DispEditHighlight.HighlightFieldInfo hightlightField = null)
        {
            //
            // Start
            //

            // hint mode disable, when not edit
            hintMode = hintMode && editMode;

            // remember objects for UI thread / redrawing
            this._packages            = packages;
            this._theEntities         = entities;
            _helper.packages          = packages;
            _helper.highlightField    = hightlightField;
            _helper.appEventsProvider = appEventProvider;

            // primary access
            var renderHints = new DisplayRenderHints();

            if (theMasterPanel == null || entities == null || entities.Count < 1)
            {
                renderHints.showDataPanel = false;
                return(renderHints);
            }

#if MONOUI
            var stack = ClearDisplayDefautlStack();
#else
            var stack = new AnyUiStackPanel();
#endif

            // create display context for WPF
            _displayContext     = new AnyUiDisplayContextWpf(flyoutProvider, packages);
            _helper.levelColors = DispLevelColors.GetLevelColorsFromOptions(Options.Curr);

            // modify repository
            ModifyRepo repo = null;
            if (editMode)
            {
                // some functionality still uses repo != null to detect editMode!!
                repo = new ModifyRepo();
            }
            _helper.editMode    = editMode;
            _helper.hintMode    = hintMode;
            _helper.repo        = repo;
            _helper.showIriMode = showIriMode;
            _helper.context     = _displayContext;

            //
            // Test for Blazor
            //
#if __test_blazor
            if (false)
            {
                var lab = new AnyUiLabel();
                lab.Content    = "Hallo";
                lab.Foreground = AnyUiBrushes.DarkBlue;
                stack.Children.Add(lab);

                if (editMode)
                {
                    var tb = new AnyUiTextBox();
                    tb.Foreground = AnyUiBrushes.Black;
                    tb.Text       = "Initial";
                    stack.Children.Add(tb);
                    repo.RegisterControl(tb, (o) =>
                    {
                        Log.Singleton.Info($"Text changed to .. {""+o}");
                        return(new AnyUiLambdaActionNone());
                    });

                    var btn = new AnyUiButton();
                    btn.Content = "Click me!";
                    stack.Children.Add(btn);
                    repo.RegisterControl(btn, (o) =>
                    {
                        Log.Singleton.Error("Button clicked!");
                        return(new AnyUiLambdaActionRedrawAllElements(null));
                    });
                }
            }
#endif

            var inhibitRenderStackToPanel = false;

            if (entities.ExactlyOne)
            {
                //
                // Dispatch: ONE item
                //
                var entity = entities.First();

                if (entity is VisualElementEnvironmentItem veei)
                {
                    _helper.DisplayOrEditAasEntityAasEnv(
                        packages, veei.theEnv, veei, editMode, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementAdminShell veaas)
                {
                    _helper.DisplayOrEditAasEntityAas(
                        packages, veaas.theEnv, veaas.theAas, editMode, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementAsset veas)
                {
                    _helper.DisplayOrEditAasEntityAsset(
                        packages, veas.theEnv, veas.theAsset, editMode, repo, stack, hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodelRef vesmref)
                {
                    AdminShell.AdministrationShell aas = null;
                    if (vesmref.Parent is VisualElementAdminShell xpaas)
                    {
                        aas = xpaas.theAas;
                    }
                    _helper.DisplayOrEditAasEntitySubmodelOrRef(
                        packages, vesmref.theEnv, aas, vesmref.theSubmodelRef, vesmref.theSubmodel, editMode, stack,
                        hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodel vesm)
                {
                    _helper.DisplayOrEditAasEntitySubmodelOrRef(
                        packages, vesm.theEnv, null, null, vesm.theSubmodel, editMode, stack,
                        hintMode: hintMode);
                }
                else if (entity is VisualElementSubmodelElement vesme)
                {
                    _helper.DisplayOrEditAasEntitySubmodelElement(
                        packages, vesme.theEnv, vesme.theContainer, vesme.theWrapper, vesme.theWrapper.submodelElement,
                        editMode,
                        repo, stack, hintMode: hintMode,
                        nestedCds: cdSortOrder.HasValue &&
                        cdSortOrder.Value == VisualElementEnvironmentItem.ConceptDescSortOrder.BySme);
                }
                else if (entity is VisualElementOperationVariable vepv)
                {
                    _helper.DisplayOrEditAasEntityOperationVariable(
                        packages, vepv.theEnv, vepv.theContainer, vepv.theOpVar, editMode,
                        stack, hintMode: hintMode);
                }
                else if (entity is VisualElementConceptDescription vecd)
                {
                    _helper.DisplayOrEditAasEntityConceptDescription(
                        packages, vecd.theEnv, null, vecd.theCD, editMode, repo, stack, hintMode: hintMode,
                        preventMove: cdSortOrder.HasValue &&
                        cdSortOrder.Value != VisualElementEnvironmentItem.ConceptDescSortOrder.None);
                }
                else if (entity is VisualElementView vevw)
                {
                    if (vevw.Parent != null && vevw.Parent is VisualElementAdminShell xpaas)
                    {
                        _helper.DisplayOrEditAasEntityView(
                            packages, vevw.theEnv, xpaas.theAas, vevw.theView, editMode, stack,
                            hintMode: hintMode);
                    }
                    else
                    {
                        _helper.AddGroup(stack, "View is corrupted!", _helper.levelColors.MainSection);
                    }
                }
                else if (entity is VisualElementReference verf)
                {
                    if (verf.Parent != null && verf.Parent is VisualElementView xpev)
                    {
                        _helper.DisplayOrEditAasEntityViewReference(
                            packages, verf.theEnv, xpev.theView, (AdminShell.ContainedElementRef)verf.theReference,
                            editMode, stack);
                    }
                    else
                    {
                        _helper.AddGroup(stack, "Reference is corrupted!", _helper.levelColors.MainSection);
                    }
                }
                else
                if (entity is VisualElementSupplementalFile vesf)
                {
                    _helper.DisplayOrEditAasEntitySupplementaryFile(packages, vesf.theFile, editMode, stack);
                }
                else if (entity is VisualElementPluginExtension vepe)
                {
                    // create controls
                    object result = null;

                    try
                    {
                        // replace at top level
                        theMasterPanel.Children.Clear();
                        if (vepe.thePlugin != null)
                        {
                            result = vepe.thePlugin.InvokeAction(
                                "fill-panel-visual-extension", vepe.thePackage, vepe.theReferable, theMasterPanel);
                        }
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }

                    // add?
                    if (result == null)
                    {
                        // re-init display!
#if MONOUI
                        stack = ClearDisplayDefautlStack();
#else
                        stack = new AnyUiStackPanel();
#endif

                        // helping message
                        _helper.AddGroup(
                            stack, "Entity from Plugin cannot be rendered!", _helper.levelColors.MainSection);
                    }
                    else
                    {
                        // this is natively done; do NOT render Any UI to WPF
                        inhibitRenderStackToPanel = true;
                    }

                    // show no panel nor scroll
                    renderHints.scrollingPanel = false;
                    renderHints.showDataPanel  = false;
                }
                else
                {
                    _helper.AddGroup(stack, "Entity is unknown!", _helper.levelColors.MainSection);
                }
            }
            else
            {
                //
                // Dispatch: MULTIPLE items
                //
                _helper.DisplayOrEditAasEntityMultipleElements(packages, entities, editMode, stack, cdSortOrder);
            }

            // now render master stack
#if __export_BLAZOR
            var fn = @"fileEdit.json";
            if (!editMode)
            {
                count = 0;
                var jsonSerializerSettings = new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All,
                    Formatting       = Formatting.Indented
                };
                var json = JsonConvert.SerializeObject(stack, jsonSerializerSettings);
                System.IO.File.WriteAllText(fn, json);
            }
            if (editMode)
            {
                if (true && count == 2)
                {
                    count = 0;
                    JsonSerializerSettings settings = new JsonSerializerSettings
                    {
                        // SerializationBinder = new DisplayNameSerializationBinder(
                        //    new[] { typeof(AasxIntegrationBase.AasForms.FormDescListOfElement),
                        //      typeof(AasxIntegrationBase.AasForms.FormDescProperty) }),
                        // SerializationBinder = new DisplayNameSerializationBinder(
                        //     new[] { typeof(AnyUiStackPanel), typeof(AnyUiUIElement) }),
                        // NullValueHandling = NullValueHandling.Ignore,
                        ReferenceLoopHandling = ReferenceLoopHandling.Error,
                        TypeNameHandling      = TypeNameHandling.All,
                        Formatting            = Formatting.Indented
                    };

                    //if (stack is AnyUiPanel pan)
                    //{
                    //    for (int i = 0; i < pan.Children.Count; i++)
                    //    {
                    //        var json = JsonConvert.SerializeObject(pan.Children[i], settings);
                    //        System.IO.File.WriteAllText(fn+"."+i, json);
                    //    }
                    //}
                    var json = JsonConvert.SerializeObject(stack, settings);
                    System.IO.File.WriteAllText(fn, json);
                }
                count++;

                /*
                 * var writer = new System.Xml.Serialization.XmlSerializer(typeof(AnyUiUIElement));
                 * var wfile = new System.IO.StreamWriter(@"c:\development\fileEdit.xml");
                 * writer.Serialize(wfile, stack);
                 * wfile.Close();
                 */
            }
#endif
#if MONOUI
#else
            // render Any UI to WPF?
            if (!inhibitRenderStackToPanel)
            {
                // rendering
                theMasterPanel.Children.Clear();
                var spwpf = _displayContext.GetOrCreateWpfElement(stack);
                _helper.ShowLastHighlights();
                DockPanel.SetDock(spwpf, Dock.Top);
                theMasterPanel.Children.Add(spwpf);

                // register key shortcuts
                var num = _displayContext.PrepareNameList(stack);
                if (num > 0)
                {
                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-move-up", ModifierKeys.Shift | ModifierKeys.Control, Key.Up,
                        "Move current AAS element up by one position.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-move-down", ModifierKeys.Shift | ModifierKeys.Control, Key.Down,
                        "Move current AAS element down by one position.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-move-top", ModifierKeys.Shift | ModifierKeys.Control, Key.Home,
                        "Move current AAS element to the first position of the respective list.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-move-end", ModifierKeys.Shift | ModifierKeys.Control, Key.End,
                        "Move current AAS element to the last position of the respective list.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-delete", ModifierKeys.Shift | ModifierKeys.Control, Key.Delete,
                        "Delete current AAS element in the respective list. Shift key skips dialogue.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-cut", ModifierKeys.Shift | ModifierKeys.Control, Key.X,
                        "Transfers current AAS element into paste buffer and deletes in respective list.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-copy", ModifierKeys.Shift | ModifierKeys.Control, Key.C,
                        "Copies current AAS element into paste buffer for later pasting.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-paste-into", ModifierKeys.Shift | ModifierKeys.Control, Key.V,
                        "Copy existing paste buffer into the child list of the current AAS element.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-paste-above", ModifierKeys.Shift | ModifierKeys.Control, Key.W,
                        "Copy existing paste buffer above the current AAS element in the same list.");

                    _displayContext.RegisterKeyShortcut(
                        "aas-elem-paste-below", ModifierKeys.Shift | ModifierKeys.Control, Key.Y,
                        "Copy existing paste buffer below the current AAS element in the same list.");
                }
            }

            // keep the stack
            _lastRenderedRootElement = stack;
#endif

            // return render hints
            return(renderHints);
        }