public static List <T> Find <TKey, TValue, T>(UIElement element, DbAttribute attribute, DisplayableProperty <TKey, TValue> dp) where TValue : Tuple where T : FrameworkElement
        {
            var elements = GetAll(element, attribute, dp);

            if (elements.Count == 0)
            {
                return(null);
            }

            List <UIElement> allElements = new List <UIElement>();

            while (elements.Any(p => p is Panel))
            {
                foreach (var telement in elements)
                {
                    if (telement is Panel)
                    {
                        allElements.AddRange(((Panel)telement).Children.OfType <UIElement>());
                    }
                    else
                    {
                        allElements.Add(telement);
                    }
                }

                elements = allElements;
            }

            return(elements.OfType <T>().ToList());
        }
예제 #2
0
        private GDbTab _gDbTabMaker(SdeDatabase database, TabControl control, BaseDb gdb)
        {
            GTabSettings <TKey, ReadableTuple <TKey> >  settings = new GTabSettings <TKey, ReadableTuple <TKey> >(gdb);
            GDbTabWrapper <TKey, ReadableTuple <TKey> > tab      = new GDbTabWrapper <TKey, ReadableTuple <TKey> >();
            Table <TKey, ReadableTuple <TKey> >         table    = gdb.To <TKey>().Table;

            settings.Table   = table;
            settings.Control = control;

            Settings.Control  = control;
            Settings.Gdb      = gdb;
            Settings.Tab      = tab;
            Settings.Table    = table;
            Settings.Database = database;

            InitStyle(tab, settings, gdb);
            InitAttributes(tab, settings, gdb);
            if (OnInitSettings != null)
            {
                OnInitSettings(tab, settings, gdb);
            }

            DisplayableProperty <TKey, ReadableTuple <TKey> > generalProperties = new DisplayableProperty <TKey, ReadableTuple <TKey> >();

            generalProperties.Spacing  = DefaultSpacing;
            Settings.GeneralProperties = generalProperties;

            SdeEditor.Instance.SelectionChanged += new SdeEditor.SdeSelectionChangedEventHandler((sender, oldTab, newTab) => {
                try {
                    TabItem item = newTab;

                    if (gdb.DbSource.AlternativeName != null)
                    {
                        if (WpfUtilities.IsTab(item, gdb.DbSource.Filename) || WpfUtilities.IsTab(item, gdb.DbSource.AlternativeName))
                        {
                            if (generalProperties.OnTabVisible != null)
                            {
                                generalProperties.OnTabVisible(this);
                            }
                            if (OnPreviewTabVisualUpdate != null)
                            {
                                OnPreviewTabVisualUpdate(tab, settings, gdb);
                            }
                            if (OnTabVisualUpdate != null)
                            {
                                OnTabVisualUpdate(tab, settings, gdb);
                            }
                            if (OnTabRefreshed != null)
                            {
                                OnTabRefreshed(Settings);
                            }
                        }
                    }
                    else
                    {
                        if (WpfUtilities.IsTab(item, gdb.DbSource))
                        {
                            if (generalProperties.OnTabVisible != null)
                            {
                                generalProperties.OnTabVisible(this);
                            }
                            if (OnPreviewTabVisualUpdate != null)
                            {
                                OnPreviewTabVisualUpdate(tab, settings, gdb);
                            }
                            if (OnTabVisualUpdate != null)
                            {
                                OnTabVisualUpdate(tab, settings, gdb);
                            }
                            if (OnTabRefreshed != null)
                            {
                                OnTabRefreshed(Settings);
                            }
                        }
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            });

            database.PreviewReloaded += delegate {
                if (OnPreviewDatabaseReloaded != null)
                {
                    OnPreviewDatabaseReloaded(tab, settings, gdb);
                }
            };

            database.Reloaded += delegate {
                //if (OnPreviewTabVisualUpdate != null) OnPreviewTabVisualUpdate(tab, settings, gdb);
                //if (OnTabVisualUpdate != null) OnTabVisualUpdate(tab, settings, gdb);

                DisplayablePropertyHelper.CheckAttributeRestrictions(tab, settings, gdb);

                if (OnDatabaseReloaded != null)
                {
                    OnDatabaseReloaded(tab, settings, gdb);
                }

                if (OnTabRefreshed != null)
                {
                    OnTabRefreshed(Settings);
                }
            };

            int line = 0;

            if (OnPreviewGenerateGrid != null)
            {
                OnPreviewGenerateGrid(ref line, Settings);
            }
            if (GenerateGrid != null)
            {
                GenerateGrid(ref line, Settings);
            }
            if (OnGenerateGrid != null)
            {
                OnGenerateGrid(ref line, Settings);
            }

            settings.DisplayablePropertyMaker = generalProperties;
            settings.ClientDatabase           = database;

            if (SetSettings != null)
            {
                SetSettings(tab, settings, gdb);
            }
            if (OnSetCustomCommands != null)
            {
                OnSetCustomCommands(tab, settings, gdb);
            }
            if (OnPreviewTabInitialize != null)
            {
                OnPreviewTabInitialize(tab, settings, gdb);
            }
            tab.Initialize(settings);
            if (OnAfterTabInitialize != null)
            {
                OnAfterTabInitialize(tab, settings, gdb);
            }
            return(tab);
        }
        public static List <UIElement> GetAll <TKey, TValue>(UIElement element, DbAttribute attribute, DisplayableProperty <TKey, TValue> dp) where TValue : Tuple
        {
            if (dp == null)
            {
                return(GetAll(element, attribute));
            }

            var elements = GetAll(element, attribute);

            if (elements.Count == 0)
            {
                // Search in the undeployed attributes
                Label label = dp.GetLabel(attribute.DisplayName);

                if (label == null)
                {
                    return(elements);
                }

                // Only items from the primary grid can be returned
                return(dp.GetComponents((int)label.GetValue(Grid.RowProperty), (int)label.GetValue(Grid.ColumnProperty) + 1).Where(p => p.Parent == label.Parent).OfType <UIElement>().ToList());
            }

            return(elements);
        }