示例#1
0
        private void initAssociationsTable <TElement, TProxy>
            (ref CustomDataGridView <TProxy> tableCDGV, ref DataGridView tableOriginal,
            ref Panel containerPanel, ref ObservableProxyEnumerable <TProxy, TElement> proxyListRef,
            ObservableList <TElement> listA, ObservableList <TElement> listB,
            Func <TElement, string> elementNameGetter, Func <TElement, int> elementIndexGetter)
            where TElement : class, Model.General.INotifyPropertyChanged
            where TProxy : RouterIOProxy <TElement>, new()
        {
            tableCDGV = createTable <TProxy>(containerPanel, ref tableOriginal);
            tableCDGV.VerticalHeader = true;
            CustomDataGridViewColumnDescriptorBuilder <TProxy> builder;

            if ((listA == null) || (listB == null))
            {
                return;
            }

            // Create database
            ObservableProxyEnumerable <TProxy, TElement> proxyList = new ObservableProxyEnumerable <TProxy, TElement>(listA, (elementA) => new TProxy()
            {
                Original = elementA
            });

            proxyListRef = proxyList;

            // Column: sideA name
            builder = getColumnDescriptorBuilderForTable <TProxy>(tableCDGV);
            builder.Header("");
            builder.Width(150);
            builder.DividerWidth(3);
            builder.InitializerMethod((elementProxyA, cell) => { cell.Value = elementNameGetter(elementProxyA.Original); });
            builder.BuildAndAdd();

            // Columns for associations
            foreach (TElement elementB in listB)
            {
                builder = getColumnDescriptorBuilderForTable <TProxy>(tableCDGV);
                builder.Type(DataGridViewColumnType.SmallIcon);
                builder.Header(elementNameGetter(elementB));
                builder.Width(30);
                builder.IconColor(ICONCOLOR_ASSOCIATION);
                builder.IconType(DataGridViewSmallIconCell.IconTypes.Circle);
                builder.IconShown(false);
                builder.UpdaterMethod((elementProxyA, cell) =>
                {
                    DataGridViewSmallIconCell typedCell = ((DataGridViewSmallIconCell)cell);
                    bool active = (elementProxyA.AssociatedElement == elementB);
                    if (active)
                    {
                        cell.Style.BackColor = BACKCOLOR_ASSOCIATION_ACTIVE;
                        typedCell.IconShown  = true;
                    }
                    else
                    {
                        cell.Style.BackColor = BACKCOLOR_ASSOCIATION_INACTIVE;
                        typedCell.IconShown  = false;
                    }
                });
                builder.AddChangeEvent("#" + elementIndexGetter(elementB));
                builder.CellDoubleClickHandlerMethod((elementProxyA, cell, e) => { doAssociation(elementProxyA, elementB, proxyList); });
                builder.BuildAndAdd();
            }

            // Bind database
            tableCDGV.BoundCollection = proxyList;
        }
示例#2
0
        private void initializeTable()
        {
            crosspointsTable = new CustomDataGridView <RouterOutputProxy>();
            crosspointsTableContainer.Controls.Clear();
            crosspointsTableContainer.Controls.Add(crosspointsTable);
            crosspointsTable.Dock = DockStyle.Fill;
            table = (CustomDataGridView <RouterOutputProxy>)crosspointsTable;
            table.VerticalHeader = true;

            CustomDataGridViewColumnDescriptorBuilder <RouterOutputProxy> builder;

            bool _singleMode = singleMode;

            // Column: output name
            builder = getColumnDescriptorBuilderForTable();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("");
            builder.Width(150);
            builder.DividerWidth(3);
            builder.UpdaterMethod((routerOutputProxy, cell) => {
                if (_singleMode)
                {
                    cell.Value = routerOutputProxy.Name;
                }
                else
                {
                    cell.Value = string.Format("[{0}] {1}", routerOutputProxy.RouterName, routerOutputProxy.Name);
                }
            });
            builder.AddChangeEvent(nameof(RouterOutput.Name));
            builder.BuildAndAdd();

            // Column: lock
            builder = getColumnDescriptorBuilderForTable();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Lock");
            builder.Width(30);
            builder.UpdaterMethod((routerOutputProxy, cell) => { cell.Value = ""; });
            builder.AddChangeEvent(nameof(RouterOutput.Name));
            builder.BuildAndAdd();

            // Column: protect
            builder = getColumnDescriptorBuilderForTable();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Protect");
            builder.Width(30);
            builder.DividerWidth(3);
            builder.UpdaterMethod((routerOutputProxy, cell) => { cell.Value = ""; });
            builder.AddChangeEvent(nameof(RouterOutput.Name));
            builder.BuildAndAdd();

            List <IRouterOutputAssignable> assignables = getAllAssignables();

            foreach (IRouterOutputAssignable assignable in assignables)
            {
                builder = getColumnDescriptorBuilderForTable();
                builder.Type(DataGridViewColumnType.SmallIcon);
                builder.Header(assignable.Name);
                builder.Width(30);
                builder.IconColor(Color.Red);
                builder.IconType(DataGridViewSmallIconCell.IconTypes.Circle);
                builder.IconShown(false);
                builder.CellDoubleClickHandlerMethod((routerOutputProxy, cell, e) => {
                    if (autotake)
                    {
                        doAssign(routerOutputProxy.Output, assignable);
                    }
                    else
                    {
                        routerOutputProxy.SelectedToAssign = assignable;
                    }
                });
                builder.UpdaterMethod((routerOutputProxy, cell) => {
                    DataGridViewSmallIconCell typedCell = ((DataGridViewSmallIconCell)cell);

                    bool active = _singleMode
                        ? (routerOutputProxy.ActiveAssigned == assignable)
                        : (routerOutputProxy.ActiveAssigned?.SourceSignal == assignable.SourceSignal);

                    bool selected = _singleMode
                        ? (routerOutputProxy.SelectedToAssign == assignable)
                        : ((routerOutputProxy.SelectedToAssign != null) && (routerOutputProxy.SelectedToAssign?.SourceSignal == assignable.SourceSignal));

                    if (active)
                    {
                        cell.Style.BackColor = BACKCOLOR_CROSSPOINT_ACTIVE;
                        typedCell.IconShown  = true;
                        typedCell.IconColor  = ICONCOLOR_CROSSPOINT_ACTIVE;
                    }
                    else if (selected)
                    {
                        cell.Style.BackColor = BACKCOLOR_CROSSPOINT_SELECTED;
                        typedCell.IconShown  = true;
                        typedCell.IconColor  = ICONCOLOR_CROSSPOINT_SELECTED;
                    }
                    else
                    {
                        cell.Style.BackColor = BACKCOLOR_CROSSPOINT_EMPTY;
                        typedCell.IconShown  = false;
                        typedCell.IconColor  = ICONCOLOR_CROSSPOINT_EMPTY;
                    }
                });
                builder.AddChangeEvent(nameof(RouterOutputProxy.ActiveAssigned));
                builder.AddChangeEvent(nameof(RouterOutputProxy.SelectedToAssign));
                builder.BuildAndAdd();
            }

            // Bind database
            ObservableList <RouterOutput> allOutputs = getAllOutputs();

            routerOutputProxies   = new ObservableProxyList <RouterOutputProxy, RouterOutput>(allOutputs, (routerOutput) => new RouterOutputProxy(routerOutput));
            table.BoundCollection = routerOutputProxies;
        }