Example #1
0
            public PetEvolutionTargetView(Utilities.Extension.Tuple <object, int> requirement, Table <int, ReadableTuple <int> > itemsTable, Table <int, ReadableTuple <int> > clientTable)
            {
                _requirement = requirement;
                _itemsTable  = itemsTable;
                _clientTable = clientTable;

                _reload();
            }
Example #2
0
        public override void Init(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, DisplayableProperty <TKey, ReadableTuple <TKey> > dp)
        {
            _tab           = tab;
            _configuration = (CustomTableInitializer)tab.Settings.AttributeList[1].AttachedObject;
            _configuration.AttributeTable       = tab.Settings.AttributeList[1];
            _tab.Settings.NewItemAddedFunction += item => item.SetRawValue(_configuration.AttributeTable, new Dictionary <int, ReadableTuple <int> >());

            SdeDatabase gdb = _tab.ProjectDatabase;

            _table.Commands.CommandUndo          += _commandChanged;
            _table.Commands.CommandRedo          += _commandChanged;
            _table.Commands.CommandExecuted      += _commandChanged;
            _table.Commands.ModifiedStateChanged += _visualUpdate;

            gdb.Commands.CommandUndo     += _commandChanged2;
            gdb.Commands.CommandRedo     += _commandChanged2;
            gdb.Commands.CommandExecuted += _commandChanged2;

            Grid grid = new Grid();

            grid.SetValue(Grid.RowProperty, _row);
            grid.SetValue(Grid.ColumnProperty, 0);
            grid.SetValue(Grid.ColumnSpanProperty, 1);

            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(-1, GridUnitType.Auto)
            });
            grid.RowDefinitions.Add(new RowDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            _lv = new RangeListView();
            _lv.SetValue(TextSearch.TextPathProperty, "ID");
            _lv.SetValue(WpfUtils.IsGridSortableProperty, true);
            _lv.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
            _lv.SetValue(Grid.RowProperty, 1);
            _lv.Width               = 334;
            _lv.FocusVisualStyle    = null;
            _lv.Margin              = new Thickness(3);
            _lv.BorderThickness     = new Thickness(1);
            _lv.HorizontalAlignment = HorizontalAlignment.Left;
            _lv.SelectionChanged   += _lv_SelectionChanged;
            SdeEditor.Instance.ProjectDatabase.Reloaded += _database_Reloaded;

            OnInitListView();

            _lv.PreviewMouseDown += delegate {
                _lv.Focus();
                Keyboard.Focus(_lv);
            };
            _lv.ContextMenu         = new ContextMenu();
            _configuration.ListView = _lv;
            dp.AddResetField(_lv);
            dp.AddUpdateAction(_updateTable);

            _dp                   = new DisplayableProperty <TKey, ReadableTuple <TKey> >();
            _dp.IsDico            = true;
            _dp.DicoConfiguration = _configuration;

            grid.Children.Add(_lv);
            OnDeplayTable();
            _tab.PropertiesGrid.Children.Add(grid);
            _dp.Deploy(_tab, null, true);

            DbSearchPanel dbSearchPanel = new DbSearchPanel();

            dbSearchPanel._border1.BorderThickness = new Thickness(1);
            dbSearchPanel.Margin = new Thickness(3, 0, 3, 0);
            grid.Children.Add(dbSearchPanel);

            Settings = new GTabSettings <TKey, ReadableTuple <TKey> >(ServerDbs.MobGroups, tab.DbComponent);

            var attributes = _configuration.SubTableAttributeList.Take(_configuration.MaxElementsToCopy).Where(p => !p.IsSkippable).ToList();

            if (!attributes.Any(p => p.IsDisplayAttribute))
            {
                var att = _configuration.SubTableAttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute);

                if (att != null)
                {
                    attributes.Insert(1, att);
                }
            }

            if (attributes.Count % 2 != 0)
            {
                attributes.Add(null);
            }

            Settings.AttributeList = _configuration.SubTableAttributeList;
            Settings.DbData        = _configuration.ServerDb;
            Settings.AttId         = attributes[0];
            Settings.AttDisplay    = attributes[1];

            SearchEngine = Settings.SearchEngine;
            SearchEngine.SetAttributes();
            SearchEngine.SetSettings(attributes[0], true);
            SearchEngine.SetSettings(attributes[1], true);
            SearchEngine.SetAttributes(attributes);

            SearchEngine.Init(dbSearchPanel, _lv, () => {
                var dico = _getSelectedGroups();

                if (dico == null)
                {
                    return(new List <ReadableTuple <TKey> >());
                }

                return(dico.Values.Cast <ReadableTuple <TKey> >().ToList());
            });

            ApplicationShortcut.Link(ApplicationShortcut.Cut, Cut, _lv);

            foreach (var update in _dp.Updates)
            {
                Utilities.Extension.Tuple <DbAttribute, FrameworkElement> x = update;

                if (x.Item1.DataType == typeof(bool))
                {
                    CheckBox element = (CheckBox)x.Item2;
                    _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1)))));

                    element.Checked   += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, true); };
                    element.Unchecked += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, false); };
                }
                else if (
                    x.Item1.DataType == typeof(string) ||
                    x.Item1.DataType == typeof(int))
                {
                    // This will convert integers to strings, but the database engine
                    // is smart enough to auto-convert them to integers afterwards.
                    TextBox element = (TextBox)x.Item2;
                    _dp.AddUpdateAction(new Action <ReadableTuple <TKey> >(item => element.Dispatch(
                                                                               delegate {
                        try {
                            string val = item.GetValue <string>(x.Item1);

                            if (val == element.Text)
                            {
                                return;
                            }

                            element.Text      = item.GetValue <string>(x.Item1);
                            element.UndoLimit = 0;
                            element.UndoLimit = int.MaxValue;
                        }
                        catch {
                        }
                    })));

                    element.TextChanged += delegate { _dp.ApplyDicoCommand(_tab, _lv, (ReadableTuple <TKey>)_tab.List.SelectedItem, _configuration.AttributeTable, (ReadableTuple <TKey>)_lv.SelectedItem, x.Item1, element.Text); };
                }
            }

            foreach (var property in _dp.FormattedProperties)
            {
                //property.Initialize()
                property.Init(tab, _dp);
            }
        }
Example #3
0
        public void Deploy(GDbTabWrapper <TKey, TValue> tab, GTabSettings <TKey, TValue> settings, bool noUpdate = false)
        {
            foreach (Utilities.Extension.Tuple <FrameworkElement, FrameworkElement> element in _deployControls)
            {
                Grid             grid     = element.Item2 as Grid;
                FrameworkElement fElement = element.Item1;

                if (grid == null)
                {
                    grid = tab.PropertiesGrid;
                }

                if (fElement is TextBox || fElement is TextEditor)
                {
                    RemoveUndoAndRedoEvents(fElement, tab);
                }

                int gridRow = (int)fElement.GetValue(Grid.RowProperty);

                while (grid.RowDefinitions.Count <= gridRow)
                {
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(-1, GridUnitType.Auto)
                    });
                }

                if (fElement.Parent == null)
                {
                    grid.Children.Add(fElement);
                }
            }

            foreach (Action <Grid> command in _deployCommands)
            {
                command(tab.PropertiesGrid);
            }

            if (noUpdate)
            {
                return;
            }

            foreach (Utilities.Extension.Tuple <DbAttribute, FrameworkElement> v in _update)
            {
                Utilities.Extension.Tuple <DbAttribute, FrameworkElement> x = v;

                if (x.Item1.DataType == typeof(int))
                {
                    TextBox element = (TextBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(
                                                               delegate {
                        Debug.Ignore(() => element.Text = item.GetValue <int>(x.Item1).ToString(CultureInfo.InvariantCulture));
                        element.UndoLimit = 0;
                        element.UndoLimit = int.MaxValue;
                    })));

                    element.TextChanged += delegate { ApplyCommand(tab, x.Item1, element.Text); };
                }
                else if (x.Item1.DataType == typeof(bool))
                {
                    CheckBox element = (CheckBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1)))));

                    element.Checked   += (sender, args) => ApplyCommand(tab, x.Item1, true, false);
                    element.Unchecked += (sender, args) => ApplyCommand(tab, x.Item1, false, false);
                }
                else if (x.Item1.DataType == typeof(string))
                {
                    TextBox element = (TextBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(
                                                               delegate {
                        try {
                            string val = item.GetValue <string>(x.Item1);

                            if (val == element.Text)
                            {
                                return;
                            }

                            element.Text      = val;
                            element.UndoLimit = 0;
                            element.UndoLimit = int.MaxValue;
                        }
                        catch {
                            Z.F();
                        }
                    })));

                    element.TextChanged += delegate { ApplyCommand(tab, x.Item1, element.Text); };
                }
                else if (x.Item1.DataType.BaseType == typeof(Enum))
                {
                    ComboBox   element = (ComboBox)x.Item2;
                    List <int> values  = Enum.GetValues(x.Item1.DataType).Cast <int>().ToList();

                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(delegate {
                        try {
                            element.SelectedIndex = values.IndexOf(item.GetValue <int>(x.Item1));
                        }
                        catch {
                            element.SelectedIndex = -1;
                        }
                    })));

                    element.SelectionChanged += delegate {
                        if (tab.ItemsEventsDisabled)
                        {
                            return;
                        }

                        try {
                            ApplyCommand(tab, x.Item1, values[element.SelectedIndex], false);
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };
                }
            }

            foreach (ICustomControl <TKey, TValue> property in _customProperties)
            {
                property.Init(tab, this);
            }

            foreach (FormatConverter <TKey, TValue> property in _formattedProperties)
            {
                property.Init(tab, this);
            }

            _orderTabs(tab);

            OnDeployed();
        }